Skip to content

Commit

Permalink
Update language
Browse files Browse the repository at this point in the history
  • Loading branch information
zachlatta committed Jan 27, 2018
1 parent d6adad0 commit a779993
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions api/app/controllers/v1/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
module V1
class UsersController < ApiController
def auth
applicant = User.find_or_initialize_by(email: params[:email])
user = User.find_or_initialize_by(email: params[:email])

applicant.generate_login_code!
user.generate_login_code!

if applicant.save
ApplicantMailer.login_code(applicant).deliver_later
if user.save
ApplicantMailer.login_code(user).deliver_later

render_success(applicant)
render_success(user)
else
render_field_errors(applicant.errors)
render_field_errors(user.errors)
end
end

def exchange_login_code
applicant = User.find_by(id: params[:user_id])
user = User.find_by(id: params[:user_id])
login_code = params[:login_code]

return render_not_found unless applicant
return render_not_found unless user

if !login_code.nil? &&
applicant.login_code == login_code &&
applicant.login_code_generation > (Time.current - 15.minutes)
user.login_code == login_code &&
user.login_code_generation > (Time.current - 15.minutes)

applicant.generate_auth_token!
applicant.login_code = nil
applicant.login_code_generation = nil
applicant.save
user.generate_auth_token!
user.login_code = nil
user.login_code_generation = nil
user.save

return render_success(auth_token: applicant.auth_token)
return render_success(auth_token: user.auth_token)
end

render_field_error(:login_code, 'invalid', 401)
Expand Down

0 comments on commit a779993

Please sign in to comment.