4
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'app/services/cats/core/user_service.rb', line 4
def change_password(email, old_password, new_password, password_confirmation)
raise(StandardError, "Password and confirmation do not match.") unless new_password == password_confirmation
user = User.find_by(email: email)
raise(StandardError, "User with email '#{email}' could not be found.") unless user
raise(StandardError, "Old password for user '#{email}' is not correct.") unless user.authenticate(old_password)
user.password = new_password
user.password_confirmation = password_confirmation
user.save!
user
end
|