Commit d166e9de by Xuan Trung Le

fix bugs

parent bc1b104a
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
@import "stylesheets/bootstrap.min.css"; @import "stylesheets/bootstrap.min.css";
@import "stylesheets/font-awesome.css"; @import "stylesheets/font-awesome.css";
body{
background: #eee;
}
.footer{ .footer{
//position: absolute; //position: absolute;
//bottom: 0; //bottom: 0;
......
...@@ -9,20 +9,17 @@ class RegistrationsController < Devise::RegistrationsController ...@@ -9,20 +9,17 @@ class RegistrationsController < Devise::RegistrationsController
end end
def create def create
if user_params[:step].to_s == '1' if user_params[:step].to_i == 1
user = User.new(email: user_params[:email]) user = User.new(email: user_params[:email])
user.confirmation_token = Devise.friendly_token user.confirmation_token = Devise.friendly_token
user.skip_password_validation = true user.skip_validation = true # skip validation of name and password
respond_to do |format|
if user.save if user.save
UserMailer.registration_confirmation(user).deliver UserMailer.registration_confirmation(user).deliver_later
flash[:notice] = 'Please check your email to fisnish registering member' flash[:notice] = 'Please check your email to fisnish registering member'
format.html { redirect_to register_path(step: 2) } redirect_to register_path(step: 2)
else else
flash[:error] = user.errors.full_messages.to_sentence flash[:error] = user.errors.full_messages.to_sentence
format.html { redirect_back(fallback_location: root_path) } redirect_back(fallback_location: root_path)
end
end end
else else
redirect_to root_path redirect_to root_path
...@@ -31,24 +28,17 @@ class RegistrationsController < Devise::RegistrationsController ...@@ -31,24 +28,17 @@ class RegistrationsController < Devise::RegistrationsController
def complete_registering_user def complete_registering_user
user = User.find_by(confirmation_token: user_params[:confirmation_token]) user = User.find_by(confirmation_token: user_params[:confirmation_token])
user.name = user_params[:name] user.attributes = user_params
user.password = user_params[:password]
user.password_confirmation = user_params[:password_confirmation]
user.cv = user_params[:cv]
respond_to do |format|
if user.save if user.save
flash[:success] = "Successfully created..." flash[:success] = "Successfully created..."
sign_in(user) sign_in(user)
format.html { redirect_to after_sign_in_path_for(user) } # auto login after created successfully redirect_to after_sign_in_path_for(user)
else else
flash[:error] = user.errors.full_messages.to_sentence flash[:error] = user.errors.full_messages.to_sentence
format.html { redirect_back(fallback_location: root_path) } redirect_back(fallback_location: root_path)
end end
end end
end
private private
def user_params def user_params
params.require(:user).permit(:email, :name, :password, :password_confirmation, :cv, :confirmation_token, :step) params.require(:user).permit(:email, :name, :password, :password_confirmation, :cv, :confirmation_token, :step)
......
class User < ApplicationRecord class User < ApplicationRecord
attr_accessor :skip_password_validation attr_accessor :skip_validation
before_save -> { skip_confirmation! } before_save -> { skip_confirmation! }
has_many :apply_jobs has_many :apply_jobs
has_many :applied_jobs, through: :apply_jobs, class_name: 'Job', source: :job has_many :applied_jobs, through: :apply_jobs, class_name: 'Job', source: :job
...@@ -16,16 +16,12 @@ class User < ApplicationRecord ...@@ -16,16 +16,12 @@ class User < ApplicationRecord
# Validate # Validate
validates :email, presence: true, length: {maximum: 200} validates :email, presence: true, length: {maximum: 200}
validates :name, presence: true, length: {maximum: 200}, unless: :skip_password_validation validates :name, presence: true, length: {maximum: 200}, unless: :skip_validation
validate :cv_size_validation validates_size_of :cv, maximum: 5.megabytes, message: "size should be less than 5MB"
private private
def password_required? def password_required?
return false if skip_password_validation return false if skip_validation
super super
end end
def cv_size_validation
errors[:cv] << "size should be less than 5MB" if cv.size > 5.megabytes
end
end end
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<%- else -%> <%- else -%>
<li><a href="<%= new_user_session_path %>"><i class="fa fa-sign-in" aria-hidden="true"></i> Login</a></li> <li><a href="<%= new_user_session_path %>"><i class="fa fa-sign-in" aria-hidden="true"></i> Login</a></li>
<li> <li>
<%= link_to "/register/1" do %> <%= link_to register_path(step: 1) do %>
<i class="fa fa-plus-circle" aria-hidden="true"></i> Register <i class="fa fa-plus-circle" aria-hidden="true"></i> Register
<% end %> <% end %>
</li> </li>
......
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
<p>By clicking on the following link, you are confirming your email address and agreeing to VeNJOB's Terms of Service.</p> <p>By clicking on the following link, you are confirming your email address and agreeing to VeNJOB's Terms of Service.</p>
<p> <p>
<%= link_to "Click here", "http://localhost:3000/register/3?code=#{@user.confirmation_token}", class: "btn btn-primary" %> <%= link_to "Click here", register_url(step: 3, code: @user.confirmation_token), class: "btn btn-primary" %>
</p> </p>
<div class="row"> <div class="row">
<div class="container"> <div class="container">
<h2>Register</h2> <h2>Register</h2>
<%- if @step.to_s == '1' -%> <%- if @step.to_i == 1 -%>
<%= render "users/registrations/step1" %> <%= render "users/registrations/step1" %>
<%- elsif @step.to_s == '2' -%> <%- elsif @step.to_i == 2 -%>
<%= render "users/registrations/step2" %> <%= render "users/registrations/step2" %>
<%- elsif @step.to_s == '3' -%> <%- elsif @step.to_i == 3 -%>
<%= render "users/registrations/step3" %> <%= render "users/registrations/step3" %>
<%- end -%> <%- end -%>
</div> </div>
......
...@@ -51,14 +51,18 @@ Rails.application.configure do ...@@ -51,14 +51,18 @@ Rails.application.configure do
# Use an evented file watcher to asynchronously detect changes in source code, # Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem. # routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker config.file_watcher = ActiveSupport::EventedFileUpdateChecker
config.action_mailer.default_url_options = { :protocol => 'http', :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { address: 'localhost',
port: 1025 }
config.action_mailer.smtp_settings = { # config.action_mailer.smtp_settings = {
address: "smtp.gmail.com", # address: "smtp.gmail.com",
port: 587, # port: 587,
domain: "example.com", # domain: "example.com",
authentication: "plain", # authentication: "plain",
enable_starttls_auto: true, # enable_starttls_auto: true,
user_name: ENV["GMAIL_USER"], # user_name: ENV["GMAIL_USER"],
password: ENV["GMAIL_PASSWORD"] # password: ENV["GMAIL_PASSWORD"]
} # }
end end
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