Skip to content

Commit

Permalink
FIX: invited users get clearer messaging when setting a password for …
Browse files Browse the repository at this point in the history
…the first time
  • Loading branch information
nlalonde committed Jan 21, 2014
1 parent 3c3449a commit ba74226
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@
<div class="control-group">
<label class="control-label">{{i18n user.password.title}}</label>
<div class="controls">
<a href="#" {{action changePassword}} class='btn'><i class="fa fa-envelope"></i>{{i18n user.change_password.action}}</a> {{passwordProgress}}
<a href="#" {{action changePassword}} class='btn'><i class="fa fa-envelope"></i>
{{#if no_password}}
{{i18n user.change_password.set_password}}
{{else}}
{{i18n user.change_password.action}}
{{/if}}
</a>
{{passwordProgress}}
</div>
</div>

Expand Down
4 changes: 3 additions & 1 deletion app/mailers/user_notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def authorize_email(user, opts={})
end

def forgot_password(user, opts={})
build_email(user.email, template: "user_notifications.forgot_password", email_token: opts[:email_token])
build_email( user.email,
template: user.has_password? ? "user_notifications.forgot_password" : "user_notifications.set_password",
email_token: opts[:email_token])
end

def digest(user, opts={})
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ def password_required?
!!@password_required
end

def has_password?
password_hash.present?
end

def password_validator
PasswordValidator.new(attributes: :password).validate_each(self, :password, @raw_password)
end
Expand Down
11 changes: 10 additions & 1 deletion app/serializers/current_user_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class CurrentUserSerializer < BasicUserSerializer
:dynamic_favicon,
:trust_level,
:can_edit,
:can_invite_to_forum
:can_invite_to_forum,
:no_password

def include_site_flagged_posts_count?
object.staff?
Expand Down Expand Up @@ -45,4 +46,12 @@ def include_can_invite_to_forum?
scope.can_invite_to_forum?
end

def no_password
true
end

def include_no_password?
!object.has_password?
end

end
10 changes: 8 additions & 2 deletions app/views/users/password_reset.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@
</p>
<% else %>
<%if @user.present? %>
<h3><%= t 'password_reset.choose_new' %></h3>
<h3>
<% if @user.has_password? %>
<%= t 'password_reset.choose_new' %>
<% else %>
<%= t 'password_reset.choose' %>
<% end %>
</h3>

<%=form_tag({}, method: :put) do %>
<p>
<input id="user_password" name="password" size="30" type="password">
</p>
<p>
<%=submit_tag(t('password_reset.update'), class: 'btn')%>
<%=submit_tag( @user.has_password? ? t('password_reset.update') : t('password_reset.save'), class: 'btn')%>
</p>
<%end%>
<%end%>
Expand Down
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ en:
in_progress: "(sending email)"
error: "(error)"
action: "Send Password Reset Email"
set_password: "Set Password"

change_about:
title: "Change About Me"
Expand Down
16 changes: 14 additions & 2 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,10 @@ en:
password_reset:
no_token: "Sorry, your token has expired. Please try resetting your password again."
choose_new: "Please choose a new password"
update: 'update password'
title: 'reset password'
choose: "Please choose a password"
update: 'Update Password'
save: 'Set Password'
title: 'Reset Password'
success: "You successfully changed your password and are now logged in."
success_unapproved: "You successfully changed your password."
continue: "Continue to %{site_name}"
Expand Down Expand Up @@ -1218,6 +1220,16 @@ en:
Click the following link to choose a new password:
%{base_url}/users/password-reset/%{email_token}
set_password:
subject_template: "[%{site_name}] Set Password"
text_body_template: |
Somebody asked to add a password to your account on [%{site_name}](%{base_url}). Alternatively, you can log in using any supported online service (Google, Facebook, etc) that is associated with this validated email address.
If you did not make this request, you can safely ignore this email.
Click the following link to choose a password:
%{base_url}/users/password-reset/%{email_token}
authorize_email:
subject_template: "[%{site_name}] Confirm your new email address"
text_body_template: |
Expand Down

0 comments on commit ba74226

Please sign in to comment.