Commit 7721b77f by Tran Hoang Viet

Merge branch 'vietth_feat_user_management' into 'develop'

VietTH: Feature user management

See merge request !2
parents d1b9f8b7 01aebadf
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
layout Proc.new { |controller| controller.devise_controller? ? 'devise' : 'application' }
# Prevent CSRF attacks by raising an exception. # Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead. # For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception protect_from_forgery with: :exception
......
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
<h2>Resend confirmation instructions</h2>
<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, 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 <%= @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| %>
<%= devise_error_messages! %>
<%= 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>
<% end %><br />
<%= f.password_field :password, autofocus: true, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirm new password" %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Change my password" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
<h2>Forgot your password?</h2>
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="actions">
<%= f.submit "Send me reset password instructions" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
= form_for resource, as: resource_name, url: registration_path(resource_name), html: {method: :put, class: 'form-horizontal'} do |f|
= devise_error_messages!
.form-group
= f.label :email, class: 'col-sm-2 control-label'
.col-sm-4
= f.email_field :email, autofocus: true, class: 'form-control'
- if devise_mapping.confirmable? && resource.pending_reconfirmation?
%div
Currently waiting confirmation for:
= resource.unconfirmed_email
.form-group
= f.label :password, class: 'col-sm-2 control-label'
%i (leave blank if you don't want to change it)
.col-sm-4
= f.password_field :password, autocomplete: "off", class: 'form-control'
.form-group
= f.label :password_confirmation, class: 'col-sm-2 control-label'
.col-sm-4
= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control'
.form-group
= f.label :current_password, class: 'col-sm-2 control-label'
%i (we need your current password to confirm your changes)
.col-sm-4
= f.password_field :current_password, autocomplete: "off", class: 'form-control'
.form-group
.col-sm-offset-2.col-sm-10
= f.submit "Update", class: 'btn btn-default'
= form_for resource, as: resource_name, url: registration_path(resource_name), html: {class: 'form-horizontal'} do |f|
= devise_error_messages!
.form-group
= f.label :email, class: 'col-sm-2 control-label'
.col-sm-4
= f.email_field :email, autofocus: true, class: 'form-control'
.form-group
= f.label :password, class: 'col-sm-2 control-label'
.col-sm-4
- if @minimum_password_length
%em= "(#{@minimum_password_length} characters minimum)"
= f.password_field :password, autocomplete: "off", class: 'form-control'
.form-group
= f.label :password_confirmation, class: 'col-sm-2 control-label'
.col-sm-4
= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control'
.form-group
.col-sm-offset-2.col-sm-10
= f.submit "Sign up", class: 'btn btn-default'
= form_for resource, as: resource_name, url: session_path(resource_name), html: {class: 'form-horizontal'} do |f|
.form-group
= f.label :email, class: 'col-sm-2 control-label'
.col-sm-4
= f.email_field :email, autofocus: true, class: 'form-control'
.form-group
= f.label :password, class: 'col-sm-2 control-label'
.col-sm-4
= f.password_field :password, autocomplete: "off", class: 'form-control'
.form-group
.col-sm-offset-2.col-sm-10
= f.submit "Log in", class: 'btn btn-default'
<%- 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 #{provider.to_s.titleize}", 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| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="actions">
<%= f.submit "Resend unlock instructions" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
%ul.breadcrumb
%li
%a{href: '#'}
Home
%li
%a{href: '#'}
Cate 1
\ No newline at end of file
...@@ -4,13 +4,18 @@ ...@@ -4,13 +4,18 @@
%span.icon-bar %span.icon-bar
%span.icon-bar %span.icon-bar
%span.icon-bar %span.icon-bar
%a.navbar-brand.logo{:href => "#"} %a.navbar-brand.logo{:href => "/"}
%img{src: 'http://zigexn.vn/assets/logo-main-e75d68f895f288e75637440f337c1687.png'} %img{src: 'http://zigexn.vn/assets/logo-main-e75d68f895f288e75637440f337c1687.png'}
#navbar.navbar-collapse.collapse #navbar.navbar-collapse.collapse
%ul.nav.navbar-nav.navbar-right %ul.nav.navbar-nav.navbar-right
%li - if user_signed_in?
%a{:href => "#"} %li
Login = link_to 'Logout', destroy_user_session_path, method: :delete
%li %li
%a{:href => "#"} = link_to 'Change profile', edit_user_registration_path
Register
\ No newline at end of file - else
%li
= link_to('Login', new_user_session_path)
%li
= link_to 'Register', new_user_registration_path
\ No newline at end of file
!!!
%html{:lang => "en"}
%title Vendor
= stylesheet_link_tag 'application', media: 'all'
= javascript_include_tag 'application'
= csrf_meta_tags
%body
%nav.navbar.navbar-inverse.navbar-fixed-top
.container-fluid
= render '/layouts/header'
#wrapper.container-fluid
.row
.col-md-6.search-wrapper
= render 'layouts/search'
#content.row
.container
.col-md-12
= yield
# 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"
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 confirm link to confirm your new email address."
updated: "Your account has been updated successfully."
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:"
class DeviseCreateUsers < ActiveRecord::Migration
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
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