2011-10-30 23:02:41 +00:00
|
|
|
module Locomotive
|
2011-11-04 15:55:51 +00:00
|
|
|
class InstallationController < ::ApplicationController
|
2010-10-27 00:11:44 +00:00
|
|
|
|
2011-11-04 15:55:51 +00:00
|
|
|
layout '/locomotive/layouts/not_logged_in'
|
2010-10-27 00:11:44 +00:00
|
|
|
|
|
|
|
before_filter :is_step_already_done?
|
|
|
|
|
2010-10-29 15:28:38 +00:00
|
|
|
before_filter :allow_installation?
|
|
|
|
|
2011-11-10 21:41:20 +00:00
|
|
|
helper Locomotive::BaseHelper
|
|
|
|
|
2010-10-27 00:11:44 +00:00
|
|
|
def show
|
|
|
|
request.get? ? self.handle_get : self.handle_post
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def handle_get
|
|
|
|
case params[:step].to_i
|
2011-04-05 00:18:17 +00:00
|
|
|
when 1 then @account = Account.new
|
|
|
|
when 2 then @site = Site.new
|
2010-10-27 00:11:44 +00:00
|
|
|
end
|
|
|
|
render "step_#{params[:step]}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def handle_post
|
|
|
|
case params[:step].to_i
|
2011-04-05 00:18:17 +00:00
|
|
|
when 1 # create account
|
2010-10-27 00:11:44 +00:00
|
|
|
@account = Account.create(params[:account])
|
|
|
|
if @account.valid?
|
2011-10-31 23:44:23 +00:00
|
|
|
redirect_to installation_step_url(2)
|
2010-10-27 00:11:44 +00:00
|
|
|
else
|
2011-04-05 00:18:17 +00:00
|
|
|
render 'step_1'
|
2010-10-27 00:11:44 +00:00
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
when 2 # create site
|
|
|
|
@site = Site.create_first_one(params[:site])
|
2010-10-27 00:11:44 +00:00
|
|
|
|
|
|
|
if @site.valid?
|
2011-05-29 02:45:29 +00:00
|
|
|
Site.install_template(@site, params)
|
2010-10-27 00:11:44 +00:00
|
|
|
|
2011-04-05 00:18:17 +00:00
|
|
|
redirect_to last_url
|
2010-10-27 00:11:44 +00:00
|
|
|
else
|
2011-04-24 23:21:38 +00:00
|
|
|
logger.error "Unable to create the first website: #{@site.errors.inspect}"
|
2011-04-05 00:18:17 +00:00
|
|
|
render 'step_2'
|
2010-10-27 00:11:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_step_already_done?
|
|
|
|
case params[:step].to_i
|
2011-04-05 00:18:17 +00:00
|
|
|
when 1 # already an account in db
|
2011-05-29 02:45:29 +00:00
|
|
|
if account = Account.first
|
2011-10-30 23:02:41 +00:00
|
|
|
@step_done = I18n.t('locomotive.installation.step_1.done', :name => account.name, :email => account.email)
|
2011-04-05 00:18:17 +00:00
|
|
|
render 'step_1' and return false
|
2010-10-27 00:11:44 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-10-29 15:28:38 +00:00
|
|
|
def allow_installation?
|
2011-10-31 23:44:23 +00:00
|
|
|
redirect_to pages_url if Site.count > 0 && Account.count > 0
|
2010-10-29 15:28:38 +00:00
|
|
|
end
|
|
|
|
|
2011-04-05 00:18:17 +00:00
|
|
|
def last_url
|
|
|
|
if Locomotive.config.manage_domains?
|
2011-11-10 21:41:20 +00:00
|
|
|
locomotive_account_session_url(:host => Site.first.domains.first, :port => request.port)
|
2011-04-05 00:18:17 +00:00
|
|
|
else
|
2011-11-10 21:41:20 +00:00
|
|
|
locomotive_account_session_url
|
2011-04-05 00:18:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-10-27 00:11:44 +00:00
|
|
|
end
|
|
|
|
end
|