egov_utils 0.2.12 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38c99e9ec2cf5d25aa7b814edae5f6ea40bc0daf4415ab949b3a8cbacca86bb8
4
- data.tar.gz: 0befe9b58a73e45efde674697f22c116e3a82e9219e68ea3ad8bf6bf6c70f29a
3
+ metadata.gz: '0180df0129a941cc5e555901b831867c2540fb9fba09d2ae8ac4d174e07606d7'
4
+ data.tar.gz: 9790504b20a2987452da2433aa0364de5d0d6b1ad59d3646cfdf3d2b761dda4a
5
5
  SHA512:
6
- metadata.gz: 73c3cef165f18c95dc3b518709ff825ff5f840b71444b471d414f2f0e0c031a17f68df0c4fa740e015109d7d7e509d7f92d3e2985f24375dc898e4fb1fbc51e9
7
- data.tar.gz: c17455fe4ff7594600241b123e4100c881a0c6ba9bf9e6467c48d4b7912fbd3cc87f2891b48a1e89db0782d8a3da604a4726536acf20ed79f2e010656665c611
6
+ metadata.gz: c458ee913a5c0b9c6727db5283b971cec87fcbea447ee540d665201addfed1a3ca396fe5019d9d4128348bf717c711330c05e1654fc1bef4849561d90a2935b6
7
+ data.tar.gz: f455d3005cdaa372d499ac0fc42a288814554249cf8b909ac625b11c10673d098647fefd94c2c7e2fa994af5eecca5fca4473058a7740f70d1f9fdca648632f4
@@ -3,7 +3,38 @@ require_dependency "egov_utils/application_controller"
3
3
  module EgovUtils
4
4
  class PasswordsController < ApplicationController
5
5
 
6
- skip_before_action :check_password_change
6
+ skip_before_action :require_login, only: [:reset, :send_reset_token, :new, :create]
7
+ skip_before_action :check_password_change, only: [:edit, :update]
8
+
9
+ before_action :find_user_for_reset, only: [:new, :create]
10
+
11
+ def reset
12
+ return render_404 unless EgovUtils::Settings.allow_password_reset?
13
+ end
14
+
15
+ def send_reset_token
16
+ return render_404 unless EgovUtils::Settings.allow_password_reset?
17
+ @user = EgovUtils::User.find_by(mail: params[:reset_password][:mail])
18
+ if @user
19
+ @token = @user.generate_reset_password_token
20
+ EgovUtils::UserMailer.password_reset(@user, @token).deliver_later if @user.save
21
+ end
22
+ redirect_to egov_utils.reset_passwords_path, notice: t('notice_reset_email_sent')
23
+ end
24
+
25
+ # New password for existing user - password reset
26
+ def new
27
+ end
28
+ def create
29
+ if change_password!(@user)
30
+ EgovUtils::UserMailer.password_change_info(@user).deliver_later
31
+ flash[:notice] = t(:notice_password_changed)
32
+ redirect_to main_app.root_path
33
+ else
34
+ flash[:warning] = t(:warning_password_not_changed)
35
+ redirect_to reset_passwords
36
+ end
37
+ end
7
38
 
8
39
  def edit
9
40
  @user = current_user
@@ -11,11 +42,8 @@ module EgovUtils
11
42
 
12
43
  def update
13
44
  @user = current_user
14
- if @user.password_change_possible? && @user.password_check?(params[:password_change][:current_password])
15
- @user.attributes = password_change_params
16
- @user.must_change_password = false
17
- end
18
- if @user.save
45
+ if @user.password_check?(params[:password_change][:current_password]) && change_password!(@user)
46
+ EgovUtils::UserMailer.password_change_info(@user).deliver_later
19
47
  flash[:notice] = t(:notice_password_changed)
20
48
  redirect_to main_app.root_path
21
49
  else
@@ -26,9 +54,27 @@ module EgovUtils
26
54
 
27
55
  private
28
56
 
57
+ def find_user_for_reset
58
+ @token = params[:token]
59
+ @user = EgovUtils::User.find_by(confirmation_code: @token)
60
+ if @user.nil? || @user.updated_at < (Time.now - 1.hour)
61
+ render_404
62
+ else
63
+ @user
64
+ end
65
+ end
66
+
29
67
  def password_change_params
30
68
  params.require(:password_change).permit(:password, :password_confirmation)
31
69
  end
32
70
 
71
+ # private helpers
72
+ def change_password!(user)
73
+ return false unless @user.password_change_possible?
74
+ user.attributes = password_change_params
75
+ user.must_change_password = false
76
+ user.save
77
+ end
78
+
33
79
  end
