Class: Api::V1::AuthController
- Inherits:
-
BaseController
- Object
- BaseController
- Api::V1::AuthController
- Defined in:
- lib/generators/petergate_api/templates/app/controllers/api/v1/auth_controller.rb
Instance Method Summary collapse
Instance Method Details
#change_password ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/generators/petergate_api/templates/app/controllers/api/v1/auth_controller.rb', line 41 def change_password user = User.find_by(mobile_reset_token: params[:token]) if user && user.update(password: params[:password], password_confirmation: params[:password_confirmation], mobile_reset_token: nil) render status: :ok, json: {message: "Password Changed"} else render json: {error: "Incorrect token or missmatched password"}, status: :unprocessable_entity end end |
#create ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/generators/petergate_api/templates/app/controllers/api/v1/auth_controller.rb', line 13 def create if params[:email] && (@user = User.find_by_email(params[:email])) && @user.valid_password?(auth_params[:password]) connection = @user.api_connections.create render json: {id: @user.id, auth_token: connection.token, email: @user.email}.to_json, status: :ok else render status: :unauthorized, nothing: true end end |
#destroy ⇒ Object
23 24 25 26 |
# File 'lib/generators/petergate_api/templates/app/controllers/api/v1/auth_controller.rb', line 23 def destroy @connection.destroy render status: :ok, json: {message: "connection destroyed"} end |
#forgot_password ⇒ Object
30 31 32 33 34 |
# File 'lib/generators/petergate_api/templates/app/controllers/api/v1/auth_controller.rb', line 30 def forgot_password user = User.find_by_email(params[:email]) user.set_mobile_reset_token! render json: {note: "this token is provided for test purposes", token: user.mobile_reset_token} end |