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
112 changed files
with
1,822 additions
and
791 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 |
---|---|---|
@@ -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,3 @@ | ||
// Place all the styles related to the sessions 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
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,6 +1,9 @@ | ||
class DashboardController < ApplicationController | ||
|
||
# GET '/' | ||
def index | ||
redirect_to signin_path, status: 301 and return unless sessions_signed_in? | ||
@page_title = 'Your dashboard' | ||
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 SessionsController < ApplicationController | ||
|
||
# GET /signin | ||
def new | ||
@page_title = 'Sign in' | ||
@user = User.new | ||
end | ||
|
||
# POST /sessions | ||
def create | ||
user = User.find_by(email: params[:session][:email].downcase) | ||
if user && user.authenticate(params[:session][:password]) | ||
sessions_sign_in user | ||
redirect_to root_path | ||
else | ||
@page_title = 'Sign in' | ||
flash.now[:error] = 'Unrecognised email and password combination.' | ||
render 'new' | ||
end | ||
end | ||
|
||
# DELETE /signout | ||
def destroy | ||
sessions_sign_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,68 @@ | ||
class UsersController < ApplicationController | ||
|
||
# GET /users | ||
def index | ||
@users = User.all | ||
@page_title = 'Users' | ||
end | ||
|
||
# GET /signup | ||
def new | ||
@user = User.new | ||
@page_title = 'Create account' | ||
end | ||
|
||
# GET /users/:id | ||
def show | ||
@user = User.find(params[:id]) | ||
@page_title = "User #{@user.id}" | ||
end | ||
|
||
# GET /users/:id/edit | ||
def edit | ||
@user = User.find(params[:id]) | ||
@page_title = "Edit user #{@user.id}" | ||
end | ||
|
||
# POST /users | ||
def create | ||
@user = User.new(user_params) | ||
if @user.save | ||
sessions_sign_in @user | ||
flash[:success] = 'Thanks for signing up and welcome to TaxonWorks!' | ||
redirect_to root_path | ||
else | ||
@page_title = 'Create account' | ||
render 'new' | ||
end | ||
end | ||
|
||
# PATCH or PUT /users/:id | ||
def update | ||
@user = User.find(params[:id]) | ||
if @user.update_attributes(user_params) | ||
flash[:success] = 'Changes to your account information have been saved.' | ||
redirect_to @user | ||
else | ||
@page_title = "Edit user #{@user.id}" | ||
render 'edit' | ||
end | ||
end | ||
|
||
# DELETE /users/:id | ||
def destroy | ||
User.find(params[:id]).destroy | ||
flash[:success] = "Your account has been deleted." | ||
redirect_to root_url | ||
end | ||
|
||
private | ||
|
||
def user_params | ||
params.require(:user).permit(:name, | ||
: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,28 @@ | ||
module SessionsHelper | ||
|
||
def sessions_signed_in? | ||
!sessions_current_user.nil? | ||
end | ||
|
||
def sessions_current_user=(user) | ||
@sessions_current_user = user | ||
end | ||
|
||
def sessions_current_user | ||
remember_token = User.encrypt(cookies[:remember_token]) | ||
@sessions_current_user ||= User.find_by(remember_token: remember_token) | ||
end | ||
|
||
def sessions_sign_in(user) | ||
remember_token = User.secure_random_token | ||
cookies.permanent[:remember_token] = remember_token | ||
user.update_attribute(:remember_token, User.encrypt(remember_token)) | ||
self.sessions_current_user = user | ||
end | ||
|
||
def sessions_sign_out | ||
self.sessions_current_user = nil | ||
cookies.delete(:remember_token) | ||
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 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
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
Oops, something went wrong.