34
80
  end
@@ -12,6 +12,11 @@ module EgovUtils
12
12
  mail(to: user.mail, subject: t(:app_name))
13
13
  end
14
14
 
15
+ def password_reset(user, token)
16
+ @user, @token = user, token
17
+ mail(to: user.mail, subject: t(:app_name))
18
+ end
19
+
15
20
  def password_change_info(user)
16
21
  @user = user
17
22
  mail(to: user.mail, subject: t(:app_name))
@@ -163,6 +163,11 @@ module EgovUtils
163
163
  false
164
164
  end
165
165
 
166
+ def generate_reset_password_token
167
+ self.confirmation_code = nil
168
+ generate_confirmation_code
169
+ end
170
+
166
171
  private
167
172
 
168
173
  def generate_confirmation_code
@@ -0,0 +1,7 @@
1
+ %h2= t('label_reset_password')
2
+
3
+ = bootstrap_form_for(:password_change, url: egov_utils.create_password_path(@token), method: :post) do |f|
4
+ = f.password_field(:password)
5
+ = f.password_field(:password_confirmation)
6
+ .form-actions
7
+ = f.submit
@@ -0,0 +1,6 @@
1
+ %h2= t('label_reset_password')
2
+
3
+ = bootstrap_form_for(:reset_password, url: send_reset_token_passwords_path, method: :post) do |f|
4
+ = f.text_field(:mail)
5
+ .form-actions
6
+ = f.submit t('label_send')
@@ -3,4 +3,6 @@
3
3
  = f.password_field(:password)
4
4
  = f.submit t(:label_login)
5
5
  - if EgovUtils::Settings.allow_register?
6
- = link_to t('label_signup'), new_user_path, class: 'btn btn-secondary'
6
+ = link_to t('label_signup'), egov_utils.new_user_path, class: 'btn btn-secondary'
7
+ - if EgovUtils::Settings.allow_password_reset?
8
+ = link_to t('label_forgotten_password'), egov_utils.reset_passwords_path
@@ -0,0 +1,9 @@
1
+ <p>
2
+ v aplikaci <%= t(:app_name) %> jste si vyžádal/a změnu hesla, pro provedení této změny klikněte prosím <%= link_to 'sem', new_password_url(@token) %>.
3
+ </p>
4
+ <p>
5
+ Tento odkaz je platný hodinu od vyplnění žádosti.
6
+ </p>
7
+ <p>
8
+ Pokud jste o změnu hesla nežádal/a, tento e-mail ignorujte.
9
+ </p>
@@ -0,0 +1,5 @@
1
+ v aplikaci <%= t(:app_name) %> jste si vyžádal/a změnu hesla, pro provedení této změny přejděte prosím na tuto url: <%= new_password_url(@token) %>.
2
+ Tento odkaz je platný hodinu od vyplnění žádosti.
3
+
4
+
5
+ Pokud jste o změnu hesla nežádal/a, tento e-mail ignorujte.
@@ -1 +1 @@
1
- Forbidden
1
+ = t('error_forbidden')
@@ -0,0 +1 @@
1
+ = t('error_not_found')
@@ -22,6 +22,9 @@ cs:
22
22
  cookies_text: K ukládání nastavení a správnému fungování využíváme soubory cookies. Používáním webu s jejich používáním souhlasíte.
23
23
  ok: Rozumím
24
24
 
25
+ error_forbidden: Přístup odepřen
26
+ error_not_found: Nenalezeno
27
+
25
28
  button_add: Přidat
26
29
 
27
30
  ministery_justice_name: Ministerstvo spravedlnosti ČR
@@ -34,6 +37,7 @@ cs:
34
37
  notice_logout: Byl/a jste úspěšně odhlášen/a
35
38
  notice_signeup_with_mail: Registrace proběhla úspěšně, byl Vám odeslán potvrzovací e-mail, prosím zkontrolujte svou poštu.
36
39
  notice_password_changed: Vaše heslo bylo úspěšně změněno
40
+ notice_reset_email_sent: E-mail s instrukcemi pro změnu hesla byl odeslán na zadanou e-mailovou adresu.
37
41
  success_user_confirm: Váše e-mailová adresa byla potvrzena. Nyní se již můžete přihlásit.
38
42
  error_password_expired: Platnost vašeho hesla vypršela. Prosím změňte ho.
39
43
  warning_password_not_changed: Heslo nebylo změněno, zadali jste všechna hesla správně?
