Fix user edit/registration
- Don't require password to edit - Fix errors on registration form
This commit is contained in:
parent
ad4fa94bfa
commit
c4715b172d
|
@ -14,6 +14,7 @@ class UsersController < ApplicationController
|
|||
session[:user_id] = @user.id
|
||||
redirect_to root_path, notice: t(".account_created")
|
||||
else
|
||||
flash.now.alert = t(".create_failed")
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,15 @@ class User < ApplicationRecord
|
|||
validates :email,
|
||||
format: { with: /\A.*@.*\..*\z/ } # Only very basic regex
|
||||
|
||||
validates :password, confirmation: true
|
||||
validates :password,
|
||||
confirmation: true,
|
||||
length: { in: 12..300 },
|
||||
presence: true,
|
||||
if: :validate_password?
|
||||
|
||||
validates :password_confirmation,
|
||||
presence: true,
|
||||
if: :validate_password?
|
||||
|
||||
def to_param
|
||||
username
|
||||
|
@ -25,4 +33,10 @@ class User < ApplicationRecord
|
|||
def full_name
|
||||
"#{first_name} #{last_names}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate_password?
|
||||
new_record? || password_digest_changed?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<%= turbo_stream.replace "flash_wrapper" do %>
|
||||
<%= render "shared/flash" %>
|
||||
<% end %>
|
||||
|
||||
<%= turbo_stream.replace "user_form" do %>
|
||||
<%= render partial: "form",
|
||||
locals: {
|
||||
user: @user,
|
||||
button_text: t(".register"),
|
||||
title: t(".register"),
|
||||
} %>
|
||||
<% end %>
|
|
@ -1,5 +1,6 @@
|
|||
en:
|
||||
users:
|
||||
create_failed: Could not create user account, please correct the errors below.
|
||||
account_created: Account created!
|
||||
account_updated: Your details have been updated.
|
||||
update_failed: Could not update your details.
|
||||
|
|
Loading…
Reference in New Issue