summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Andrinopoulos <geoandri@gmail.com>2017-02-02 12:46:14 +0200
committerGeorge Andrinopoulos <geoandri@gmail.com>2017-02-02 12:47:23 +0200
commit19dda1606b4dc76160bf2198ab95f2998eccaec8 (patch)
treea423654e591727b8d15ef878e424f267abbc47a1
parentfabdcf818b5bfb45edd3a4ffbf1382b4ec9662d2 (diff)
downloadgitlab-ce-19dda1606b4dc76160bf2198ab95f2998eccaec8.tar.gz
Force new password after password reset via API
-rw-r--r--changelogs/unreleased/24606-force-password-reset-on-next-login.yml4
-rw-r--r--lib/api/users.rb2
-rw-r--r--spec/requests/api/users_spec.rb6
3 files changed, 12 insertions, 0 deletions
diff --git a/changelogs/unreleased/24606-force-password-reset-on-next-login.yml b/changelogs/unreleased/24606-force-password-reset-on-next-login.yml
new file mode 100644
index 00000000000..fd671d04a9f
--- /dev/null
+++ b/changelogs/unreleased/24606-force-password-reset-on-next-login.yml
@@ -0,0 +1,4 @@
+---
+title: Force new password after password reset via API
+merge_request:
+author: George Andrinopoulos
diff --git a/lib/api/users.rb b/lib/api/users.rb
index 11a7368b4c0..0ed468626b7 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -160,6 +160,8 @@ module API
end
end
+ user_params.merge!(password_expires_at: Time.now) if user_params[:password].present?
+
if user.update_attributes(user_params.except(:extern_uid, :provider))
present user, with: Entities::UserPublic
else
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index 5bf5bf0739e..f9127096953 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -305,6 +305,12 @@ describe API::Users, api: true do
expect(user.reload.bio).to eq('new test bio')
end
+ it "updates user with new password and forces reset on next login" do
+ put api("/users/#{user.id}", admin), { password: '12345678' }
+ expect(response).to have_http_status(200)
+ expect(user.reload.password_expires_at).to be < Time.now
+ end
+
it "updates user with organization" do
put api("/users/#{user.id}", admin), { organization: 'GitLab' }