@@ -54,6 +58,8 @@ cs:
54
58
  label_actions: Akce
55
59
  label_done: hotovo
56
60
  label_add_group_member: Přidat uživatele
61
+ label_forgotten_password: Zapomněli jste heslo?
62
+ label_reset_password: Obnova hesla
57
63
 
58
64
  text_born_on_at: "Narozen %{date} v %{place}"
59
65
 
@@ -123,8 +129,10 @@ cs:
123
129
  password: Heslo
124
130
  password_change:
125
131
  current_password: Současné heslo
126
- password: Heslo
132
+ password: Nové heslo
127
133
  password_confirmation: Potvrzení hesla
134
+ reset_password:
135
+ mail: E-mailová adresa
128
136
 
129
137
  submits: &my_submits
130
138
  password_change:
data/config/routes.rb CHANGED
@@ -22,7 +22,14 @@ EgovUtils::Engine.routes.draw do
22
22
  end
23
23
  resources :roles
24
24
 
25
- resources :passwords
25
+ resources :passwords, only: [:index, :edit, :update] do
26
+ collection do
27
+ get 'reset'
28
+ post 'send_reset_token'
29
+ end
30
+ end
31
+ get 'passwords/new/:token', to: 'passwords#new', as: 'new_password'
32
+ post 'passwords/:token', to: 'passwords#create', as: 'create_password'
26
33
 
27
34
  # post '/auth/:provider/callback', to: 'sessions#create'
28
35
 
@@ -15,9 +15,14 @@ module EgovUtils
15
15
  allow_register
16
16
  end
17
17
 
18
+ def allow_password_reset?
19
+ allow_register? && allow_password_reset
20
+ end
21
+
18
22
  end
19
23
 
20
24
  Settings['allow_register'] ||= false
25
+ Settings['allow_password_reset'] ||= true
21
26
 
22
27
  Settings['redmine'] ||= Settingslogic.new({})
23
28
  Settings['redmine']['enabled'] ||= false
@@ -50,6 +50,15 @@ module EgovUtils
50
50
  render 'common/modal_action'
51
51
  end
52
52
 
53
+ def render_404(exception = nil)
54
+ respond_to do |format|
55
+ format.json { head :not_found, content_type: 'text/html' }
56
+ format.html { render template: "errors/error_404", error: exception.try('message'), status: 404 }
57
+ format.js { head :not_found, content_type: 'text/html' }
58
+ end
59
+ return false
60
+ end
61
+
53
62
  protected
54
63
  def find_current_user
55
64
  # existing session
@@ -1,3 +1,3 @@
1
1
  module EgovUtils
2
- VERSION = '0.2.12'
2
+ VERSION = '0.2.13'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egov_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondřej Ezr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-21 00:00:00.000000000 Z
11
+ date: 2018-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -438,6 +438,7 @@ files:
438
438
  - app/views/egov_utils/groups/show.html.haml
439
439
  - app/views/egov_utils/passwords/edit.html.haml
440
440
  - app/views/egov_utils/passwords/new.html.haml
441
+ - app/views/egov_utils/passwords/reset.html.haml
441
442
  - app/views/egov_utils/people/_form.html.haml
442
443
  - app/views/egov_utils/redmine/issues/index.html.haml
443
444
  - app/views/egov_utils/roles/index.html.haml
@@ -448,6 +449,8 @@ files:
448
449
  - app/views/egov_utils/user_mailer/confirmation_email.text.erb
449
450
  - app/views/egov_utils/user_mailer/password_change_info.html.erb
450
451
  - app/views/egov_utils/user_mailer/password_change_info.text.erb
452
+ - app/views/egov_utils/user_mailer/password_reset.html.erb
453
+ - app/views/egov_utils/user_mailer/password_reset.text.erb
451
454
  - app/views/egov_utils/users/_form.html.haml
452
455
  - app/views/egov_utils/users/_ldap_search.html.haml
453
456
  - app/views/egov_utils/users/_users_tab.html.haml
@@ -455,6 +458,7 @@ files:
455
458
  - app/views/egov_utils/users/new.html.haml
456
459
  - app/views/egov_utils/users/show.html.haml
457
460
  - app/views/errors/error_403.html.haml
461
+ - app/views/errors/error_404.html.haml
458
462
  - app/views/layouts/egov_utils/_messages.html.haml
459
463
  - app/views/layouts/egov_utils/application.html.erb
460
464
  - app/views/layouts/egov_utils/mailer.html.erb