简体   繁体   English

如何在Ruby on Rails应用程序数据库中存储ldap数据?

[英]how to store ldap data in ruby on rails application database?

i have created a web app with rails4 and authentication system is developed with devise_ldap_authenticable gem. 我用rails4创建了一个Web应用程序,并且使用devise_ldap_authenticable gem开发了身份验证系统。 where i am using username for login not email. 我在使用用户名登录而不是电子邮件。 but i want to store email in my users table. 但我想将电子邮件存储在我的用户表中。 My user model is 我的用户模型是

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
#@attr_accessible :email, :password, :password_confirmation
# not required for LDAP :recoverable, :registerable, :validatable
devise :ldap_authenticatable, :rememberable, :trackable

validates_uniqueness_of :email, :allow_blank => true

 before_save :get_ldap_email

 def get_ldap_email
  self.email = Devise::LDAP::Adapter.get_ldap_param(self.username, "mail")
 end
end 

But in users table of email field its storing data like 但是在电子邮件字段的用户表中,其存储数据如

`email` = '--- !ruby/array:Net::BER::BerIdentifiedArray\ninternal:\n- !ruby/string:Net::BER::BerIdentifiedString\n str: !binary |-\n cy5naG9zaEBzYW1zdW5nLmNvbQ==\n ber_identifier: 4\nivars:\n :@ber_identifier: 49\n'  

My log says LDAP: Requested param mail has value ["s.ghosh@example.com"] 我的日志显示LDAP:请求的参数邮件的值为[“ s.ghosh@example.com”]

How i will store this value to my users table. 我将如何将该值存储到我的用户表。 where im doing wrong? 我在哪里做错了? please help me out. 请帮帮我。

Just need to add the following then its totally ok 只需添加以下内容即可

def get_ldap_email
  self.email = Devise::LDAP::Adapter.get_ldap_param(self.username, "mail").first
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM