Commit 7bc102de by Thanh Hung Pham

Validate message

parent b119f78f
class ConfirmationsController < Devise::ConfirmationsController class ConfirmationsController < Devise::ConfirmationsController
def update_confirm def update_confirm
@user = User.find(params[:user][:id]) @user = User.find_by(params[:user][:id])
@user.skip_password_validation = false
@user.skip_fullname_validation = false
if @user.update_attributes(user_params) if @user.update_attributes(user_params)
set_flash_message!(:notice, :confirmed) set_flash_message!(:notice, :confirmed)
redirect_to root_path redirect_to root_path
......
class RegistrationsController < Devise::RegistrationsController class RegistrationsController < Devise::RegistrationsController
# POST /resource
def create
build_resource(sign_up_params)
resource.skip_password_validation = true
resource.skip_fullname_validation = true
resource.save
yield resource if block_given?
if resource.persisted?
if resource.active_for_authentication?
set_flash_message! :notice, :signed_up
sign_up(resource_name, resource)
respond_with resource, location: after_sign_up_path_for(resource)
else
set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
expire_data_after_sign_in!
respond_with resource, location: after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
set_minimum_password_length
respond_with resource
end
end
protected protected
......
class User < ApplicationRecord class User < ApplicationRecord
attr_accessor :skip_password_validation, :skip_fullname_validation
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable # :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
...@@ -6,4 +7,6 @@ class User < ApplicationRecord ...@@ -6,4 +7,6 @@ class User < ApplicationRecord
:confirmable, :lockable :confirmable, :lockable
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, length: { maximum: 255 }, format: { with: VALID_EMAIL_REGEX } validates :email, length: { maximum: 255 }, format: { with: VALID_EMAIL_REGEX }
validates_presence_of :fullname, message: "can't be empty", unless: :skip_fullname_validation
validates_presence_of :password, message: "can't be empty", unless: :skip_fullname_validation
end end
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<%= f.label :fullname %> <%= f.label :fullname, 'Full name' %>
<%= f.text_field :fullname, autofocus: true, class: 'form-control' %> <%= f.text_field :fullname, autofocus: true, class: 'form-control' %>
</div> </div>
......
...@@ -30,4 +30,7 @@ ...@@ -30,4 +30,7 @@
# available at http://guides.rubyonrails.org/i18n.html. # available at http://guides.rubyonrails.org/i18n.html.
en: en:
hello: "Hello world" activerecord:
attributes:
user:
fullname: "Full Name"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment