You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/services/users/update_password_service.rb

32 lines
749 B

class Users::UpdatePasswordService < ApplicationService
Error = Class.new(StandardError)
attr_reader :user, :params
def initialize(user, params)
@user = user
@params = params
end
def call
Users::UpdatePasswordForm.new(params).validate!
raise Error, '旧密码不匹配' unless user.check_password?(params[:old_password])
ActiveRecord::Base.transaction do
user.update!(password: params[:password])
if user.gid.present?
# 同步修改gitlab密码
begin
Gitlab.client.edit_user(user.gid, password: params[:password])
rescue Exception => ex
Rails.logger.error(ex.message)
raise Error, '修改失败'
end
end
end
user
end
end