Merge branch 'master' into prep_upgrade

This commit is contained in:
2019-01-05 16:20:37 +01:00
6 changed files with 55 additions and 9 deletions

View File

@@ -2,11 +2,23 @@
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
skip_before_filter :verify_authenticity_token skip_before_filter :verify_authenticity_token
def failure def failure
# flash[:notice] = "Failure #{Hash.new(request.env)} #{Hash.new(params)}" # flash[:notice] = "Failure #{Hash.new(request.env)} #{Hash.new(params)}"
#redirect_to new_user_registration_url , :notice=>"Omniauth Login failed" #redirect_to new_user_registration_url , :notice=>"Omniauth Login failed"
super super
end 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 def facebook
# You need to implement the method below in your model (e.g. app/models/user.rb) # 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) @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)

View File

@@ -29,12 +29,33 @@ class User < ActiveRecord::Base
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, # :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable # :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 acts_as_voter
# Setup accessible (or protected) attributes for your model # Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :provider, :uid, :name attr_accessible :email, :password, :password_confirmation, :remember_me, :provider, :uid, :name
belongs_to :fetprofile belongs_to :fetprofile
# attr_accessible :title, :body # attr_accessible :title, :body
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) def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
logger.debug auth.to_s logger.debug auth.to_s
logger.debug "DDD Username= #{auth.username}" logger.debug "DDD Username= #{auth.username}"

View File

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

View File

@@ -43,9 +43,20 @@
<li><%= link_to image_tag("/flaggen/png/gb.png") + " English" ,switch_locale_url(:en)%> </li> <li><%= link_to image_tag("/flaggen/png/gb.png") + " English" ,switch_locale_url(:en)%> </li>
</ul></div> </ul></div>
</li><li> </li>
<li>
<% if not user_signed_in? %>
<% if Rails.env.development? %>
<%# link_to I18n.t('home.login'), user_omniauth_authorize_path(:developer) %>
<%= render 'layouts/login' %>
<% else %>
<%= link_to ffi1_icon("academic") + I18n.t('home.login'), user_omniauth_authorize_path(:ldap) %> <%= link_to ffi1_icon("academic") + I18n.t('home.login'), user_omniauth_authorize_path(:ldap) %>
<%# render 'layouts/login' %> <% end %>
<% else %>
<%= render 'layouts/login' %>
<% end %>
</li></ul> </li></ul>
<!--<span class="pull-right"><%if I18n.locale == :en %> <!--<span class="pull-right"><%if I18n.locale == :en %>

View File

@@ -225,6 +225,7 @@ Devise.setup do |config|
# up on your models and hooks. # up on your models and hooks.
#config.omniauth :facebook, 'appid', 'secret' #config.omniauth :facebook, 'appid', 'secret'
secrets = YAML.load_file("#{::Rails.root.to_s}/config/omniauth_secrets.yml") 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 :facebook, secrets["facebook"]["appid"], secrets["facebook"]["secret"]
config.omniauth :ldap, :title => "My LDAP", config.omniauth :ldap, :title => "My LDAP",
:host => secrets["ldap"]["host"], :host => secrets["ldap"]["host"],
@@ -236,6 +237,8 @@ Devise.setup do |config|
:bind_dn =>secrets["ldap"]['bind'], :bind_dn =>secrets["ldap"]['bind'],
:password => secrets["ldap"]['password'] :password => secrets["ldap"]['password']
# ==> Warden configuration<< # ==> Warden configuration<<
# If you want to use other strategies, that are not supported by Devise, or # If you want to use other strategies, that are not supported by Devise, or
# change the failure app, you can configure them inside the config.warden block. # change the failure app, you can configure them inside the config.warden block.

View File

@@ -72,6 +72,7 @@ end
end end
end end
devise_for :users , :controllers=>{:omniauth_callbacks=> "users/omniauth_callbacks"} 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 scope '(:locale)', constraints: {:locale=>/en|de/i} do