1
0
Fork 0

User Controllers

This commit is contained in:
Andrew Tomaka 2014-10-02 16:35:55 -04:00
parent 9ba59608cb
commit df80ce9062
17 changed files with 82 additions and 54 deletions

View file

@ -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/

View file

@ -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/

View file

@ -0,0 +1,3 @@
// Place all the styles related to the home controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View file

@ -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/

View file

@ -1,5 +1,8 @@
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
helper_method :current_user
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
end

View file

@ -0,0 +1,4 @@
class HomeController < ApplicationController
def show
end
end

View file

@ -0,0 +1,14 @@
class SessionsController < ApplicationController
def create
user = User.from_omniauth(env['omniauth.auth'])
session[:user_id] = user.id
redirect_to root_path
end
def destroy
session[:user_id] = nil
redirect_to root_path
end
end

View file

@ -0,0 +1,2 @@
module HomeHelper
end

View file

@ -0,0 +1,2 @@
module SessionsHelper
end

View file

@ -0,0 +1,2 @@
<h1>Home#show</h1>
<p>Find me in app/views/home/show.html.erb</p>

View file

@ -0,0 +1,2 @@
<h1>Sessions#create</h1>
<p>Find me in app/views/sessions/create.html.erb</p>

View file

@ -0,0 +1,2 @@
<h1>Sessions#destroy</h1>
<p>Find me in app/views/sessions/destroy.html.erb</p>

View file

@ -1,56 +1,10 @@
Rails.application.routes.draw do
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
get 'auth/:provider/callback', to: 'sessions#create'
get 'auth/failure', to: redirect('/')
get 'logout', to: 'sessions#destroy', as: 'logout'
# You can have the root of your site routed with "root"
# root 'welcome#index'
resources :sessions, only: [ :create, :destroy ]
resources :home, only: [ :show ]
# Example of regular route:
# get 'products/:id' => 'catalog#view'
# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end
# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable
# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
root to: 'home#show'
end

View file

@ -0,0 +1,9 @@
require 'test_helper'
class HomeControllerTest < ActionController::TestCase
test "should get show" do
get :show
assert_response :success
end
end

View file

@ -0,0 +1,14 @@
require 'test_helper'
class SessionsControllerTest < ActionController::TestCase
test "should get create" do
get :create
assert_response :success
end
test "should get destroy" do
get :destroy
assert_response :success
end
end

View file

@ -0,0 +1,4 @@
require 'test_helper'
class HomeHelperTest < ActionView::TestCase
end

View file

@ -0,0 +1,4 @@
require 'test_helper'
class SessionsHelperTest < ActionView::TestCase
end