added developer login strategy for testing

This commit is contained in:
Andreas Stephanides
2018-06-02 12:01:18 +02:00
parent 52fcabf2dc
commit 52ffe0c701
5 changed files with 40 additions and 7 deletions

View File

@@ -2,11 +2,23 @@
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
skip_before_filter :verify_authenticity_token
def failure
# flash[:notice] = "Failure #{Hash.new(request.env)} #{Hash.new(params)}"
#redirect_to new_user_registration_url , :notice=>"Omniauth Login failed"
super
end
def developer
if Rails.env.development?
@user= User.find_for_developer_oauth(request.env["omniauth.auth"],current_user)
if @user
sign_in_and_redirect @user, event: :authentication
else
redirect_to new_user_registration_url
end
else
flash[:notice]=flash[:notice] + "Still not logged in "
redirect_to new_user_registration_url
end
end
def facebook
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)
@@ -23,7 +35,7 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
end
def ldap
logger.debug current_user.to_s
logger.debug current_user.to_s
@user=User.find_for_ldap_oauth(request.env["omniauth.auth"],current_user)
# @user=User.find_for_ldap_oauth(session["devise.ldap_data"],current_user)
# @user=User.first

View File

@@ -29,13 +29,34 @@ class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable,:omniauthable, :omniauth_providers => [:facebook,:ldap]
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable,:omniauthable, :omniauth_providers => [:facebook,:ldap,:developer]
acts_as_voter
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :provider, :uid, :name
belongs_to :fetprofile
# attr_accessible :title, :body
def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
def self.find_for_developer_oauth(auth, signed_in_resource=nil)
# logger.debug("Developer Login started")
# logger.debug(auth.info.to_s)
# logger.debug(auth.extra.raw_info.to_s)
email = auth.info.email.to_s
logger.debug("Login E-Mail:"+"'"+ email+"'")
user= User.where(:provider=>auth.provider,:uid=>email).first
unless user
user= User.create(name: email,
provider: auth.provider,
uid: email,
email: email,
password:Devise.friendly_token[0,20])
user.add_role("fetuser")
end
user
end
def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
logger.debug auth.to_s
logger.debug "DDD Username= #{auth.username}"
user = User.where(:provider => auth.provider, :uid => auth.uid).first

View File

@@ -24,6 +24,4 @@
<div><%= f.submit "Sign in" %></div>
<% end %>
<%= render "devise/shared/links" %>

View File

@@ -225,6 +225,7 @@ Devise.setup do |config|
# up on your models and hooks.
#config.omniauth :facebook, 'appid', 'secret'
secrets = YAML.load_file("#{::Rails.root.to_s}/config/omniauth_secrets.yml")
config.omniauth :developer,:title => "Developer" unless Rails.env.production?
config.omniauth :facebook, secrets["facebook"]["appid"], secrets["facebook"]["secret"]
config.omniauth :ldap, :title => "My LDAP",
:host => secrets["ldap"]["host"],
@@ -236,7 +237,7 @@ Devise.setup do |config|
:bind_dn =>secrets["ldap"]['bind'],
:password => secrets["ldap"]['password']
config.omniauth :developer if Rails.env.development?
# ==> Warden configuration<<
# If you want to use other strategies, that are not supported by Devise, or

View File

@@ -72,6 +72,7 @@ end
end
end
devise_for :users , :controllers=>{:omniauth_callbacks=> "users/omniauth_callbacks"}
#match '/auth/:provider/callback', to: "session#new", via: [:get, :post]
scope '(:locale)', constraints: {:locale=>/en|de/i} do