Class: RegistrationsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/registrations_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/registrations_controller.rb', line 8

def create
  # Passwordless apps: there is no create-account-by-form. Logging a user in
  # straight from a signup POST would skip proof of email ownership, so we
  # treat "sign up" as a magic-link request — the create-or-login link (which
  # only fires after the recipient clicks it) does the account creation.
  unless Studio.auth_method?(:password)
    email = (params.dig(:user, :email) || params[:email]).to_s.strip.downcase
    if email.match?(URI::MailTo::EMAIL_REGEXP)
      token = MagicLink.generate(email: email)
      UserMailer.magic_link(email, token).deliver_later
    end
    return redirect_to , notice: "Check your inbox — we just emailed you a sign-in link."
  end

  @user = User.new(user_params)
  Studio.configure_new_user.call(@user)
  rescue_and_log(target: @user) do
    @user.save!
    set_app_session(@user)
    redirect_to root_path, notice: Studio.welcome_message.call(@user)
  end
rescue StandardError => e
  render :new, status: :unprocessable_entity
end

#newObject



4
5
6
# File 'app/controllers/registrations_controller.rb', line 4

def new
  @user = User.new
end