Sha256: 3587d17e93705bafe58bd2d0867a5410b4c79295a82fa4118417d863b0684704

Contents?: true

Size: 1.63 KB

Versions: 30

Compression:

Stored size: 1.63 KB

Contents

module Caboose
  class RegisterController < Caboose::ApplicationController
    layout 'caboose/modal'
    
    # GET /register
    def index
      @return_url = params[:return_url].nil? ? "/" : params[:return_url];
      redirect_to @return_url if logged_in?
    end
    
    # POST /register
    def register
      
      resp = StdClass.new('error' => '', 'redirect' => '')
      
      if (logged_in?)
        resp.error = "Already logged in"
      else
        
        first_name  = params[:first_name]
        last_name   = params[:last_name]
        email       = params[:email]
        pass1       = params[:pass1]
        pass2       = params[:pass2]
                          
        if (first_name.nil? || first_name.strip.length == 0)
          resp.error = "Your first name is required."
        elsif (last_name.nil? || last_name.strip.length == 0)
          resp.error = "Your last name is required."
        elsif (email.nil? || email.strip.length == 0)
          resp.error = "Your email address is required."
        elsif (pass1.nil? || pass1.strip.length < 8)
          resp.error = "Your password must be at least 8 characters."
        elsif (pass2.nil? || pass1 != pass2)
          resp.error = "Your passwords don't match."
        else
          
          u = Caboose::User.new
          u.first_name    = first_name
          u.last_name     = last_name
          u.email         = email
          u.password      = Digest::SHA1.hexdigest(Caboose::salt + pass1)
          u.creation_date = DateTime.now
          u.save                    
          resp.redirect = "/login"

        end
      end
      render json: resp
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
caboose-cms-0.2.35 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.34 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.33 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.32 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.31 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.30 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.29 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.28 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.26 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.25 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.24 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.23 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.22 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.21 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.20 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.19 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.18 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.17 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.16 app/controllers/caboose/register_controller.rb
caboose-cms-0.2.15 app/controllers/caboose/register_controller.rb