Class: Chronicle::AuthController

Inherits:
ApplicationController show all
Defined in:
app/controllers/chronicle/auth_controller.rb

Instance Method Summary collapse

Instance Method Details

#loginObject

Raises:



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/chronicle/auth_controller.rb', line 3

def 
  email    = params.require(:email)
  password = params.require(:password)

  admin_user = AdminUser.find_by(email: email)
  raise NotFoundError, 'User not found' unless admin_user

  if admin_user.authenticate(password)
    render json: { admin_user: admin_user.slice(:id, :name, :email, :auth_token) }, status: :ok
  else
    render json: { error: 'Invalid email or password' }, status: :unauthorized
  end
end