LDAP BASE IMPLEMENRTATION
This commit is contained in:
parent
b4cc04d7e1
commit
c083df0570
12 changed files with 80 additions and 2 deletions
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
3
app/assets/stylesheets/users/omniauth_callbacks.css.scss
Normal file
3
app/assets/stylesheets/users/omniauth_callbacks.css.scss
Normal file
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the Users::OmniauthCallbacks controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
22
app/controllers/users/omniauth_callbacks_controller.rb
Normal file
22
app/controllers/users/omniauth_callbacks_controller.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||
|
||||
def ldap
|
||||
# We only find ourselves here if the authentication to LDAP was successful.
|
||||
ldap = request.env["omniauth.auth"]["extra"]["raw_info"]
|
||||
username = ldap.sAMAccountName[0].to_s
|
||||
email = ldap.proxyaddresses[0][5..-1].to_s
|
||||
|
||||
if @user = User.find_by_email(email)
|
||||
sign_in_and_redirect root_path
|
||||
else
|
||||
password = User.generate_random_password
|
||||
@user = User.create(:name => username,
|
||||
:email => email,
|
||||
:password => password,
|
||||
:password_confirmation => password
|
||||
)
|
||||
sign_in_and_redirect @user
|
||||
end
|
||||
end
|
||||
|
||||
end
|
2
app/helpers/users/omniauth_callbacks_helper.rb
Normal file
2
app/helpers/users/omniauth_callbacks_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module Users::OmniauthCallbacksHelper
|
||||
end
|
|
@ -2,7 +2,7 @@ class User < ActiveRecord::Base
|
|||
# Include default devise modules. Others available are:
|
||||
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
|
||||
devise :database_authenticatable, :token_authenticatable,
|
||||
:recoverable, :rememberable, :trackable, :validatable
|
||||
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
|
||||
|
||||
# Setup accessible (or protected) attributes for your model
|
||||
attr_accessible :email, :password, :password_confirmation, :remember_me,
|
||||
|
@ -62,6 +62,10 @@ class User < ActiveRecord::Base
|
|||
def last_activity_project
|
||||
projects.first
|
||||
end
|
||||
|
||||
def self.generate_random_password
|
||||
(0...8).map{ ('a'..'z').to_a[rand(26)] }.join
|
||||
end
|
||||
end
|
||||
# == Schema Information
|
||||
#
|
||||
|
|
|
@ -9,4 +9,5 @@
|
|||
<br/>
|
||||
<%= f.submit "Sign in", :class => "grey-button" %>
|
||||
<div class="right"> <%= render :partial => "devise/shared/links" %></div>
|
||||
<%= user_omniauth_authorize_path(:ldap)%>
|
||||
<% end %>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue