forked from awesome-academy/dn_fresher_haikhanh_ecomerces
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request awesome-academy#6 from hainv-2854/user_login
User Login
- Loading branch information
Showing
14 changed files
with
248 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class SessionsController < ApplicationController | ||
def new; end | ||
|
||
def create | ||
user = User.find_by email: params[:session][:email].downcase | ||
if user&.authenticate params[:session][:password] | ||
log_in user | ||
redirect_to root_url | ||
else | ||
@email = params[:session][:email] | ||
flash.now[:danger] = t ".invalid_email_password" | ||
render :new | ||
end | ||
end | ||
|
||
def destroy | ||
log_out | ||
redirect_to root_url | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module SessionsHelper | ||
def log_in user | ||
session[:user_id] = user.id | ||
session[:user_name] = user.name | ||
end | ||
|
||
def current_user | ||
@current_user ||= User.find_by id: session[:user_id] | ||
end | ||
|
||
def logged_in? | ||
current_user.present? | ||
end | ||
|
||
def log_out | ||
session.delete :user_id | ||
session.delete :user_name | ||
@current_user = nil | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<% provide :title, t(".title") %> | ||
<div class="page-login"> | ||
<div class="wrap-breadcrumb"> | ||
<ul> | ||
<li class="item-link"><a href="#" class="link"><%= t ".home" %></a></li> | ||
<li class="item-link"><span><%= t ".title" %></span></li> | ||
</ul> | ||
</div> | ||
<div> | ||
<% flash.each do |message_type, message| %> | ||
<div class="alert alert-<%= message_type %>"><%= message %></div> | ||
<% end %> | ||
</div> | ||
<div class="row"> | ||
<div class="col-lg-6 col-sm-6 col-md-6 col-xs-12 col-md-offset-3"> | ||
<div class=" main-content-area"> | ||
<div class="wrap-login-item "> | ||
<div class="login-form form-item form-stl"> | ||
<%= form_for :session, url: login_path, html: {class: "login100-form validate-form"} do |f| %> | ||
<fieldset class="wrap-title"> | ||
<h3 class="form-title"><span><%= t ".login_to_account" %></span></h3> | ||
</fieldset> | ||
<fieldset class="wrap-input"> | ||
<%= f.label :name, t(".email") %> | ||
<%= f.email_field :email, class: "form-control", value: @email %> | ||
</fieldset> | ||
<fieldset class="wrap-input"> | ||
<%= f.label :name, t(".password") %> | ||
<%= f.password_field :password, class: "form-control" %> | ||
</fieldset> | ||
<fieldset class="wrap-input"> | ||
<%= f.label :remember_me, class: "remember-field" do %> | ||
<%= f.check_box :remember_me, class: "frm-input" %> | ||
<span><%= t ".remember_me" %></span> | ||
<% end %> | ||
<a class="link-function left-position" href="#" title="<%= t ".forgot_password" %>"><%= t ".forgot_password" %></a> | ||
</fieldset> | ||
<%= f.submit t(".title"), class: "btn btn-primary btn-submit" %> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<% if object.errors.any? %> | ||
<div id="error_explanation"> | ||
<div class="alert alert-danger"> | ||
<%= t "the_form_contains" %> | ||
<%= t "errors.error_message", count: pluralize(@user.errors.count, t("errors.error_singular")) %> | ||
</div> | ||
<ul> | ||
<% object.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<div class="primary-nav-section"> | ||
<div class="container"> | ||
<ul class="nav primary clone-main-menu" id="mercado_main" data-menuname="Main menu" > | ||
<li class="menu-item home-icon"> | ||
<%= link_to root_path do %> | ||
<i class="fa fa-home" aria-hidden="true"></i> | ||
<% end %> | ||
</li> | ||
<li class="menu-item"> | ||
<%= link_to t(".about_us"), "#", class: "link-term mercado-item-title" %> | ||
</li> | ||
<li class="menu-item"> | ||
<%= link_to t(".shop"), "#", class: "link-term mercado-item-title" %> | ||
</li> | ||
<li class="menu-item"> | ||
<%= link_to t(".cart"), "#", class: "link-term mercado-item-title" %> | ||
</li> | ||
<li class="menu-item"> | ||
<%= link_to t(".contact"), "#", class: "link-term mercado-item-title" %> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,34 @@ | ||
<main id="main"> | ||
<div class="container"> | ||
<%= render "shared/banner" %> | ||
|
||
<!--BANNER--> | ||
<%= render "shared/banner" %> | ||
|
||
<!--On Sale--> | ||
<div class="wrap-show-advance-info-box style-1"> | ||
<h3 class="title-box"><%= t ".on_sale" %></h3> | ||
<div class="wrap-top-banner"> | ||
<%= link_to "#", class: "link-banner banner-effect-2" do %> | ||
<figure> | ||
<%= image_tag("fashion-accesories-banner.jpg", alt: "", width: "1170", height: "240") %> | ||
</figure> | ||
<% end %> | ||
</div> | ||
</div> | ||
<div class="wrap-show-advance-info-box style-1"> | ||
<h3 class="title-box"><%= t ".on_sale" %></h3> | ||
<div class="wrap-top-banner"> | ||
<%= link_to "#", class: "link-banner banner-effect-2" do %> | ||
<figure> | ||
<%= image_tag("fashion-accesories-banner.jpg", alt: "", width: "1170", height: "240") %> | ||
</figure> | ||
<% end %> | ||
</div> | ||
</div> | ||
|
||
<!--Latest Products--> | ||
<div class="wrap-show-advance-info-box style-1"> | ||
<h3 class="title-box"><%= t ".latest_products" %></h3> | ||
<div class="wrap-top-banner"> | ||
<%= link_to "#", class: "link-banner banner-effect-2" do %> | ||
<figure> | ||
<%= image_tag("digital-electronic-banner.jpg", alt: "", width: "1170", height: "240") %> | ||
</figure> | ||
<% end %> | ||
</div> | ||
</div> | ||
<div class="wrap-show-advance-info-box style-1"> | ||
<h3 class="title-box"><%= t ".latest_products" %></h3> | ||
<div class="wrap-top-banner"> | ||
<%= link_to "#", class: "link-banner banner-effect-2" do %> | ||
<figure> | ||
<%= image_tag("digital-electronic-banner.jpg", alt: "", width: "1170", height: "240") %> | ||
</figure> | ||
<% end %> | ||
</div> | ||
</div> | ||
|
||
<!--Product Categories--> | ||
<div class="wrap-show-advance-info-box style-1"> | ||
<h3 class="title-box"><%= t ".product_categories" %></h3> | ||
<div class="wrap-top-banner"> | ||
<%= link_to "#", class: "link-banner banner-effect-2" do %> | ||
<figure> | ||
<%= image_tag("fashion-accesories-banner.jpg", alt: "", width: "1170", height: "240") %> | ||
</figure> | ||
<% end %> | ||
</div> | ||
</div> | ||
<div class="wrap-show-advance-info-box style-1"> | ||
<h3 class="title-box"><%= t ".product_categories" %></h3> | ||
<div class="wrap-top-banner"> | ||
<%= link_to "#", class: "link-banner banner-effect-2" do %> | ||
<figure> | ||
<%= image_tag("fashion-accesories-banner.jpg", alt: "", width: "1170", height: "240") %> | ||
</figure> | ||
<% end %> | ||
</div> | ||
</main> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
# This file should contain all the record creation needed to seed the database with its default values. | ||
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). | ||
# | ||
# Examples: | ||
# | ||
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) | ||
# Character.create(name: 'Luke', movie: movies.first) | ||
User.create!(name: "Example User", | ||
email: "[email protected]", | ||
password: "user123", | ||
password_confirmation: "user123", | ||
is_role: 1, | ||
activated: true | ||
) | ||
10.times do |n| | ||
name = Faker::Name.name | ||
email = "example#{n+1}@project.org" | ||
password = "password" | ||
User.create!(name: name, | ||
email: email, | ||
password: password, | ||
password_confirmation: password, | ||
activated: true | ||
) | ||
end |