Class: Comee::Core::AccessController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- Comee::Core::AccessController
- Defined in:
- app/controllers/comee/core/access_controller.rb
Instance Method Summary collapse
Methods inherited from ApplicationController
#application_code, #authenticate, #current_application, #current_user, #render_content, #render_error, #skip_bullet
Methods included from Pagination
#default_per_page, #order_by, #order_direction, #page_no, #paginate, #paginate_offset, #per_page
Instance Method Details
#login ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/comee/core/access_controller.rb', line 6 def login user = User.find_by(email: auth_params[:email]) if user unless user.application_roles?(current_application) render(json: {error: "User does not have access to this application."}, status: 400) and return end roles = user.application_roles(current_application).map(&:code) if user.authenticate(auth_params[:password]) payload = { id: user.id, name: user.name, email: user.email, roles: roles } jwt = TokenService.issue(payload) render json: {token: jwt, user: payload} else render json: {error: "Invalid password."}, status: 400 end else render json: {error: "User does not exist."}, status: 400 end end |