Merge pull request #36 from sgmap/remember_me

Add remember me on login
This commit is contained in:
LeSim 2017-03-07 14:15:37 +01:00 committed by GitHub
commit 2e19dd26b7
3 changed files with 18 additions and 25 deletions

View file

@ -10,7 +10,7 @@ class Users::SessionsController < Sessions::SessionsController
# GET /resource/sign_in
def new
unless user_return_to_procedure_id.nil?
unless user_return_to_procedure_id.nil? # WTF ?
@dossier = Dossier.new(procedure: Procedure.active(user_return_to_procedure_id))
end
@ -21,9 +21,10 @@ class Users::SessionsController < Sessions::SessionsController
#POST /resource/sign_in
def create
try_to_authenticate(User)
try_to_authenticate(Gestionnaire)
try_to_authenticate(Administrateur)
remember_me = params[:user][:remember_me] == '1'
try_to_authenticate(User, remember_me)
try_to_authenticate(Gestionnaire, remember_me)
try_to_authenticate(Administrateur, remember_me)
if user_signed_in?
current_user.update_attributes(loged_in_with_france_connect: '')
@ -83,9 +84,10 @@ class Users::SessionsController < Sessions::SessionsController
NumberService.to_number session["user_return_to"].split("?procedure_id=").second
end
def try_to_authenticate(klass)
def try_to_authenticate(klass, remember_me = false)
if resource = klass.find_for_database_authentication(email: params[:user][:email])
if resource.valid_password?(params[:user][:password])
resource.remember_me = remember_me
sign_in resource
resource.force_sync_credentials
set_flash_message :notice, :signed_in

View file

@ -13,25 +13,16 @@
Quest-ce que FranceConnect ?
%hr
= form_for @user, url: user_session_path, method: :post do |f|
%h4
= f.label :email
.input-group
.input-group-addon
%span.fa.fa-user
= f.email_field :email, class: 'form-control'
%br
%h4
= f.label 'Mot de passe'
.input-group
.input-group-addon
%span.fa.fa-asterisk
= f.password_field :password, class: 'form-control', value: "#{@user.password}"
%br
%br
.actions
= f.submit "Se connecter", class:'btn btn-primary'
%br
.text-left
= simple_form_for @user, url: user_session_path do |f|
= f.input :email
= f.input :password, label: 'Mot de passe', input_html: { value: @user.password }
- if devise_mapping.rememberable?
= f.input :remember_me, as: :boolean, label: 'Se souvenir de moi'
.text-center
= f.submit "Se connecter", class:'btn btn-primary'
- if @user.email != DemoEmails[:gestionnaire] && @user.email != DemoEmails[:admin]
= render "users/shared/links"

View file

@ -126,7 +126,7 @@ Devise.setup do |config|
# ==> Configuration for :rememberable
# The time the user will be remembered without asking for credentials again.
# config.remember_for = 2.weeks
config.remember_for = 2.weeks
# Invalidates all the remember me tokens when the user signs out.
config.expire_all_remember_me_on_sign_out = true