Class: Searls::Auth::CreatesUser

Inherits:
Object
  • Object
show all
Defined in:
lib/searls/auth/creates_user.rb

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Instance Method Details

#call(params) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/searls/auth/creates_user.rb', line 9

def call(params)
  user = Searls::Auth.config.user_finder_by_email.call(params[:email]) ||
    Searls::Auth.config.user_initializer.call(params)

  if user.persisted?
    Result.new(nil, false, ["An account already exists for that email address. <a href=\"#{(**forwardable_params(params))}\">Log in</a> instead?".html_safe])
  elsif (errors = Searls::Auth.config.validate_registration.call(user, params, [])).any?
    Result.new(nil, false, errors)
  elsif user.save
    Result.new(user, true)
  else
    Result.new(user, false, simplified_error_messages(user))
  end
end