tabletop-companion/app/controllers/users_controller.rb

36 lines
841 B
Ruby
Raw Normal View History

2024-05-26 10:45:10 +00:00
# frozen_string_literal: true
2024-04-14 19:01:32 +00:00
class UsersController < ApplicationController
2024-04-21 14:01:10 +00:00
skip_before_action :authenticate, only: [ :new, :create ]
2024-04-14 19:01:32 +00:00
def new
@user = User.new
end
def create
@user = User.new(user_params)
if @user.save
token = @user.generate_token_for(:email_verification)
UserMailer.with(user: @user, token: token).email_verification.deliver_later
flash[:notice] = t(".success", name: @user.first_name)
2024-04-21 14:01:10 +00:00
redirect_to login_path
2024-04-14 19:01:32 +00:00
else
flash[:alert] = t(".error", error: @user.errors.full_messages.to_sentence)
render :new, status: :unprocessable_entity
end
end
private
def user_params
params.require(:user).permit(
:username,
:password,
:password_confirmation,
:email,
:first_name,
:last_name,
)
end
end