9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'app/controllers/groovestack/auth/passwordless/sessions_controller.rb', line 9
def create
self.resource = resource_class.find_for_authentication(email: create_params[:email])
if resource.blank?
u = ::User.new(email: create_params[:email], password: ::Devise.friendly_token[0, 20])
u.save!
self.resource = u
end
send_magic_link(resource)
respond_to do |format|
format.html { redirect_to(after_magic_link_sent_path_for(resource), status: devise_redirect_status) }
format.json do
render json: { success: true, resource: resource.as_json, message: 'Magic link sent.' }, status: :ok
end
end
rescue StandardError => e
msg = "Passwordless Magic Link Send Failure for #{create_params[:email]}: #{e}"
::Groovestack::Base.notify_error('Groovestack::Auth::Passwordless::SessionsController', msg)
respond_to do |format|
format.html { render :new, status: devise_error_status }
format.json do
render json: { error: 'User not found or unable to register account. Our team has been notified.' },
status: :not_found
end
end
end
|