zepheira_controller.rb 1 KB
Newer Older
1 2
class ZepheiraController < ApplicationController

3 4
  skip_before_filter :verify_authenticity_token

5
  verify method: :get, only: :ldap, render: { nothing: true, status: :method_not_allowed }
6
  def ldap
7 8 9
    created = false
    user = nil
    login = params[:username]
10
    auth_sources = AuthSource.all
11 12 13 14 15 16 17 18 19 20 21
    auth_sources.each do |src|
      if src.auth_method_name == 'LDAP'
        # Cheating.  Private method.
        attrs = src.__send__(:get_user_dn, login)
        if attrs.length > 0
          user = User.new(attrs.except(:dn))
          user.login = login
          user.language = Setting.default_language
          if user.save
            created = true
            logger.info("User '#{user.login}' created from #{user.auth_source.name} by API") if logger && user.auth_source
22 23 24
          end
        end
      end
25 26 27 28
    end
    if !created
      if user.nil?
        render_404
29
      else
30
        render :nothing => true, :status => 422
31 32
      end
    else
33
      render :nothing => true, :status => 201
34 35 36 37
    end
  end

end