2010-10-27 00:11:44 +00:00
|
|
|
module Admin
|
|
|
|
class InstallationController < BaseController
|
|
|
|
|
|
|
|
layout '/admin/layouts/box'
|
|
|
|
|
|
|
|
skip_before_filter :require_site
|
|
|
|
|
2011-05-28 17:52:36 +00:00
|
|
|
skip_before_filter :require_admin
|
2010-10-27 00:11:44 +00:00
|
|
|
|
|
|
|
skip_before_filter :verify_authenticity_token
|
|
|
|
|
|
|
|
skip_before_filter :validate_site_membership
|
|
|
|
|
|
|
|
before_filter :is_step_already_done?
|
|
|
|
|
2010-10-29 15:28:38 +00:00
|
|
|
before_filter :allow_installation?
|
|
|
|
|
2011-06-26 23:02:48 +00:00
|
|
|
skip_load_and_authorize_resource
|
|
|
|
|
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-04-05 21:41:50 +00:00
|
|
|
redirect_to admin_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
|
|
|
|
@step_done = I18n.t('admin.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?
|
|
|
|
redirect_to admin_pages_url if Site.count > 0 && Account.count > 0
|
|
|
|
end
|
|
|
|
|
2011-04-05 00:18:17 +00:00
|
|
|
def last_url
|
|
|
|
if Locomotive.config.manage_domains?
|
|
|
|
admin_session_url(:host => Site.first.domains.first, :port => request.port)
|
|
|
|
else
|
|
|
|
admin_session_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-10-27 00:11:44 +00:00
|
|
|
end
|
|
|
|
end
|