Class: SessionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/sessions_controller.rb

Overview

Handles the user login, using Google authentication, creating and destroying sessions as needed.

Instance Method Summary collapse

Instance Method Details

#createObject

request.env['omniauth.auth'] contains all the information sent by the server to our app (it is called the auth hash). from http://www.sitepoint.com/youtube-api-version-3-rails


7
8
9
10
11
12
13
# File 'app/controllers/sessions_controller.rb', line 7

def create
  user = User.from_omniauth(request.env['omniauth.auth'])
  session[:user_id] = user.id
  flash[:success] = "Welcome, #{user.name}"
  redirect_to user_videos_path(user)  #redirect_to user_videos_path(user)

end

#destroyObject


15
16
17
18
19
# File 'app/controllers/sessions_controller.rb', line 15

def destroy
  session[:user_id] = nil
  flash[:success] = "Goodbye!"
  redirect_to root_url
end