Class: Api::V1::AuthenticationController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Api::V1::AuthenticationController
- Defined in:
- app/controllers/people/api/v1/authentication_controller.rb
Instance Method Summary collapse
-
#authenticate ⇒ Object
POST /api/1/authentication/authenticate.
-
#login ⇒ Object
POST /api/1/authentication/login.
-
#login_status ⇒ Object
GET /api/1/authentication/login_status.
-
#logout ⇒ Object
POST /api/1/authentication/logout.
-
#register ⇒ Object
POST /api/1/authentication/register.
Instance Method Details
#authenticate ⇒ Object
POST /api/1/authentication/authenticate
60 61 62 63 64 65 66 |
# File 'app/controllers/people/api/v1/authentication_controller.rb', line 60 def authenticate if authenticate_password render :json => {errors: "Email and/or Password is incorrect"}, status: :unauthorized return end render json: {} end |
#login ⇒ Object
POST /api/1/authentication/login
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/people/api/v1/authentication_controller.rb', line 29 def login errors = "Email and/or Password is incorrect" user = ::People::V1::User.find_by(email: get_email) if is_locked?(user) return end if user && user.authenticate(params[:user][:password]) successful_login(user,user.tokens.create) else if unsuccessful_login?(user) errors = "Account is locked due to too many failed login attempts" end render :json => {errors: errors}, status: :unauthorized end end |
#login_status ⇒ Object
GET /api/1/authentication/login_status
54 55 56 57 |
# File 'app/controllers/people/api/v1/authentication_controller.rb', line 54 def login_status # Will give an unauthorized if not logged in render json: {} end |
#logout ⇒ Object
POST /api/1/authentication/logout
46 47 48 49 50 51 |
# File 'app/controllers/people/api/v1/authentication_controller.rb', line 46 def logout #Destroy the current token token = current_token token.destroy render json: {} end |
#register ⇒ Object
POST /api/1/authentication/register
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/people/api/v1/authentication_controller.rb', line 13 def register #Create a new user user = ::People::V1::User.new(user_params) if user.save #If the user is saved, return a token successful_login(user,user.tokens[0]) #Send confirmation email here ::People::AccountMailer.welcome_email(user).deliver ::People::AccountMailer.email_confirmation(user).deliver else #Return an error if not saved render :json => {errors: user.errors.}, status: :unprocessable_entity end end |