Jump to content

The ultimate community for Ruby on Rails developers.


Omniauth facebook sessions controller create action integration

omniauth railstutorial

  • Please log in to reply
No replies to this topic

#1 mlennie



  • Members
  • 1 posts

Posted 21 December 2013 - 02:08 PM

I have just finished the Michael Hartl tutorial. I am trying to implement omniauth-facebook to sign-up and sign-in users. I am having trouble creating the master variable to use in the create action in the sessions controller. My assumption is that I should put in an if else statement to see if the master is either signing on through facebook or through the default form? Or should I use and or statement:

(master = Master.find_by(email: params[:session][:email].downcase)|| Master.from_omniauth(env["omniauth.auth"])) ?

Here is the omniauth-facebook sessons controller create action code:

def create
 user = User.from_omniauth(env["omniauth.auth"])
 session[:user_id] = user.id
 redirect_to root_url

And here is my current sessions controller create action code:

class SessionsController < ApplicationController

 def new

 def create
  master = Master.find_by(email: params[:session][:email].downcase)
  if master && master.authenticate(params[:session][:password])
   sign_in master
   redirect_back_or master
   flash.now[:error] = 'Invalid email/password combination'
   render 'new'



Also tagged with one or more of these keywords: omniauth, railstutorial

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users