I'm beginner in Ruby on Rails and I need help
In my project, I need to catch on LDAP the e-mail of user.
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :ldap_authenticatable,:rememberable, :trackable
#validates :username, presence: true, uniqueness: true
validates :email, presence: true
validates_uniqueness_of :email
before_validation :get_ldap_email
before_save :get_ldap_email
def get_ldap_email
self.email = Devise::LDAP::Adapter.get_ldap_param(self.username,"mail").first
end
But If in LDAP doesn't have an e-mail, shows an Rails´ error message and I want to redirect to a page with a message made by me.
So, in SessionController i want make an "if", but i don't have success to call the method.
class Users::SessionsController < Devise::SessionsController
require_relative '../../models/User.rb'
def create
super
if get_ldap_email == nil
# redirect to /errorlogin
end
end
And here show message
undefined local variable or method `get_ldap_email' for #
Users::SessionsController:0x67342e0>
Also I modificed the User for this...
def get_ldap_email
ldapEmail = Devise::LDAP::Adapter.get_ldap_param(self.username,"mail")
if ldapEmail == nil
else
self.email = ldapEmail.first
end
end
But now show this message
Validation failed: Email can't be blank
I don't what I need to do...
Aucun commentaire:
Enregistrer un commentaire