Sha256: 90d2a999957bef6d888197a80d89af568183955e13b5c6282e4aabef66f3d8a6

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

class LoginController < ApplicationController

  def index
    if request.post?
      user = User.find_by_email_and_password(params[:email], params[:password])
      
      if user
        login!(user)
        return redirect_to("/tr8n/dashboard")
      end
      
      trfe('Incorrect email or password')
    end
  end

  def register
    if request.post?
      unless validate_registration
        user = User.create(:email => params[:email], 
                  :password => params[:password], 
                  :first_name => params[:first_name], 
                  :last_name => params[:last_name], 
                  :gender => params[:gender], 
                  :mugshot => params[:mugshot], 
                  :link => params[:link])
        login!(user)
        
        trfn('Thank you for registering.')
        return redirect_to("/tr8n/dashboard")
      end
    end
  end

  def out
    logout!
    redirect_to("/tr8n/home") 
  end

private

  def validate_registration
    params[:email].strip!
     
    if params[:email].blank?
      return trfe('Email is missing')
    end

    user = User.find_by_email(params[:email])
    if user
      return trfe('This email is already used by another user')
    end

    if params[:password].blank?
      return trfe('Password is missing')
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tr8n-3.1.1 test/dummy/app/controllers/login_controller.rb