-
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
6f91b2f
commit b2b069d
Showing
17 changed files
with
107 additions
and
11 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
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 @@ | ||
# sessions controller class | ||
class SessionsController < ApplicationController | ||
def create | ||
@user = User.authenticate(params[:email], params[:password]) | ||
if @user | ||
flash[:notice] = 'you log in good' | ||
session[:user_id] = @user.id | ||
redirect_to root_path | ||
else | ||
flash[:alert] = 'you try log in but problem' | ||
redirect_to log_in_path | ||
end | ||
end | ||
|
||
def destroy | ||
session[:user_id] = nil | ||
flash[:notice] = 'stopped being logged in' | ||
redirect_to root_path | ||
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,23 @@ | ||
# user controller | ||
class UsersController < ApplicationController | ||
def new | ||
|
||
end | ||
def create | ||
@user = User.new(user_params) | ||
if @user.save | ||
flash[:notice] = 'Thanks for the sympathy.' | ||
session[:user_id] = @user.id | ||
redirect_to root_path | ||
else | ||
flash[:alert] = 'problem doing the thing' | ||
redirect_to :back | ||
end | ||
end | ||
|
||
private | ||
|
||
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 |
---|---|---|
@@ -1,2 +1,21 @@ | ||
# practice user class | ||
class User < ActiveRecord::Base | ||
attr_accessor :password | ||
validates_confirmation_of :password | ||
|
||
before_save :encrypt_password | ||
|
||
def encrypt_password | ||
self.password_salt = BCrypt::Engine.generate_salt | ||
self.password_hash = BCrypt::Engine.hash_secret(password, password_salt) | ||
end | ||
|
||
def self.authenticate(email, password) | ||
user = User.where(email: email).first | ||
if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt) | ||
user | ||
else | ||
nil | ||
end | ||
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 |
---|---|---|
@@ -1,2 +1,9 @@ | ||
%h1 | ||
Today we mourn the loss of something with both good and bad aspects. | ||
- flash.keys.each do |k| | ||
= flash[k] | ||
%hr | ||
= link_to 'join', new_user_path | ||
= link_to 'sign in', log_in_path | ||
= link_to 'sign out', log_out_path | ||
= current_user ? 'logged in' : 'logged out' |
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,11 @@ | ||
%h1 | ||
Log in | ||
- flash.keys.each do |k| | ||
= flash[k] | ||
%hr | ||
= form_tag log_in_path do | ||
= label_tag :email | ||
= text_field_tag :email | ||
= label_tag :password | ||
= password_field_tag :password | ||
= submit_tag 'Log in' |
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 @@ | ||
%h1 | ||
Sign Up | ||
- flash.keys.each do |k| | ||
= flash[k] | ||
%hr | ||
= form_for User.new do |f| | ||
= f.label :email | ||
= f.text_field :email | ||
= f.label :password | ||
= f.password_field :password | ||
= f.label :password_confirmation | ||
= f.password_field :password_confirmation | ||
= f.submit "Sign up" |
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
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.