Class: TokenAuthBox::AuthController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- TokenAuthBox::AuthController
- Includes:
- Middleware
- Defined in:
- app/controllers/token_auth_box/auth_controller.rb
Instance Method Summary collapse
Methods included from Middleware
Instance Method Details
#login ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/token_auth_box/auth_controller.rb', line 21 def login data = user_params user = User.find_by(email: data["email"]) .try(:authenticate, data["password"]) if !user print_error "No User Found; Check to see if the email/password combination is correct" render json: 'no', status: :unauthorized else user_data = user_response_data(user) token = TokenService.gen_token user_data render json: { user: user_data, token: token } end end |
#register ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/token_auth_box/auth_controller.rb', line 8 def register user = User.new(user_params) if user.save data = user_response_data(user) token = TokenService.gen_token data render json: { user: data, token: token } else print_error user.errors. render json: user.errors., status: :bad_request end end |
#verify ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/token_auth_box/auth_controller.rb', line 36 def verify begin user_data = TokenService.decode extract_token render json: user_data.to_json rescue StandardError => e print_error(e.) render json: "Invalid Token: #{e.}", status: :unauthorized end end |