class Api::V1::AuthController
Public Instance Methods
change_password()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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
Private Instance Methods
auth_params()
click to toggle source
# File lib/generators/petergate_api/templates/app/controllers/api/v1/auth_controller.rb, line 51 def auth_params params.permit(:email, :password, :password_confirmation) end