diff options
Diffstat (limited to 'lib/tasks/gitlab/password.rake')
-rw-r--r-- | lib/tasks/gitlab/password.rake | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/tasks/gitlab/password.rake b/lib/tasks/gitlab/password.rake new file mode 100644 index 00000000000..02c28578a2a --- /dev/null +++ b/lib/tasks/gitlab/password.rake @@ -0,0 +1,31 @@ +# frozen_string_literal: true +namespace :gitlab do + namespace :password do + desc "GitLab | Password | Reset a user's password" + task :reset, [:username] => :environment do |_, args| + username = args[:username] || Gitlab::TaskHelpers.prompt('Enter username: ') + abort('Username can not be empty.') if username.blank? + + user = User.find_by(username: username) + abort("Unable to find user with username #{username}.") unless user + + password = Gitlab::TaskHelpers.prompt_for_password + password_confirm = Gitlab::TaskHelpers.prompt_for_password('Confirm password: ') + + user.password = password + user.password_confirmation = password_confirm + user.send_only_admin_changed_your_password_notification! + + unless user.save + message = <<~EOF + Unable to change password of the user with username #{username}. + #{user.errors.full_messages.to_sentence} + EOF + + abort(message) + end + + puts "Password successfully updated for user with username #{username}." + end + end +end |