-
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
Showing
5 changed files
with
162 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class SessionsController < ApplicationController | ||
|
||
def new | ||
end | ||
|
||
def create | ||
user = User.find_by(email: params[:session][:email]) | ||
if user && user.authenticate(params[:session][:password]) | ||
session[:user_id] = user.id | ||
flash[:notice] = "Welcome!" | ||
redirect_to bracks_path | ||
else | ||
flash[:error] = "Invalid Username or Password!" | ||
redirect_to login_path | ||
end | ||
end | ||
|
||
def destroy | ||
session.clear | ||
flash[:notice] = "Goodbye!" | ||
redirect_to login_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
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 @@ | ||
<h1>Login</h1> | ||
|
||
<div class="well"> | ||
<%= form_for :session, url: login_path do |f| %> | ||
<div class="form-group"> | ||
<%= f.label :email %> | ||
<%= f.text_field :email, class: 'form-control' %> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= f.label :password %> | ||
<%= f.password_field :password, class: 'form-control' %> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= f.submit "Log In", class: 'btn btn-primary' %> | ||
</div> | ||
<% end %> | ||
<h5>Don't have an account? <%= link_to "Sign up by clicking here!", new_user_path %></h5> | ||
</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,21 @@ | ||
require 'rails_helper' | ||
|
||
feature "user can log out" do | ||
let(:user) {create(:user)} | ||
context "as a logged in user" do | ||
scenario "user is logged in and clicks logout" do | ||
visit login_path | ||
|
||
within ".well" do | ||
fill_in 'session[email]', with: user.email | ||
fill_in 'session[password]', with: user.password | ||
click_on "Log In" | ||
end | ||
|
||
click_on "Log Out" | ||
expect(page).to have_content("Goodbye!") | ||
expect(page).to have_content("Log In") | ||
expect(page).to_not have_content("Log Out") | ||
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
require 'rails_helper' | ||
|
||
feature "login process" do | ||
let(:user) {create(:user)} | ||
context "as an unauthenticated user" do | ||
scenario "can navigate to login path" do | ||
visit root_path | ||
|
||
click_on "Log In" | ||
|
||
expect(current_path).to eq(login_path) | ||
end | ||
scenario "can login with email and password" do | ||
visit login_path | ||
|
||
within ".well" do | ||
fill_in "session[email]", with: user.email | ||
fill_in "session[password]", with: user.password | ||
click_on "Log In" | ||
end | ||
|
||
expect(page).to have_content("Welcome!") | ||
expect(current_path).to eq(bracks_path) | ||
expect(page).to have_content("Log Out") | ||
|
||
expect(page).to_not have_content "Sign Up" | ||
expect(page).to_not have_content "Log In" | ||
end | ||
scenario "they provide invalid email" do | ||
visit login_path | ||
|
||
within ".well" do | ||
fill_in "session[email]", with: "[email protected]" | ||
fill_in "session[password]", with: user.password | ||
click_button "Log In" | ||
end | ||
|
||
expect(current_path).to eq(login_path) | ||
expect(page).to have_content("Invalid Username or Password!") | ||
|
||
expect(page).to_not have_content "Log Out" | ||
expect(page).to have_content "Sign Up" | ||
expect(page).to have_content "Log In" | ||
end | ||
scenario "they provide invalid password" do | ||
visit login_path | ||
|
||
within ".well" do | ||
fill_in "session[email]", with: user.email | ||
fill_in "session[password]", with: "blah" | ||
click_on "Log In" | ||
end | ||
|
||
expect(current_path).to eq(login_path) | ||
expect(page).to have_content("Invalid Username or Password!") | ||
|
||
expect(page).to_not have_content "Log Out" | ||
expect(page).to have_content "Sign Up" | ||
expect(page).to have_content "Log In" | ||
end | ||
scenario "they provide blank email" do | ||
visit login_path | ||
|
||
within ".well" do | ||
fill_in "session[email]", with: "" | ||
fill_in "session[password]", with: user.password | ||
click_button "Log In" | ||
end | ||
|
||
expect(current_path).to eq(login_path) | ||
expect(page).to have_content("Invalid Username or Password!") | ||
|
||
expect(page).to_not have_content "Log Out" | ||
expect(page).to have_content "Sign Up" | ||
expect(page).to have_content "Log In" | ||
end | ||
scenario "they provide blank password" do | ||
visit login_path | ||
|
||
within ".well" do | ||
fill_in "session[email]", with: user.email | ||
fill_in "session[password]", with: "" | ||
click_button "Log In" | ||
end | ||
|
||
expect(current_path).to eq(login_path) | ||
expect(page).to have_content("Invalid Username or Password!") | ||
|
||
expect(page).to_not have_content "Log Out" | ||
expect(page).to have_content "Sign Up" | ||
expect(page).to have_content "Log In" | ||
end | ||
end | ||
end |