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



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

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



25
26
27
28
# File 'lib/generators/fetty/authentication/templates/controllers/sessions_controller.rb', line 25

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

#newObject



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

def new
end