Skip to content

Commit

Permalink
Enhancement: Reduce shown messages after password reset/verify to one…
Browse files Browse the repository at this point in the history
… single version.
  • Loading branch information
rolfschmidt authored and thorsteneckel committed Mar 4, 2020
1 parent bca16de commit e61fa67
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
21 changes: 6 additions & 15 deletions app/assets/javascripts/app/controllers/password_reset.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,13 @@ class Index extends App.ControllerContent
)

success: (data) =>
if data.message is 'ok'

# if in developer mode, redirect to set new password
if data.token && @Config.get('developer_mode') is true
redirect = =>
@navigate "#password_reset_verify/#{data.token}"
@delay(redirect, 2000)
@render(sent: true)

else
@$('[name=username]').val('')
@notify(
type: 'error'
msg: App.i18n.translateContent('Username or email address invalid, please try again.')
)
@formEnable( @el.find('.form-password') )
# if in developer mode, redirect to set new password
if data.token && @Config.get('developer_mode') is true
redirect = =>
@navigate "#password_reset_verify/#{data.token}"
@delay(redirect, 2000)
@render(sent: true)

App.Config.set('password_reset', Index, 'Routes')

Expand Down
5 changes: 4 additions & 1 deletion app/assets/javascripts/app/views/password/reset.jst.eco
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
<% if @sent: %>
<h2><%- @T('We\'ve sent password reset instructions to your email address.') %><small></small></h2>
<p><%- @T('If you don\'t receive instructions within a minute or two, check your email\'s spam and junk filters, or try resending your request.') %></p>
<a href="#" class="subtle retry">&raquo; <%- @T('again') %> &laquo;</a>
<div class="form-controls">
<a class="btn btn--text btn--subtle js-cancel" href="#login"><%- @T( 'Cancel & Go Back' ) %></a>
<button class="btn btn--primary retry align-right"><%- @T( 'again' ) %></button>
</div>
<% else: %>
<h2><%- @T( 'Forgot your password?' ) %><small></small></h2>
<form class="form-password">
Expand Down
15 changes: 7 additions & 8 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,12 @@ def email_verify_send

raise Exceptions::UnprocessableEntity, 'No email!' if !params[:email]

# check is verify is possible to send
user = User.find_by(email: params[:email].downcase)
raise Exceptions::UnprocessableEntity, 'No such user!' if !user
if !user
# result is always positive to avoid leaking of existing user accounts
render json: { message: 'ok' }, status: :ok
return
end

#if user.verified == true
# render json: { error: 'Already verified!' }, status: :unprocessable_entity
Expand Down Expand Up @@ -615,14 +618,10 @@ def password_reset_send
render json: { message: 'ok', token: result[:token].name }, status: :ok
return
end

# token sent to user, send ok to browser
render json: { message: 'ok' }, status: :ok
return
end

# unable to generate token
render json: { message: 'failed' }, status: :ok
# result is always positive to avoid leaking of existing user accounts
render json: { message: 'ok' }, status: :ok
end

=begin
Expand Down
4 changes: 3 additions & 1 deletion test/browser/signup_password_change_and_reset_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,11 @@ def test_signup
click(css: '.content .btn--primary')
watch_for(
css: 'body',
value: 'address invalid',
value: 'sent password reset instructions',
)

click(css: '.content .btn--primary')

set(
css: 'input[name="username"]',
value: signup_user_email,
Expand Down

0 comments on commit e61fa67

Please sign in to comment.