Commit 81c4f237 by Xuan Trung Le

f/Create register page

parent 364b38c6
class RegistrationsController < Devise::RegistrationsController
def new
@step = params[:step]
if params[:code]
@user = User.find_by(confirmation_token: params[:code])
else
super
end
end
def create
if user_params[:step].to_s == '1'
user = User.new(email: user_params[:email])
user.confirmation_token = Devise.friendly_token
user.skip_password_validation = true
respond_to do |format|
if user.save
UserMailer.registration_confirmation(user).deliver
flash[:notice] = 'Please check your email to fisnish registering member'
format.html { redirect_to register_path(step: 2) }
else
flash[:error] = user.errors.full_messages.to_sentence
format.html { redirect_back(fallback_location: root_path) }
end
end
else
redirect_to root_path
end
end
def complete_registering_user
user = User.find_by(confirmation_token: user_params[:confirmation_token])
user.name = user_params[:name]
user.password = user_params[:password]
user.password_confirmation = user_params[:password_confirmation]
user.cv = user_params[:cv]
respond_to do |format|
if user.save
flash[:success] = "Successfully created..."
sign_in(user)
format.html { redirect_to after_sign_in_path_for(user) } # auto login after created successfully
else
flash[:error] = user.errors.full_messages.to_sentence
format.html { redirect_back(fallback_location: root_path) }
end
end
end
private
def user_params
params.require(:user).permit(:email, :name, :password, :password_confirmation, :cv, :confirmation_token, :step)
end
end
class UserMailer < ApplicationMailer
default from: 'from@example.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_password_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,23 @@ 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_password_validation
validate :cv_size_validation
private
def password_required?
return false if skip_password_validation
super
end
def cv_size_validation
errors[:cv] << "size should be less than 5MB" if cv.size > 5.megabytes
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
<div class="col-md-<%= column %> maxH109">
<div class="job-intro well mr0 mrBot20 maxH89">
<<<<<<< 28eda34d875adbaa9af263755cbdb98465bc5939
<h4 class="mr0"><%= link_to industry.name, industry_jobs_path(industry) %></h4>
=======
<h4 class="mr0"><%= link_to industry.name, "#{jobs_path}/industry/#{industry.id}" %></h4>
>>>>>>> Create the TOP, industry_list, city_list, job_detail pages.
<p>Jobs: <span class="badge"><%= industry.jobs_count %></span></p>
</div>
</div>
<% flash.each do |name, msg| %>
<div class="alert alert-info alert-dismissable fade in" style="position: fixed; right: 0">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<strong><%= "#{name}!" %></strong> <%= msg %>
</div>
<% 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>
......@@ -11,12 +10,19 @@
<ul class="nav navbar-nav navbar-right">
<%- if current_user -%>
<li><a href="#"><i class="fa fa-sign-in" aria-hidden="true"></i> My Page</a></li>
<li><a href="#"><i class="fa fa-plus" aria-hidden="true"></i> Logout</a></li>
<li>
<%= link_to destroy_user_session_path, method: :delete do %>
<i class="fa fa-sign-out" aria-hidden="true"></i> Logout
<% end %>
</li>
<%- else -%>
<li><a href="#"><i class="fa fa-sign-in" aria-hidden="true"></i> Login</a></li>
<li><a href="#"><i class="fa fa-plus" aria-hidden="true"></i> Register</a></li>
<li><a href="<%= new_user_session_path %>"><i class="fa fa-sign-in" aria-hidden="true"></i> Login</a></li>
<li>
<%= link_to "/register/1" do %>
<i class="fa fa-plus-circle" aria-hidden="true"></i> Register
<% end %>
</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>
......
......@@ -3,35 +3,11 @@
<head>
<title>Venjob</title>
<%= csrf_meta_tags %>
<<<<<<< 28eda34d875adbaa9af263755cbdb98465bc5939
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
=======
<link
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
rel="stylesheet"
integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN"
crossorigin="anonymous">
<script
src="https://code.jquery.com/jquery-3.2.1.js"
integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="
crossorigin="anonymous"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
>>>>>>> Create the TOP, industry_list, city_list, job_detail pages.
<body>
<%= render "layouts/menu" %>
<%= yield %>
......
<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", "http://localhost:3000/register/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 -%>
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>
<div class="field">
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, autocomplete: "off" %>
<% if @minimum_password_length %>
<br />
<em><%= @minimum_password_length %> characters minimum</em>
<% end %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Update" %>
</div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
<%= link_to "Back", :back %>
<div class="row">
<div class="container">
<h2>Register</h2>
<%- if @step.to_s == '1' -%>
<%= render "users/registrations/step1" %>
<%- elsif @step.to_s == '2' -%>
<%= render "users/registrations/step2" %>
<%- elsif @step.to_s == '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>
......@@ -51,4 +51,14 @@ Rails.application.configure do
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "example.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USER"],
password: ENV["GMAIL_PASSWORD"]
}
end
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
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