Commit 051d5416 by Ba Toi Dang

Merge branch 'features/create_register_page' into 'master'

Features/create register page

See merge request !4
parents 608d29a9 b5e045ee
......@@ -2,6 +2,10 @@
@import "stylesheets/bootstrap.min.css";
@import "stylesheets/font-awesome.css";
body{
background: #eee;
}
.footer{
//position: absolute;
//bottom: 0;
......
class RegistrationsController < Devise::RegistrationsController
def new
@step = params[:step].to_i
if params[:code]
@user = User.find_by(confirmation_token: params[:code])
else
super
end
end
def create
if user_params[:step].to_i == 1
user = User.new(email: user_params[:email])
user.confirmation_token = Devise.friendly_token
user.skip_validation = true # skip validation of name and password
if user.save
UserMailer.registration_confirmation(user).deliver_later
flash[:notice] = 'Please check your email to fisnish registering member'
redirect_to register_path(step: 2)
else
flash[:error] = user.errors.full_messages.to_sentence
redirect_back(fallback_location: root_path)
end
else
redirect_to root_path
end
end
def complete_registering_user
user = User.find_by(confirmation_token: user_params[:confirmation_token])
user.attributes = user_params
if user.save
flash[:success] = "Successfully created..."
sign_in(user)
redirect_to after_sign_in_path_for(user)
else
flash[:error] = user.errors.full_messages.to_sentence
redirect_back(fallback_location: root_path)
end
end
private
def user_params
params.require(:user).permit(:email, :name, :password, :password_confirmation, :cv, :confirmation_token, :step)
end
def account_update_params
params.require(:user).permit(:email, :name, :password, :password_confirmation,:current_password, :cv, :confirmation_token)
end
end
class UserMailer < ApplicationMailer
default from: 'notify@venjob.com'
def registration_confirmation(user)
@user = user
mail(to: @user.email, subject: 'Welcome To VeNJOB! Confirm Your Email')
end
end
class User < ApplicationRecord
attr_accessor :skip_validation
before_save -> { skip_confirmation! }
has_many :apply_jobs
has_many :applied_jobs, through: :apply_jobs, class_name: 'Job', source: :job
has_many :favorite_jobs
......@@ -7,5 +9,19 @@ class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
:recoverable, :rememberable, :trackable, :validatable, :confirmable
# CarrierWave
mount_uploader :cv, CvUploader
# Validate
validates :email, presence: true, length: {maximum: 200}
validates :name, presence: true, length: {maximum: 200}, unless: :skip_validation
validates_size_of :cv, maximum: 5.megabytes, message: "size should be less than 5MB"
private
def password_required?
return false if skip_validation
super
end
end
class CvUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url(*args)
# # For Rails 3.1+ asset pipeline compatibility:
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
#
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
# process scale: [200, 300]
#
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files:
# version :thumb do
# process resize_to_fit: [50, 50]
# end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_whitelist
%w(doc pdf xls xlsx zip)
end
# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
end
......@@ -3,7 +3,6 @@
<div class="navbar-header">
<a class="navbar-brand" href="/">WorldJob</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="/">Home</a></li>
</ul>
......@@ -18,12 +17,12 @@
</li>
<%- else -%>
<li>
<%= link_to new_user_session_path do %>
<i class="fa fa-sign-in" aria-hidden="true"></i>Signin
<% end %></li>
<%= link_to register_path(step: 1) do %>
<i class="fa fa-plus-circle" aria-hidden="true"></i> Register
<% end %>
</li>
<li><a href="#"><i class="fa fa-plus" aria-hidden="true"></i> Register</a></li>
<%- end -%>
<li><a href="#"><i class="fa fa-star" aria-hidden="true"></i></span> Favorite</a></li>
<li><a href="#"><i class="fa fa-history" aria-hidden="true"></i></span> History</a></li>
</ul>
......
<p>You're on your way!</p>
<p>Let's confirm your email address.</p>
<p>By clicking on the following link, you are confirming your email address and agreeing to VeNJOB's Terms of Service.</p>
<p>
<%= link_to "Click here", register_url(step: 3, code: @user.confirmation_token), class: "btn btn-primary" %>
</p>
<p>You're on your way!</p>
<p>Let's confirm your email address.</p>
<p>By clicking on the following link, you are confirming your email address and agreeing to VeNJOB's Terms of Service.</p>
<p>
<%= link_to "Click here", "/register/3?code=#{@user.confirmation_token}", class: "btn btn-primary" %>
</p>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="field form-group">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, class: "form-control", placeholder: 'Input your email' %>
</div>
<div class="field form-group">
<%= f.hidden_field :step, value: '1'%>
</div>
<div class="actions">
<%= f.submit "Confirm your email", class: "btn btn-default" %>
</div>
<%- end -%>
<p>Thank you for register our service, an confirmation email with registration link has been sent to your email.</p>
<p> Please check your email within 24 hours.</p>
<p> Please note that the registration link is only valid for 24 hours. </p>
<p> Over that period, you will have to register your email again.</p>
<%= form_for(resource, as: resource_name, url: complete_registering_path, method: :patch, :html => {:multipart => true} ) do |f| %>
<%= devise_error_messages! %>
<div class="field form-group">
<%= f.label :email %><br />
<%= f.email_field :email, class: "form-control", disabled: true %>
</div>
<div class="field form-group">
<%= f.label :name %><br />
<%= f.text_field :name, autofocus: true, class: "form-control" %>
</div>
<div class="field form-group">
<%= f.label :password %>
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off", class: 'form-control' %>
</div>
<div class="field form-group">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control' %>
</div>
<div class="field form-group">
<%= f.label :cv %><br />
<%= f.file_field :cv, class: 'form-control' %>
</div>
<div class="field form-group">
<%= f.hidden_field :confirmation_token %>
</div>
<div class="actions">
<%= f.submit "Register", class: "btn btn-default" %>
</div>
<%- end -%>
<div class="row">
<div class="container">
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, multipart: true }) do |f| %>
<%= devise_error_messages! %>
<div class="field form-group">
<%= f.label :email %><br />
<%= f.email_field :email, class: "form-control", disabled: true %>
</div>
<div class="field form-group">
<%= f.label :name, 'Full name' %><br />
<%= f.text_field :name, autofocus: true, class: "form-control" %>
</div>
<div class="field form-group">
<%= f.label :cv, 'My Cv' %><br />
<%= f.file_field :cv, class: "form-control" %>
</div>
<div class="field form-group">
<%= f.label :password, 'New password' %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, autocomplete: "off", class: "form-control" %>
<% if @minimum_password_length %>
<em><%= @minimum_password_length %> characters minimum</em>
<% end %>
</div>
<div class="field form-group">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off", class: "form-control" %>
</div>
<div class="field form-group">
<%= f.label :current_password, 'Old password' %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password, autocomplete: "off", class: "form-control" %>
</div>
<div class="actions">
<%= f.submit "Update", class: "btn btn-primary" %>
</div>
<% end %>
</div>
</div>
<div class="row">
<div class="container">
<h2>Register</h2>
<%- if @step == 1 -%>
<%= render "users/registrations/step1" %>
<%- elsif @step == 2 -%>
<%= render "users/registrations/step2" %>
<%- elsif @step == 3 -%>
<%= render "users/registrations/step3" %>
<%- end -%>
</div>
</div>
<div class="row">
<div class="container">
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="field form-group">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, class: "form-control" %>
</div>
<div class="field form-group">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "off", class: "form-control" %>
</div>
<% if devise_mapping.rememberable? -%>
<div class="field form-group">
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
</div>
<% end -%>
<div class="actions form-group">
<%= f.submit "Log in", class: "btn btn-default" %>
</div>
<% end %>
</div>
</div>
require 'carrierwave/orm/activerecord'
......@@ -136,7 +136,7 @@ Devise.setup do |config|
# initial account confirmation) to be applied. Requires additional unconfirmed_email
# db field (see migrations). Until confirmed, new email is stored in
# unconfirmed_email column, and copied to email column on successful confirmation.
config.reconfirmable = true
config.reconfirmable = false
# Defines which key will be used when confirming an account
# config.confirmation_keys = [:email]
......@@ -157,7 +157,7 @@ Devise.setup do |config|
# ==> Configuration for :validatable
# Range for password length.
config.password_length = 6..128
config.password_length = 8..128
# Email regex used to validate email formats. It simply asserts that
# one (and only one) @ exists in the given string. This is mainly
......@@ -223,7 +223,7 @@ Devise.setup do |config|
# Turn scoped views on. Before rendering "sessions/new", it will first check for
# "users/sessions/new". It's turned off by default because it's slower if you
# are using only default views.
# config.scoped_views = false
config.scoped_views = true
# Configure the default scope given to Warden. By default it's the first
# devise role declared in your routes (usually :user).
......
Rails.application.routes.draw do
require 'sidekiq/web'
root 'jobs#index'
devise_for :users
devise_for :users, :controllers => {:registrations => "registrations"}
as :user do
get 'register/:step', to: 'registrations#new', as: :register
patch 'complete_registering' => 'registrations#complete_registering_user'
end
resources :cities, only: [:index, :show]
resources :industries, only: [:index, :show]
......
class AddConfirmableToDevise < ActiveRecord::Migration[5.1]
def change
add_column :users, :confirmation_token, :string
add_column :users, :confirmed_at, :datetime
add_column :users, :confirmation_sent_at, :datetime
# add_column :users, :unconfirmed_email, :string # Only if using reconfirmable
add_index :users, :confirmation_token, unique: 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