Commit 2baa6eb2 by Hoang Nam Nguyen

'Fix register page'

parent bc3c4cb0
class UsersController < ApplicationController class UsersController < ApplicationController
def show
@user = User.new
end
def new def new
@user = User.new @user = User.new
end end
def confirm_email def create
@user = User.new(email_params) @user = User.new(email_params)
@user.validate_name = false @user.validate_name = false
@user.validate_password = false @user.validate_password = false
if @user.save if @user.save
flash[:success] = "Please confirm your email" flash[:success] = "Please confirm your email"
UserMailer.welcome_email(@user.id).deliver_later UserMailer.welcome_email(@user.id).deliver_later
render 'confirm_email'
else
render 'show' render 'show'
else
render 'new'
end end
end end
def create def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id]) @user = User.find(params[:id])
@user.validate_name = true @user.validate_name = true
@user.validate_password = true @user.validate_password = true
if @user.update_attributes(user_params) if @user.update_attributes(user_params)
flash[:success] = "Welcome to the Ven Jobs!" flash[:success] = "Sign up success"
redirect_to @user render 'my_page'
else else
render 'new' render 'edit'
end end
end end
def login # def create
@user = User.find(params[:id]) # @user = User.find(params[:id])
end # @user.validate_name = true
# @user.validate_password = true
# if @user.update_attributes(user_params)
# flash[:success] = "Welcome to the Ven Jobs!"
# redirect_to @user
# else
# render 'new'
# end
# end
# def login
# @user = User.find(params[:id])
# end
private private
def user_params def user_params
params.require(:user).permit(:name, :email, :password_digest, params.require(:user).permit(:name, :email, :password,
:password_confirmation) :password_confirmation)
end end
......
...@@ -3,7 +3,7 @@ class UserMailer < ApplicationMailer ...@@ -3,7 +3,7 @@ class UserMailer < ApplicationMailer
def welcome_email(user_id) def welcome_email(user_id)
@user = User.find(user_id) @user = User.find(user_id)
@url = users_path_path @url = edit_user_url(@user.id)
mail to: @user.email, subject: 'Welcome to My Ventura Jobs' mail to: @user.email, subject: 'Welcome to My Ventura Jobs'
end end
end end
class Register < ApplicationRecord
end
class User < ApplicationRecord class User < ApplicationRecord
attr_accessor :validate_name, :validate_password attr_accessor :validate_name, :validate_password, :validate_confirm
before_save { self.email = email.downcase } before_save { self.email = email.downcase }
validates :name, presence: true, length: { maximum: 200 }, if: :validate_name validates :name, presence: true, length: { maximum: 200 }, if: :validate_name
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
...@@ -7,5 +7,5 @@ class User < ApplicationRecord ...@@ -7,5 +7,5 @@ class User < ApplicationRecord
format: {with: VALID_EMAIL_REGEX }, format: {with: VALID_EMAIL_REGEX },
uniqueness: {case_sensitive: false} uniqueness: {case_sensitive: false}
has_secure_password(validations: false) has_secure_password(validations: false)
validates :password, presence: true, length: { minimum: 6}, if: :validate_password validates :password, presence: true, length: { minimum: 5}, if: :validate_password
end end
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<div class="col-6 col-md-4"> <div class="col-6 col-md-4">
<ul class="nav navbar-nav" id="slidebar"> <ul class="nav navbar-nav" id="slidebar">
<li><%= link_to 'Register',sign_up_path, class: 'btn btn-info distance mt-4 no-gutters'%></li> <li><%= link_to 'Register',confirm_email_path, class: 'btn btn-info distance mt-4 no-gutters'%></li>
<li><%= link_to 'History','#',class: 'btn btn-info distance mt-1 no-gutters'%></li> <li><%= link_to 'History','#',class: 'btn btn-info distance mt-1 no-gutters'%></li>
</ul> </ul>
</div> </div>
......
<%= provide(:title, "Register Email Finish") %>
<div class="mt-5 text-success text-center mb-5">
<h1>Register</h1>
</div>
<p>Thank you for register our service, an confirmation email with registration link has been sent to your email. Please check your email within 24 hours.<br></br>Please note that the registration link is only valid for 24 hours.Over that period, you will have to register your email again.</p>
\ No newline at end of file
<% provide(:title, 'User information Form') %>
<h1 class="text-success text-center">Register</h1>
<div class="row ml-5">
<div class="col-md-10 col-md-offset-3">
<%= form_for(@user, url: update_user_path) do |f| %>
<%= render 'shared/error_messages'%>
<div class="row mt-5 mb-5">
<div class= "col-md-2">
<strong><i><%= f.label :name,'Full Name'%></i></strong>
</div>
<div class="col-md-10">
<%= f.text_field :name, class: 'form-control' %>
</div>
</div>
<div class="row mt-3 mb-5">
<div class="col-md-2">
<strong><i><%= f.label :email %></i></strong>
</div>
<div class="col-md-10">
<%= f.email_field :email, class: 'form-control' %>
</div>
</div>
<div class="row mt-3 mb-5">
<div class="col-md-2">
<strong><i><%= f.label :password %></i></strong>
</div>
<div class="col-md-10">
<%= f.password_field :password, class: 'form-control' %>
</div>
</div>
<div class="row mt-3 mb-5">
<div class="col-md-2">
<strong><i><%= f.label :password_confirmation, "Password Confirmation" %></i></strong>
</div>
<div class="col-md-10">
<%= f.password_field :password_confirmation, class: 'form-control' %>
</div>
</div>
<div class="row col-md-12 ml-5 mt-3">
<%= f.submit "Register", class: "btn btn-primary" %>
</div>
<% end %>
</div>
</div>
<%= provide(:title, "My Page") %>
\ No newline at end of file
<% provide(:title, 'User information Form') %> <%= provide(:title, "Register Email") %>
<h1 class="text-success text-center">Register</h1>
<div class="row ml-5"> <div class="mt-5 text-success text-center mb-5">
<div class="col-md-10 col-md-offset-3"> <h1>Register</h1>
<%= form_for(@user, url: create_user_path) do |f| %> </div>
<%= render 'shared/error_messages'%>
<div class="row mt-5 mb-5">
<div class= "col-md-2">
<strong><i><%= f.label :name,'Full Name'%></i></strong>
</div>
<div class="col-md-10">
<%= f.text_field :name, class: 'form-control' %>
</div>
</div>
<div class="row mt-3 mb-5"> <%= form_for(@user, url: create_email_path(@user.id)) do |f| %>
<%= render 'shared/error_messages'%>
<div class="row mt-3 mb-3">
<div class="col-md-2"> <div class="col-md-2">
<strong><i><%= f.label :email %></i></strong> <strong><i><%= f.label :email %></i></strong>
</div> </div>
<div class="col-md-10"> <div class="col-md-10">
<%= f.email_field :email, class: 'form-control' %> <%= f.email_field :email, class: 'form-control',placeholder: 'Enter Email' %>
</div> </div>
</div> </div>
<div class="row mt-3 mb-5"> <div class="text-center">
<div class="col-md-2"> <%= f.submit "Confirm your email", class: "btn btn-primary form-control ml-3 w-50" %>
<strong><i><%= f.label :password %></i></strong>
</div>
<div class="col-md-10">
<%= f.password_field :password, class: 'form-control' %>
</div> </div>
</div> <% end %>
\ No newline at end of file
<div class="row mt-3 mb-5">
<div class="col-md-2">
<strong><i><%= f.label :password_confirmation, "Password Confirmation" %></i></strong>
</div>
<div class="col-md-10">
<%= f.password_field :password_confirmation, class: 'form-control' %>
</div>
</div>
<div class="row col-md-12 ml-5 mt-3">
<%= f.submit "Register", class: "btn btn-primary" %>
</div>
<% end %>
</div>
</div>
<%= provide(:title, "Register Email") %> <%= provide(:title, "Register Email Finish") %>
<div class="mt-5 text-success text-center mb-5"> <div class="mt-5 text-success text-center mb-5">
<h1>Register</h1> <h1>Register</h1>
</div> </div>
<p>Thank you for register our service, an confirmation email with registration link has been sent to your email. Please check your email within 24 hours.<br></br>Please note that the registration link is only valid for 24 hours.Over that period, you will have to register your email again.</p>
<%= form_for(@user, url: create_email_path) do |f| %> \ No newline at end of file
<%= render 'shared/error_messages'%>
<div class="row mt-3 mb-3">
<div class="col-md-2">
<strong><i><%= f.label :email %></i></strong>
</div>
<div class="col-md-10">
<%= f.email_field :email, class: 'form-control',placeholder: 'Enter Email' %>
</div>
</div>
<div class="text-center">
<%= f.submit "Confirm your email", class: "btn btn-primary form-control ml-3 w-50" %>
</div>
<% end %>
\ No newline at end of file
...@@ -10,12 +10,19 @@ Rails.application.routes.draw do ...@@ -10,12 +10,19 @@ Rails.application.routes.draw do
root 'top_pages#top_page' root 'top_pages#top_page'
resources :job, except: :show resources :job, except: :show
get 'detail/:id', controller: :job, action: :detail, as: :job_detail get 'detail/:id', controller: :job, action: :detail, as: :job_detail
get 'register/1', controller: :users, action: :show, as: :sign_up
get 'register/2', controller: :users, action: :confirm_email,as: :create_email get 'register/1',controller: :users,action: :new, as: :confirm_email
post 'register/2', controller: :users, action: :confirm_email post 'register/2',controller: :users,action: :create, as: :create_email
get 'register/new', controller: :users, action: :new,as: :users_path # get 'register/:id',controller: :users,action: :show, as: :show_email
post 'register/create/:id', controller: :users, action: :create, as: :create_user get 'register/:id/edit',controller: :users,action: :edit,as: :edit_user
get 'login', controller: :users,action: :login,as: :login_user patch 'register/:id',controller: :users,action: :update,as: :update_user
get '/my',controller: :users,action: :my_page,as: :my_page
# get 'register/1', controller: :users, action: :show, as: :sign_up
# get 'register/2', controller: :users, action: :confirm_email,as: :create_email
# post 'register/2', controller: :users, action: :confirm_email
# get 'register/new', controller: :users, action: :new,as: :register_users
# post 'register/create', controller: :users, action: :create, as: :create_user
# get 'login', controller: :users,action: :login,as: :login_user
mount Sidekiq::Web => '/sidekiq' mount Sidekiq::Web => '/sidekiq'
# get '/job',to: 'job#index' # get '/job',to: 'job#index'
# get '/job/detail', to: 'job#detail' # get '/job/detail', to: 'job#detail'
......
class CreateRegisters < ActiveRecord::Migration[5.1]
def change
create_table :registers do |t|
t.string :email
t.timestamps
end
end
end
REDIS0006ܳCZV
\ No newline at end of file
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
email: MyString
two:
email: MyString
require 'test_helper'
class RegisterTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# 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