Commit 2baa6eb2 by Hoang Nam Nguyen

'Fix register page'

parent bc3c4cb0
class UsersController < ApplicationController
def show
@user = User.new
end
def new
@user = User.new
end
def confirm_email
def create
@user = User.new(email_params)
@user.validate_name = false
@user.validate_password = false
if @user.save
flash[:success] = "Please confirm your email"
UserMailer.welcome_email(@user.id).deliver_later
render 'confirm_email'
else
render 'show'
else
render 'new'
end
end
def create
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
@user.validate_name = true
@user.validate_password = true
if @user.update_attributes(user_params)
flash[:success] = "Welcome to the Ven Jobs!"
redirect_to @user
flash[:success] = "Sign up success"
render 'my_page'
else
render 'new'
render 'edit'
end
end
def login
@user = User.find(params[:id])
end
# def create
# @user = User.find(params[:id])
# @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
def user_params
params.require(:user).permit(:name, :email, :password_digest,
params.require(:user).permit(:name, :email, :password,
:password_confirmation)
end
......
......@@ -3,7 +3,7 @@ class UserMailer < ApplicationMailer
def welcome_email(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'
end
end
class Register < ApplicationRecord
end
class User < ApplicationRecord
attr_accessor :validate_name, :validate_password
attr_accessor :validate_name, :validate_password, :validate_confirm
before_save { self.email = email.downcase }
validates :name, presence: true, length: { maximum: 200 }, if: :validate_name
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
......@@ -7,5 +7,5 @@ class User < ApplicationRecord
format: {with: VALID_EMAIL_REGEX },
uniqueness: {case_sensitive: 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
......@@ -14,7 +14,7 @@
<div class="col-6 col-md-4">
<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>
</ul>
</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') %>
<h1 class="text-success text-center">Register</h1>
<%= provide(:title, "Register Email") %>
<div class="row ml-5">
<div class="col-md-10 col-md-offset-3">
<%= form_for(@user, url: create_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="mt-5 text-success text-center mb-5">
<h1>Register</h1>
</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>
<%= 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">
<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="row col-md-12 ml-5 mt-3">
<%= f.submit "Register", class: "btn btn-primary" %>
</div>
<% end %>
<div class="text-center">
<%= f.submit "Confirm your email", class: "btn btn-primary form-control ml-3 w-50" %>
</div>
</div>
<% end %>
\ No newline at end of file
<%= provide(:title, "Register Email") %>
<%= provide(:title, "Register Email Finish") %>
<div class="mt-5 text-success text-center mb-5">
<h1>Register</h1>
</div>
<%= form_for(@user, url: create_email_path) do |f| %>
<%= 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
<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
......@@ -10,12 +10,19 @@ Rails.application.routes.draw do
root 'top_pages#top_page'
resources :job, except: :show
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
post 'register/2', controller: :users, action: :confirm_email
get 'register/new', controller: :users, action: :new,as: :users_path
post 'register/create/:id', controller: :users, action: :create, as: :create_user
get 'login', controller: :users,action: :login,as: :login_user
get 'register/1',controller: :users,action: :new, as: :confirm_email
post 'register/2',controller: :users,action: :create, as: :create_email
# get 'register/:id',controller: :users,action: :show, as: :show_email
get 'register/:id/edit',controller: :users,action: :edit,as: :edit_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'
# get '/job',to: 'job#index'
# 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