Closed aman199002 closed 11 years ago
I have solved the problem by overriding default authenticate method in identity model.
In identity.rb
def self.authenticate(auth_key_param, password)
return nil if auth_key_param.nil? or password.nil?
if auth_key_param.match(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i)
self.find_by_email(auth_key_param).try(:authenticate, password)
else
self.find_by_mobile_no(auth_key_param).try(:authenticate, password)
end
end
It will check if the auth_key parameter is email or mobile_no using regular expression and then will try to authenticate according to parameter type .
Mobile no. can also be received within auth_hash. The auth_hash schema is mentioned here:
https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema
It has an info hash containing information about the user which is having a key named phone. So i have created an alias attribute.
alias_attribute :phone, :mobile_no
Now the mobile no can also be recieved inside auth_hash as key phone that can be saved in associated user record.
auth['info']['phone'] = "1234567891"
Problem resolved. Closing the issue.
I am using email address for signing in a user. I want to enable user to sign in via both email or mobile no.
In omniauth.rb
In signup form
And when i recieve auth hash in session controller, mobile no is not present
Is there any way to signin using both email and mobile no. And also get mobile no. parameter in auth hash to save in associated user record.