Class: ApiUserAuth::AuthController
- Inherits:
-
ActionController::API
- Object
- ActionController::API
- ApiUserAuth::AuthController
- Defined in:
- app/controllers/api_user_auth/auth_controller.rb
Overview
Registration/Login controller
Instance Method Summary collapse
- #add_provider ⇒ Object
- #create ⇒ Object
- #forgot_password ⇒ Object
- #login ⇒ Object
- #logout ⇒ Object
- #password ⇒ Object
- #provider ⇒ Object
Instance Method Details
#add_provider ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/controllers/api_user_auth/auth_controller.rb', line 53 def add_provider if request.headers['Authorization'].blank? raise Exceptions::Unauthorized, 'Header [Authorization] can not be blank!' end token = request.headers['Authorization'].sub(/Bearer\s*=?/, '') auth_user = AuthUser.find_fy_token(token) if auth_user.present? if auth_user.add_provider_login(params) render json: auth_user.as_user_json, status: 200 else render json: {}, status: 400 end else render json: {}, status: 400 end end |
#create ⇒ Object
10 11 12 13 |
# File 'app/controllers/api_user_auth/auth_controller.rb', line 10 def create auth_user = AuthUser.create_by_params(base_params) render json: auth_user.to_json, status: 201 end |
#forgot_password ⇒ Object
27 28 29 30 31 32 |
# File 'app/controllers/api_user_auth/auth_controller.rb', line 27 def forgot_password auth_user = AuthUser.forgot_password( params.permit(:email) ) render json: auth_user.to_json end |
#login ⇒ Object
15 16 17 18 |
# File 'app/controllers/api_user_auth/auth_controller.rb', line 15 def login auth_user = AuthUser.login_by_params(base_params) render json: auth_user.to_json, status: 200 end |
#logout ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/api_user_auth/auth_controller.rb', line 34 def logout if request.headers['Authorization'].blank? raise Exceptions::Unauthorized, 'Header [Authorization] can not be blank!' end token = request.headers['Authorization'].sub(/Bearer\s*=?/, '') auth_user = AuthUser.find_fy_token(token) if auth_user.present? && auth_user.logout(token) render json: {}, status: 200 else render json: {}, status: 400 end end |
#password ⇒ Object
20 21 22 23 24 25 |
# File 'app/controllers/api_user_auth/auth_controller.rb', line 20 def password auth_user = AuthUser.update_password( params.permit(:email, :password, :code).to_h ) render json: auth_user.to_json, status: 200 end |
#provider ⇒ Object
48 49 50 51 |
# File 'app/controllers/api_user_auth/auth_controller.rb', line 48 def provider auth_user = AuthUser.create_by_provider(params) render json: auth_user.to_json end |