Kaynağa Gözat

Make password reset more robust

Maarten van den Berg 6 yıl önce
ebeveyn
işleme
8fc2f5d1b5

+ 6 - 2
app/controllers/authentication_controller.rb

@@ -99,11 +99,15 @@ class AuthenticationController < ApplicationController
99 99
 
100 100
   def reset_password
101 101
     token = Token.find_by(token: params[:token], tokentype: Token::TYPES[:password_reset])
102
-    if not token_valid? token
102
+    return unless token_valid? token
103
+
104
+    if params[:password_reset][:password].blank?
105
+      flash_message :warning, I18n.t('authentication.password_blank')
106
+      render 'authentication/reset_password_form', layout: 'void'
103 107
       return
104 108
     end
105 109
 
106
-    if not params[:password] == params[:password_confirmation]
110
+    unless params[:password_reset][:password] == params[:password_reset][:password_confirmation]
107 111
       flash_message(:warning, I18n.t('authentication.password_repeat_mismatch'))
108 112
       redirect_to action: 'reset_password_form', token: params[:token]
109 113
       return

+ 3 - 1
app/views/authentication/reset_password_form.html.haml

@@ -1,11 +1,13 @@
1 1
 - content_for :title do
2 2
   = t 'authentication.reset_password'
3
+
4
+= render 'shared/alerts'
3 5
 .container
4
-  = render 'shared/alerts'
5 6
   = form_for :password_reset, url: {action: 'reset_password', token: params[:token]}, html: { class: 'central-form'} do |f|
6 7
     %h2.central-form-header.text-center
7 8
       = t 'authentication.reset_password'
8 9
 
10
+
9 11
     = f.password_field :password, placeholder: t('authentication.new_password'), class: 'form-control input-top'
10 12
     = f.password_field :password_confirmation, placeholder: t('authentication.new_password_confirm'), class: 'form-control input-bottom'
11 13
     = f.submit t('authentication.reset_password'), class: 'btn btn-primary btn-lg btn-block'

+ 17 - 7
config/locales/translation_nl.yml

@@ -20,9 +20,17 @@ nl:
20 20
         one: Persoon  #g
21 21
         other: Personen  #g
22 22
 
23
-      session: Sessie  #g
24
-      token: Token  #g
25
-      user: Gebruiker  #g
23
+      session:
24
+        one: Sessie
25
+        other: Sessies
26
+
27
+      token:
28
+        one: Token
29
+        other: Tokens
30
+
31
+      user:
32
+        one: Gebruiker
33
+        other: Gebruikers
26 34
 
27 35
       default_subgroup:
28 36
         one: Standaardgroep
@@ -96,10 +104,12 @@ nl:
96 104
         user: :activerecord.models.user  #g
97 105
 
98 106
       user:
99
-        confirmed: Bevestigd  #g
100
-        email: E-mail  #g
101
-        password_digest: Wachtwoord-digest  #g
102
-        person: :activerecord.models.person  #g
107
+        confirmed: Bevestigd
108
+        email: E-mail
109
+        password: Wachtwoord
110
+        password_confirmation: Wachtwoordcontrole
111
+        password_digest: Wachtwoord-digest
112
+        person: :activerecord.models.person
103 113
 
104 114
       default_subgroup:
105 115
         name: Naam