Expand Up @@ -11,48 +11,81 @@
<div class="panel-body panel-footer">
{% form 'user.personal_details', user, class: "form-horizontal" %}
<fieldset>
<legend>
<span>User information</span>
</legend>
{% for field in user.fields %}
{% include 'field' with field %}
{% endfor %}
</fieldset>

<fieldset>
<div class="form-group {{ user.errors.password | error_class: 'has-error' }}">
<label for="user_password_confirmation" class="col-md-4 control-label">
Password
</label>
<div class="col-md-6">
<input id="user_password"
name="user[password]" type="password"
class="form-control">
{{ user.errors.password | inline_errors: 'help-block' }}
{% if user.using_password? %}
<fieldset>
<legend>
<span>Provide your current password</span>
</legend>
<div class="form-group {{ user.errors.current_password | error_class: 'has-error' }}">
<label for="user_current_password" class="col-md-4 control-label">
Current Password
</label>
<div class="col-md-6">
<input
id="user_current_password"
name="user[current_password]"
type="password"
class="form-control">
{{ user.errors.current_password | inline_errors: 'help-block' }}
</div>
</div>
</div>
</fieldset>

<fieldset>
<legend>
<span>Change password</span>
</legend>
<div class="form-group {{ user.errors.password | error_class: 'has-error' }}">
<label for="user_password_confirmation" class="col-md-4 control-label">
Password
</label>
<div class="col-md-6">
<input
id="user_password"
name="user[password]"
type="password"
class="form-control">
{{ user.errors.password | inline_errors: 'help-block' }}
</div>
</div>

<div class="form-group {{ user.errors.password_confirmation | error_class: 'has-error' }}">
<label for="user_password_confirmation" class="col-md-4 control-label">
Password confirmation
</label>
<div class="col-md-6">
<input id="user_password_confirmation"
name="user[password_confirmation]"
type="password"
class="form-control" >
{{ user.errors.password_confirmation | inline_errors: 'help-block' }}
<div class="form-group {{ user.errors.password_confirmation | error_class: 'has-error' }}">
<label for="user_password_confirmation" class="col-md-4 control-label">
Password confirmation
</label>
<div class="col-md-6">
<input
id="user_password_confirmation"
name="user[password_confirmation]"
type="password"
class="form-control">
{{ user.errors.password_confirmation | inline_errors: 'help-block' }}
</div>
</div>
</div>
</fieldset>
</fieldset>
{% endif %}

<fieldset>
<div class="form-group">
<div class="col-md-10">
<input class="btn btn-primary pull-right" name="commit" type="submit" value="Update Personal Details">
<input
class="btn btn-primary pull-right"
name="commit"
type="submit"
value="Update Personal Details">
</div>
</div>
</fieldset>
{% endform %}
</div>
</div>
</div>
</div>
</div>
5 changes: 5 additions & 0 deletions lib/developer_portal/lib/liquid/drops/user.rb
Expand Up @@ -91,6 +91,11 @@ def invitation
Drops::Invitation.new(@user.invitation)
end

desc "Returns true if user signed up with password"
def using_password?
@user.using_password?
end
lvillen marked this conversation as resolved.
Show resolved Hide resolved

desc %{
This method will return `true` for users using the built-in
Developer Portal authentication mechanisms and `false` for
Expand Down
Expand Up @@ -49,4 +49,18 @@ def setup

assert_response :success
end

test 'update should succeed with current password' do
login_as @buyer.admins.first
put :update, params: { user: {current_password: 'supersecret', username: 'test', email: 'test@example.com'}}
assert_redirected_to admin_account_users_path
assert_equal flash[:notice], 'User was successfully updated.'
end

test 'update should fail without current password' do
login_as @buyer.admins.first
put :update, params: { user: {username: 'test', email: 'test@example.com'}}
assert_response :success
assert_equal flash[:error], 'Current password is incorrect.'
end
end