Class: SimpleUser::AuthController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#set_user_return_to

Instance Method Details

#createObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/simple_user/auth_controller.rb', line 4

def create
  auth = request.env["omniauth.auth"]   
  authentication = Authentication.find_by_provider_and_uid(auth['provider'], auth['uid'])
 
  if authentication
    flash[:notice] = "Signed in successfully."
    (:user, authentication.user)
    redirect_after_create     
  else
    user = User.build_new_auth(auth)
    if user.save(:validate => false)
      flash[:notice] = "Account created and signed in successfully."
      (:user, user)
      redirect_after_create
    else
      flash[:error] = "Error while creating the user account. Please try again."
      redirect_after_create
    end
  end
end

#redirect_after_createObject



25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/simple_user/auth_controller.rb', line 25

def redirect_after_create
  if ENV['REDIRECT_USER_AFTER_SIGNIN'] == 'false' || !defined? session[:return_to] || session[:return_to] == "/" ||  session[:return_to].nil?
    session[:return_to] = "/"
    redirect_to root_url
  else
    return_to = session[:return_to]
    session[:return_to] = "/"
    redirect_to return_to
  end   
end