43 lines
1.2 KiB
Ruby
43 lines
1.2 KiB
Ruby
class ApiSessionsController < ApiController
|
|
|
|
def login
|
|
user = User.authenticate(params[:email], params[:password])
|
|
|
|
if user.nil?
|
|
render :json => {}, :status => 422
|
|
else
|
|
if jkclient_agent?
|
|
user.update_progression_field(:first_ran_client_at)
|
|
end
|
|
|
|
@session_only_cookie = !jkclient_agent? && 0 == params[:remember_me].to_i
|
|
|
|
complete_sign_in(user, redirect=false)
|
|
|
|
render :json => {}, :status => :ok
|
|
end
|
|
end
|
|
|
|
#update password token. inteanded for the react app (spa)
|
|
def request_reset_password
|
|
begin
|
|
url = APP_CONFIG.spa_origin_url + '/authentication/basic'
|
|
User.reset_password(params[:email], url)
|
|
render :json => {}, :status => 204
|
|
rescue JamRuby::JamArgumentError
|
|
render :json => {:message => ValidationMessages::EMAIL_NOT_FOUND}, :status => 403
|
|
end
|
|
|
|
end
|
|
|
|
def reset_forgot_password
|
|
begin
|
|
User.set_password_from_token(params[:email], params[:token], params[:password], params[:password_confirmation])
|
|
render :json => {}, :status => 204
|
|
rescue JamRuby::JamArgumentError => e
|
|
render :json => {:message => e.field_message}, :status => 403
|
|
end
|
|
end
|
|
|
|
end
|