ソースを参照

Make password reset more robust

Maarten van den Berg 6 年 前
コミット
8fc2f5d1b5
共有3 個のファイルを変更した26 個の追加10 個の削除を含む
  1. 6 2
      app/controllers/authentication_controller.rb
  2. 3 1
      app/views/authentication/reset_password_form.html.haml
  3. 17 7
      config/locales/translation_nl.yml

+ 6 - 2
app/controllers/authentication_controller.rb

99
 
99
 
100
   def reset_password
100
   def reset_password
101
     token = Token.find_by(token: params[:token], tokentype: Token::TYPES[:password_reset])
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
       return
107
       return
104
     end
108
     end
105
 
109
 
106
-    if not params[:password] == params[:password_confirmation]
110
+    unless params[:password_reset][:password] == params[:password_reset][:password_confirmation]
107
       flash_message(:warning, I18n.t('authentication.password_repeat_mismatch'))
111
       flash_message(:warning, I18n.t('authentication.password_repeat_mismatch'))
108
       redirect_to action: 'reset_password_form', token: params[:token]
112
       redirect_to action: 'reset_password_form', token: params[:token]
109
       return
113
       return

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

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

+ 17 - 7
config/locales/translation_nl.yml

20
         one: Persoon  #g
20
         one: Persoon  #g
21
         other: Personen  #g
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
       default_subgroup:
35
       default_subgroup:
28
         one: Standaardgroep
36
         one: Standaardgroep
96
         user: :activerecord.models.user  #g
104
         user: :activerecord.models.user  #g
97
 
105
 
98
       user:
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
       default_subgroup:
114
       default_subgroup:
105
         name: Naam
115
         name: Naam