Commit a65e9725 by Hoang Phuc

User management using gem devise

parent 1f4ca07e
Pipeline #554 failed with stages
in 0 seconds
......@@ -23,6 +23,7 @@ gem 'jbuilder', '~> 2.7'
# Use Active Model has_secure_password
gem 'bcrypt', '~> 3.1.7'
gem 'devise'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
......
......@@ -59,6 +59,7 @@ GEM
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
bcrypt (3.1.13)
bcrypt (3.1.13-java)
bindex (0.8.1)
bootsnap (1.4.6)
msgpack (~> 1.0)
......@@ -77,6 +78,12 @@ GEM
childprocess (3.0.0)
concurrent-ruby (1.1.6)
crass (1.0.6)
devise (4.7.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
erubi (1.9.0)
ffi (1.12.2)
ffi (1.12.2-java)
......@@ -121,6 +128,7 @@ GEM
mini_portile2 (~> 2.4.0)
nokogiri (1.10.9-x86-mingw32)
mini_portile2 (~> 2.4.0)
orm_adapter (0.5.0)
public_suffix (4.0.3)
puma (4.3.3)
nio4r (~> 2.0)
......@@ -162,6 +170,9 @@ GEM
rb-inotify (0.10.1)
ffi (~> 1.0)
regexp_parser (1.7.0)
responders (3.0.0)
actionpack (>= 5.0)
railties (>= 5.0)
ruby_dep (1.5.0)
rubyzip (2.3.0)
sass-rails (6.0.0)
......@@ -203,6 +214,8 @@ GEM
thread_safe (~> 0.1)
tzinfo-data (1.2019.3)
tzinfo (>= 1.0.0)
warden (1.2.8)
rack (>= 2.0.6)
web-console (4.0.1)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
......@@ -237,6 +250,7 @@ DEPENDENCIES
bootsnap (>= 1.4.2)
byebug
capybara (>= 2.15)
devise
jbuilder (~> 2.7)
listen (>= 3.0.5, < 3.2)
mysql2
......
class UserController < ApplicationController
def signup
end
def login
end
end
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
has_many :applies
has_many :jobs, through: :applies
has_many :favorites
has_many :jobs, through: :favorites
has_secure_password
validates :email, uniqueness: { message: "Email is exist"}
end
<h2>Resend confirmation instructions</h2>
<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
</div>
<div class="actions">
<%= f.submit "Resend confirmation instructions" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
<p>Welcome <%= @email %>!</p>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
<p>Hello <%= @email %>!</p>
<% if @resource.try(:unconfirmed_email?) %>
<p>We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.</p>
<% else %>
<p>We're contacting you to notify you that your email has been changed to <%= @resource.email %>.</p>
<% end %>
<p>Hello <%= @resource.email %>!</p>
<p>We're contacting you to notify you that your password has been changed.</p>
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
<p>Hello <%= @resource.email %>!</p>
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
<p>Click the link below to unlock your account:</p>
<p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>
<h2>Change your password</h2>
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>
<%= f.hidden_field :reset_password_token %>
<div class="field">
<%= f.label :password, "New password" %><br />
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em><br />
<% end %>
<%= f.password_field :password, autofocus: true, autocomplete: "new-password" %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirm new password" %><br />
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
</div>
<div class="actions">
<%= f.submit "Change my password" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
<% content_for :title, "VenJob - Forgot your password" %>
<header class="page-header">
<h2 class="page-title">Forgot your password</h2>
</header>
<div id="primary" class="content-area container" role="main">
<article id="post-1673" class="post-1673 page type-page status-publish hentry">
<div class="entry-content">
<div class="registration-form woocommerce">
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>
<p class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
</p>
<p class="actions">
<%= f.submit "Send me reset password instructions", class: "button" %>
</p>
<% end %>
<p>
<%= render "devise/shared/links" %>
</p>
</div>
</div>
</article>
</div>
\ No newline at end of file
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
</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: "new-password" %>
<% 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: "new-password" %>
</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: "current-password" %>
</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 %>
<% content_for :title, "VenJob - Sign Up" %>
<header class="page-header">
<h2 class="page-title">Sign Up</h2>
</header>
<div id="primary" class="content-area container" role="main">
<article id="post-1673" class="post-1673 page type-page status-publish hentry">
<div class="entry-content">
<div class="registration-form woocommerce">
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>
<p class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
</p>
<p class="field">
<%= f.label :password %>
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "new-password" %>
</p>
<p class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
</p>
<p class="actions">
<%= f.submit "Sign up", class: "button" %>
</p>
<% end %>
<p>
Do you have account? <%= render "devise/shared/links" %>
</p>
</div>
</div>
</article>
</div>
\ No newline at end of file
<% content_for :title, "VenJob - Sign In" %>
<header class="page-header">
<h2 class="page-title">Sign In</h2>
</header>
<div id="primary" class="content-area container" role="main">
<article id="post-1673" class="post-1673 page type-page status-publish hentry">
<div class="entry-content">
<div class="registration-form woocommerce">
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<p class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
</p>
<p class="field">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "current-password" %>
</p>
<% if devise_mapping.rememberable? %>
<p class="field">
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
</p>
<% end %>
<p class="actions">
<%= f.submit "Log in", class: "button" %>
</p>
<% end %>
<p>
<%= render "devise/shared/links" %>
</p>
</div>
</div>
</article>
</div>
\ No newline at end of file
<% if resource.errors.any? %>
<div id="error_explanation">
<h2>
<%= I18n.t("errors.messages.not_saved",
count: resource.errors.count,
resource: resource.class.model_name.human.downcase)
%>
</h2>
<ul>
<% resource.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<%- if controller_name != 'sessions' %>
<%= link_to "Log in", new_session_path(resource_name) %><br />
<% end %>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end %>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end %>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end %>
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end %>
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %><br />
<% end %>
<% end %>
<h2>Resend unlock instructions</h2>
<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
</div>
<div class="actions">
<%= f.submit "Resend unlock instructions" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
\ No newline at end of file
......@@ -45,12 +45,18 @@
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-99991220">
<a href="/industries">Industry</a>
</li>
<% if current_user %>
<li class="login menu-item menu-item-type-post_type menu-item-object-page menu-item-99991213">
<%= link_to 'Sign out', destroy_user_session_path, method: :delete %>
</li>
<% else %>
<li class="register menu-item menu-item-type-post_type menu-item-object-page menu-item-99991219">
<a href="/signup" class="popup-trigger-ajax">Sign Up</a>
<%= link_to 'Sign up', new_user_registration_path %>
</li>
<li class="login menu-item menu-item-type-post_type menu-item-object-page menu-item-99991213">
<a href="/login" class="popup-trigger-ajax">Login</a>
<%= link_to 'Sign in', new_user_session_path %>
</li>
<% end %>
</ul>
</div>
</nav>
......@@ -59,6 +65,7 @@
</div>
</header>
<div id="main" class="site-main">
<% render 'layouts/alerts'%>
<%= yield %>
</div>
<div class="footer-cta">
......
<% content_for :title, "VenJob - Login" %>
<header class="page-header">
<h2 class="page-title">Login</h2>
</header>
<div id="primary" class="content-area container" role="main">
<div class="row">
<div class="col-sm-12 col-md-10 col-md-offset-1">
<article id="post-99991207" class="post-99991207 page type-page status-publish hentry">
<div class="entry-content">
<div class="woocommerce">
<div class="woocommerce-notices-wrapper"></div>
<div class="woocommerce-customer-login">
<h2>Login</h2>
<form class="woocommerce-form woocommerce-form-login login" method="post">
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
<label for="username">Username or email address&nbsp;<span class="required">*</span></label>
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="username" id="username" autocomplete="username" value="">
</p>
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
<label for="password">Password&nbsp;<span class="required">*</span></label>
<input class="woocommerce-Input woocommerce-Input--text input-text" type="password" name="password" id="password" autocomplete="current-password">
</p>
<p class="form-row">
<input type="hidden" id="woocommerce-login-nonce" name="woocommerce-login-nonce" value="79e75ba619"><input type="hidden" name="_wp_http_referer" value="/classic/account/"> <button type="submit" class="woocommerce-button button woocommerce-form-login__submit" name="login" value="Log in">Log in</button>
</p>
</form>
</div>
</div>
</div>
</article>
</div>
</div>
</div>
\ No newline at end of file
<% content_for :title, "VenJob - Sign Up" %>
<header class="page-header">
<h2 class="page-title">Sign Up</h2>
</header>
<div id="primary" class="content-area container" role="main">
<article id="post-1673" class="post-1673 page type-page status-publish hentry">
<div class="entry-content">
<div class="registration-form woocommerce">
<h2>Register</h2>
<form method="post" class="register">
<p class="woocommerce-FormRow woocommerce-FormRow--first form-row form-row-first">
<label for="reg_sr_firstname">First Name</label>
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="sr_firstname" id="reg_sr_firstname" value="">
</p>
<p class="woocommerce-FormRow woocommerce-FormRow--last form-row form-row-last">
<label for="reg_sr_lastname">Last Name</label>
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="sr_lastname" id="reg_sr_lastname" value="">
</p>
<p class="woocommerce-FormRow woocommerce-FormRow--wide form-row form-row-wide">
<label for="reg_email">Email address <span class="required">*</span></label>
<input type="email" class="woocommerce-Input woocommerce-Input--text input-text" name="email" id="reg_email" value="">
</p>
<p class="woocommerce-FormRow woocommerce-FormRow--wide form-row form-row-wide">
<label for="reg_password">Password <span class="required">*</span></label>
<input type="password" class="woocommerce-Input woocommerce-Input--text input-text" name="password" id="reg_password">
</p>
<div style="left: -999em; position: absolute;"><label for="trap">Anti-spam</label><input type="text" name="email_2" id="trap" tabindex="-1" autocomplete="off"></div>
<input type="hidden" value="employer,customer" name="reg_role">
<div class="woocommerce-privacy-policy-text"></div>
<p class="woocomerce-FormRow form-row">
<input type="hidden" id="woocommerce-register-nonce" name="woocommerce-register-nonce" value="8cfd41a3e1"><input type="hidden" name="_wp_http_referer" value="/classic/signup/"> <input type="submit" class="woocommerce-Button button" name="register" value="Register">
</p>
</form>
</div>
</div>
</article>
</div>
\ No newline at end of file
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
en:
devise:
confirmations:
confirmed: "Your email address has been successfully confirmed."
send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes."
send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
failure:
already_authenticated: "You are already signed in."
inactive: "Your account is not activated yet."
invalid: "Invalid %{authentication_keys} or password."
locked: "Your account is locked."
last_attempt: "You have one more attempt before your account is locked."
not_found_in_database: "Invalid %{authentication_keys} or password."
timeout: "Your session expired. Please sign in again to continue."
unauthenticated: "You need to sign in or sign up before continuing."
unconfirmed: "You have to confirm your email address before continuing."
mailer:
confirmation_instructions:
subject: "Confirmation instructions"
reset_password_instructions:
subject: "Reset password instructions"
unlock_instructions:
subject: "Unlock instructions"
email_changed:
subject: "Email Changed"
password_change:
subject: "Password Changed"
omniauth_callbacks:
failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
success: "Successfully authenticated from %{kind} account."
passwords:
no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
updated: "Your password has been changed successfully. You are now signed in."
updated_not_active: "Your password has been changed successfully."
registrations:
destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon."
signed_up: "Welcome! You have signed up successfully."
signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirmation link to confirm your new email address."
updated: "Your account has been updated successfully."
updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again"
sessions:
signed_in: "Signed in successfully."
signed_out: "Signed out successfully."
already_signed_out: "Signed out successfully."
unlocks:
send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes."
send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."
unlocked: "Your account has been unlocked successfully. Please sign in to continue."
errors:
messages:
already_confirmed: "was already confirmed, please try signing in"
confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
expired: "has expired, please request a new one"
not_found: "not found"
not_locked: "was not locked"
not_saved:
one: "1 error prohibited this %{resource} from being saved:"
other: "%{count} errors prohibited this %{resource} from being saved:"
Rails.application.routes.draw do
devise_for :users
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
root to: 'home#index'
get '/jobs/', to: 'job#index'
get '/cities/', to: 'city#index'
get '/industries/', to: 'industry#index'
get '/signup/', to: 'user#signup'
get '/login/', to: 'user#login'
end
class CreateUsers < ActiveRecord::Migration[6.0]
def change
create_table :users do |t|
t.string :full_name
t.string :email
t.string :password
t.string :cv_of_user
t.timestamps
end
add_index :users, :email, unique: true
end
end
# frozen_string_literal: true
class DeviseCreateUsers < ActiveRecord::Migration[6.0]
def change
create_table :users do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
# t.integer :sign_in_count, default: 0, null: false
# t.datetime :current_sign_in_at
# t.datetime :last_sign_in_at
# t.string :current_sign_in_ip
# t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
t.timestamps null: false
end
add_index :users, :email, unique: true
add_index :users, :reset_password_token, unique: true
# add_index :users, :confirmation_token, unique: true
# add_index :users, :unlock_token, unique: true
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_04_03_070245) do
ActiveRecord::Schema.define(version: 2020_04_08_025325) do
create_table "applies", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "user_id", null: false
......@@ -80,13 +80,15 @@ ActiveRecord::Schema.define(version: 2020_04_03_070245) do
end
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "full_name"
t.string "email"
t.string "password"
t.string "cv_of_user"
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
add_foreign_key "applies", "jobs"
......
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