Sha256: 2f5c23a6fea342ac0a95f0c7ba6b23405b8a5584e56df2ecd79e2c97f018a3a5

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

class SetupController < ApplicationController
  before_filter :check_config, :only => 'index'
  layout 'setup'
  
  def index
    if request.post?
      Blog.transaction do
        this_blog.blog_name = params[:setting][:blog_name]  
        this_blog.base_url = blog_base_url
        this_blog.save    
      end
      
      @user = User.new(:login => 'admin', :email => params[:setting][:email])

        @user.password = generate_password
        session[:tmppass] = @user.password
        @user.name = @user.login
        if @user.save
          self.current_user = @user
          session[:user_id] = @user.id

          # Crappy hack : by default, the auto generated post is user_id less and it makes Typo crash
          if User.count == 1
            art = Article.find(:first)
            art.user_id = @user.id
            art.save
          end
        end
      redirect_to :action => 'confirm'
    end
  end

  private
  def generate_password
    chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
    newpass = ""
    1.upto(7) { |i| newpass << chars[rand(chars.size-1)] }
    return newpass
  end
  
  def check_config
    return unless this_blog.configured?
    redirect_to :controller => 'articles', :action => 'index'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
typo-5.5 app/controllers/setup_controller.rb
typo-5.4.4 app/controllers/setup_controller.rb