Class: SessionsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/generators/fetty/authentication/templates/controllers/sessions_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/generators/fetty/authentication/templates/controllers/sessions_controller.rb', line 10

def create
  @user = User.authenticate!(params[:login], params[:password])
  if @user.is_a? User
    set_session_or_cookies(@user,params[:remember_me])
    redirect_to redirect_to_target_or_default_url, :notice => "Sign in successfully."
  elsif @user == UsersAuthentication::Status::Unexist
    raise "User account not found! please sign up first."
  elsif @user == UsersAuthentication::Status::InvalidPassword
    raise "Invalid username or password."
  elsif @user == UsersAuthentication::Status::Inactivated
    raise "Please activate your account first! check your email."
  end
rescue Exception => e
  set_session_or_cookies(nil)
  flash.now[:alert] = e.message
  render :action => 'new'
end

#destroyObject



28
29
30
31
# File 'lib/generators/fetty/authentication/templates/controllers/sessions_controller.rb', line 28

def destroy
  set_session_or_cookies(nil)
  redirect_to root_url, :notice => "Successfully sign out."
end

#newObject



4
5
6
7
8
# File 'lib/generators/fetty/authentication/templates/controllers/sessions_controller.rb', line 4

def new
  if user_signed_in?
    redirect_to redirect_to_target_or_default_url, :alert => "You already sign-in!"
  end
end