简体   繁体   中英

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. 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"]

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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