-
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.
- Loading branch information
1 parent
26297ff
commit 2da856a
Showing
32 changed files
with
927 additions
and
63 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,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
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,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
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,73 @@ | ||
body { | ||
background-color: #fff; | ||
color: #333; | ||
font-family: verdana, arial, helvetica, sans-serif; | ||
font-size: 13px; | ||
line-height: 18px; | ||
} | ||
|
||
p, ol, ul, td { | ||
font-family: verdana, arial, helvetica, sans-serif; | ||
font-size: 13px; | ||
line-height: 18px; | ||
} | ||
|
||
pre { | ||
background-color: #eee; | ||
padding: 10px; | ||
font-size: 11px; | ||
} | ||
|
||
a { | ||
color: #000; | ||
|
||
&:visited { | ||
color: #666; | ||
} | ||
|
||
&:hover { | ||
color: #fff; | ||
background-color: #000; | ||
} | ||
} | ||
|
||
div { | ||
&.field, &.actions { | ||
margin-bottom: 10px; | ||
} | ||
} | ||
|
||
#notice { | ||
color: green; | ||
} | ||
|
||
.field_with_errors { | ||
padding: 2px; | ||
background-color: red; | ||
display: table; | ||
} | ||
|
||
#error_explanation { | ||
width: 450px; | ||
border: 2px solid red; | ||
padding: 7px; | ||
padding-bottom: 0; | ||
margin-bottom: 20px; | ||
background-color: #f0f0f0; | ||
|
||
h2 { | ||
text-align: left; | ||
font-weight: bold; | ||
padding: 5px 5px 5px 15px; | ||
font-size: 12px; | ||
margin: -7px; | ||
margin-bottom: 0px; | ||
background-color: #c00; | ||
color: #fff; | ||
} | ||
|
||
ul li { | ||
font-size: 12px; | ||
list-style: square; | ||
} | ||
} |
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,3 @@ | ||
// Place all the styles related to the UserSessions controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
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,3 @@ | ||
// Place all the styles related to the users controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
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,5 +1,6 @@ | ||
class ApplicationController < ActionController::Base | ||
# Prevent CSRF attacks by raising an exception. | ||
# For APIs, you may want to use :null_session instead. | ||
before_filter :require_login | ||
protect_from_forgery with: :exception | ||
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 @@ | ||
class UserSessionsController < ApplicationController | ||
skip_before_filter :require_login, only: [:index, :new, :create] | ||
def new | ||
@user = User.new | ||
end | ||
|
||
def create | ||
if @user = login(params[:email], params[:password]) | ||
redirect_back_or_to(:users, notice: "Login Succesfull") | ||
else | ||
flash.now[:alert] = "Login Failed" | ||
render action: 'new' | ||
end | ||
end | ||
|
||
def destroy | ||
logout | ||
redirect_to(:users, notice: "Logged out") | ||
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,75 @@ | ||
class UsersController < ApplicationController | ||
skip_before_filter :require_login, except: [:destroy] | ||
before_action :set_user, only: [:show, :edit, :update, :destroy] | ||
|
||
# GET /users | ||
# GET /users.json | ||
def index | ||
@users = User.all | ||
end | ||
|
||
# GET /users/1 | ||
# GET /users/1.json | ||
def show | ||
end | ||
|
||
# GET /users/new | ||
def new | ||
@user = User.new | ||
end | ||
|
||
# GET /users/1/edit | ||
def edit | ||
end | ||
|
||
# POST /users | ||
# POST /users.json | ||
def create | ||
@user = User.new(user_params) | ||
|
||
respond_to do |format| | ||
if @user.save | ||
format.html { redirect_to @user, notice: 'User was successfully created.' } | ||
format.json { render :show, status: :created, location: @user } | ||
else | ||
format.html { render :new } | ||
format.json { render json: @user.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /users/1 | ||
# PATCH/PUT /users/1.json | ||
def update | ||
respond_to do |format| | ||
if @user.update(user_params) | ||
format.html { redirect_to @user, notice: 'User was successfully updated.' } | ||
format.json { render :show, status: :ok, location: @user } | ||
else | ||
format.html { render :edit } | ||
format.json { render json: @user.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /users/1 | ||
# DELETE /users/1.json | ||
def destroy | ||
@user.destroy | ||
respond_to do |format| | ||
format.html { redirect_to users_url, notice: 'User was successfully destroyed.' } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_user | ||
@user = User.find(params[:id]) | ||
end | ||
|
||
# Never trust parameters from the scary internet, only allow the white list through. | ||
def user_params | ||
params.require(:user).permit(:email, :password, :password_confirmation) | ||
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,2 @@ | ||
module UserSessionsHelper | ||
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,2 @@ | ||
module UsersHelper | ||
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,8 @@ | ||
class User < ActiveRecord::Base | ||
authenticates_with_sorcery! | ||
validates :password, length: { minimum: 3 }, if: -> { new_record? || changes["password"] } | ||
validates :password, confirmation: true, if: -> { new_record? || changes["password"] } | ||
validates :password_confirmation, presence: true, if: -> { new_record? || changes["password"] } | ||
|
||
validates :email, uniqueness: true | ||
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 |
---|---|---|
@@ -1,14 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Thanku</title> | ||
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> | ||
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> | ||
<%= csrf_meta_tags %> | ||
</head> | ||
<body> | ||
<head> | ||
<title>Tutorial</title> | ||
<%= stylesheet_link_tag "application" %> | ||
<%= javascript_include_tag "application" %> | ||
<%= csrf_meta_tags %> | ||
</head> | ||
<body> | ||
|
||
<%= yield %> | ||
<div id="nav"> | ||
<% if current_user %> | ||
<%= link_to "Edit Profile", edit_user_path(current_user.id) %> | ||
<%= link_to "Logout", :logout, method: :post %> | ||
<% else %> | ||
<%= link_to "Register", new_user_path %> | | ||
<%= link_to "Login", :login %> | ||
<% end %> | ||
</div> | ||
<div> | ||
<p id="notice"><%= flash[:notice] %></p> | ||
<p id="alert"><%= flash[:alert] %></p> | ||
</div> | ||
<%= yield %> | ||
|
||
</body> | ||
</html> | ||
</body> | ||
</html> |
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 @@ | ||
<%= form_tag user_sessions_path, :method => :post do %> | ||
<div class="field"> | ||
<%= label_tag :email %><br /> | ||
<%= text_field_tag :email %> | ||
</div> | ||
<div class="field"> | ||
<%= label_tag :password %><br /> | ||
<%= password_field_tag :password %> | ||
</div> | ||
<div class="actions"> | ||
<%= submit_tag "Login" %> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>UserSessions#create</h1> | ||
<p>Find me in app/views/user_sessions/create.html.erb</p> |
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,2 @@ | ||
<h1>UserSessions#destroy</h1> | ||
<p>Find me in app/views/user_sessions/destroy.html.erb</p> |
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,5 @@ | ||
<h1>Login</h1> | ||
|
||
<%= render 'form' %> | ||
|
||
<%= link_to 'Back', user_sessions_path %> |
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,29 @@ | ||
<%= form_for(@user) do |f| %> | ||
<% if @user.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2> | ||
|
||
<ul> | ||
<% @user.errors.full_messages.each do |message| %> | ||
<li><%= message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<%= f.label :email %><br> | ||
<%= f.text_field :email %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :password %><br> | ||
<%= f.password_field :password %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :password_confrimation %><br> | ||
<%= f.password_field :password_confirmation %> | ||
</div> | ||
<div class="actions"> | ||
<%= f.submit %> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Editing User</h1> | ||
|
||
<%= render 'form' %> | ||
|
||
<%= link_to 'Show', @user %> | | ||
<%= link_to 'Back', users_path %> |
Oops, something went wrong.