Class: CommandTower::Deserializers::Auth::PasswordReset::ResetDeserializer

Inherits:
CommandTower::Deserializers::ApplicationDeserializer show all
Defined in:
app/deserializers/command_tower/deserializers/auth/password_reset/reset_deserializer.rb

Defined Under Namespace

Classes: Input

Instance Method Summary collapse

Methods inherited from CommandTower::Deserializers::ApplicationDeserializer

call

Instance Method Details

#call(params) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/deserializers/command_tower/deserializers/auth/password_reset/reset_deserializer.rb', line 10

def call(params)
  token = params[:token].to_s.strip
  password = params[:password].to_s
  password_confirmation = params[:passwordConfirmation].to_s.presence || params[:password_confirmation].to_s

  errors = {}
  errors[:token] = "Token is required" if token.blank?
  errors[:password] = "Password is required" if password.blank?
  errors[:passwordConfirmation] = "Password confirmation is required" if password_confirmation.blank?

  return failure(errors:) if errors.any?

  email = params[:email].to_s.strip.downcase
  email = nil if email.blank?

  success(Input.new(token:, password:, password_confirmation:, email:))
end