使用adauth时,我需要能够从活动目录中获取电子邮件。
Rails 4.x,ruby 2.0
如果我在user.rb中添加电子邮件的映射,我会收到错误
SessionsController中的NoMethodError #create undefined method`mail'对
Rails.root:C:/ Users / cmendla / RubymineProjects / technical_library
应用程序跟踪|框架跟踪|完整追踪 app / controllers / sessions_controller.rb:17:在'create'
中
user.rb
class User < ActiveRecord::Base
include Adauth::Rails::ModelBridge
Adauth.add_field(Adauth::AdObjects::User, :mail, :mail)
AdauthMappings = {
:login => :login, #was login login
:group_strings => :cn_groups,
:ou_strings => :dn_ous,
:email => :mail,
:name => :name,
}
AdauthSearchField = [:login, :login]
def groups
group_strings.split(", ")
end
end
User_controller.rb的参数
Never trust parameters from the scary internet, only allow the white list through.
def user_params
params.require(:user).permit(:login,
:group_strings,
:name,
:ou_strings,
:email
)
end
sessions_controller.rb - 创建:
def create
ldap_user = Adauth.authenticate(params[:username], params[:password])
# byebug
if ldap_user
user = User.return_and_create_from_adauth(ldap_user)
session[:user_id] = user.id
redirect_to home_path, :notice => "You are now logged in "
# byebug
else
redirect_to '/signin', :notice => "Invalid Login"
end
end
用户架构:
create_table "users", force: :cascade do |t|
t.string "login"
t.text "group_strings"
t.string "name"
t.string "ou_strings"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "email"
end
如果我将电子邮件映射出来,adauth工作正常。