This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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
dea42aa
commit 8c5127d
Showing
16 changed files
with
181 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
class ApplicationController < ActionController::Base | ||
before_action :authorized | ||
helper_method :current_user | ||
helper_method :logged_in? | ||
|
||
def current_user | ||
User.find_by(id: session[:user_id]) | ||
end | ||
|
||
def logged_in? | ||
!current_user.nil? | ||
end | ||
|
||
def authorized | ||
redirect_to '/welcome' unless logged_in? | ||
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,37 @@ | ||
class SessionsController < ApplicationController | ||
skip_before_action :authorized, only: [:new, :create, :welcome] | ||
|
||
def new | ||
end | ||
|
||
def create | ||
@user = User.find_by(username: params[:username]) | ||
if @user && @user.authenticate(params[:password]) | ||
session[:user_id] = @user.id | ||
redirect_to welcome_path | ||
else | ||
flash[:warning] = "The username or password is incorrect:/" | ||
redirect_to login_path | ||
end | ||
end | ||
|
||
def login | ||
end | ||
|
||
def welcome | ||
end | ||
|
||
def page_requires_login | ||
|
||
end | ||
|
||
def destroy | ||
#clear the sessions[:user_id] | ||
puts session[:user_id] | ||
session.delete(:user_id) | ||
#params[:id] = nil | ||
#redirect the user back to the welcome page | ||
|
||
redirect_to '/welcome' | ||
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,28 @@ | ||
class UsersController < ApplicationController | ||
skip_before_action :authorized, only: [:new, :create, :show] | ||
|
||
def new | ||
@user = User.new | ||
end | ||
|
||
def show | ||
|
||
end | ||
|
||
def create | ||
@user = User.new(user_params) | ||
if @user.save | ||
session[:user_id] = @user.id | ||
redirect_to welcome_path | ||
else | ||
flash[:warning] = "Please try again" | ||
redirect_to new_user_path | ||
end | ||
end | ||
|
||
private | ||
|
||
def user_params | ||
params.require(:user).permit(:unique_id, :username, :password) | ||
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,4 +1,6 @@ | ||
class WelcomeController < ApplicationController | ||
skip_before_action :authorized, only: [:index] | ||
|
||
def index | ||
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,6 @@ | ||
class User < ApplicationRecord | ||
has_secure_password | ||
|
||
validates :username, presence: true, uniqueness: true | ||
validates :password, presence: 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
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,12 @@ | ||
<% if flash[:warning] %> | ||
<div class="notice"><%= flash[:warning] %></div> | ||
<% end %> | ||
|
||
<h1>Login</h1> | ||
<%= form_tag '/login' do %> | ||
<%= label_tag :username%> | ||
<%= text_field_tag :username %> | ||
<%= label_tag :password%> | ||
<%= password_field_tag :password%> | ||
<%= submit_tag "Login"%> | ||
<% 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,12 @@ | ||
<% if flash[:warning] %> | ||
<div class="notice"><%= flash[:warning] %></div> | ||
<% end %> | ||
|
||
<h1>Sign Up</h1> | ||
<%= form_for @user do |f|%> | ||
<%= f.label :username%><br> | ||
<%= f.text_field :username%><br> | ||
<%= f.label :password%><br> | ||
<%= f.password_field :password%><br> | ||
<%= f.submit %> | ||
<%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 @@ | ||
<h1>nothing yet</h1> |
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,10 @@ | ||
class CreateUsers < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :users do |t| | ||
t.string :username | ||
t.string :password | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
db/migrate/20210607030403_rename_password_to_password_digest.rb
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,7 @@ | ||
class RenamePasswordToPasswordDigest < ActiveRecord::Migration[6.1] | ||
def change | ||
change_table :users do |t| | ||
t.rename :password, :password_digest | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.