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



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

def create
  user = User.authenticate(params[:email], params[:password])
  if user
    authentication_token = AuthenticationToken.create_token(user)
    render :status => 200,
      :json => { :success => true,
                 :info => "Logged in",
                 :data => { 
                   :auth_token => authentication_token.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



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

def destroy
  authentication_token = AuthenticationToken.where(token: params[:auth_token], user_id: current_user.id).first
  authentication_token.destroy
  render :status => 200,
         :json => { :success => true,
                    :info => "Logged out",
                    :data => {} }
end