Class: Aadhar::SessionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/aadhar/sessions_controller.rb

Instance Method Summary collapse

Methods included from Authenticate

#authenticate, #current_user

Instance Method Details

#createObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/aadhar/sessions_controller.rb', line 3

def create
  user = User.authenticate(params[:email], params[:password])
  if user
    user.save_token
    render :status => 200,
      :json => { :success => true,
                 :info => "Logged in",
                 :data => { 
                   :auth_token => user.authentication_token, 
                   :user => {
                     id: user.id,
                     email: user.email,
                     name: user.name,
                     change_password: user.change_password } }
                }
  else
    render :status => 200,
           :json => { :success => false,
                      :info => "Invalid email or password",
                      :data => {} }
  end
end

#destroyObject



26
27
28
29
30
31
32
# File 'app/controllers/aadhar/sessions_controller.rb', line 26

def destroy
	current_user.update_column(:authentication_token, nil)
  render :status => 200,
         :json => { :success => true,
                    :info => "Logged out",
                    :data => {} }
end