Class: RailsJwtAuth::SessionsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/rails_jwt_auth/sessions_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/rails_jwt_auth/sessions_controller.rb', line 6

def create
  user = RailsJwtAuth.model.where(
    RailsJwtAuth.auth_field_name => create_params[RailsJwtAuth.auth_field_name].to_s.downcase
  ).first

  if !user
    render json: create_error_response(user), status: 422
  elsif user.respond_to?('confirmed?') && !user.confirmed?
    render json: unconfirmed_error_response, status: 422
  elsif user.authenticate(create_params[:password])
    render json: create_success_response(user, get_jwt(user)), status: 201
  else
    render json: create_error_response(user), status: 422
  end
end

#destroyObject



22
23
24
25
# File 'app/controllers/rails_jwt_auth/sessions_controller.rb', line 22

def destroy
  authenticate!
  current_user.destroy_auth_token Jwt::Request.new(request).auth_token
end