ruby on rails - Devise sign up either by email or by mobile number -


i can register user getting both email address , mobile number in application. want register user using either email or mobile primary authentication key. if user provides email address, must saved in email field in database , if user provides mobile number, must saved in mobile field in database.

and overwrite confirmation method of mobile user , send message activation key , inter key in application activate registration. think not hard, didn't start. please suggest me favourable way accomplish task.

yes, can minor setting.

like this

modify application_controller.rb

class applicationcontroller < actioncontroller::base   before_action :configure_permitted_parameters, if: :devise_controller?    protected    def configure_permitted_parameters     added_attrs = [:mobile_no, :email, :password, :password_confirmation, :remember_me]     devise_parameter_sanitizer.permit :sign_up, keys: added_attrs     devise_parameter_sanitizer.permit :account_update, keys: added_attrs   end end 
create login virtual attribute in user model 
add login attr_accessor:    # virtual attribute authenticating either username or email   # in addition real persisted field 'username'   attr_accessor :login or, if use variable somewhere else in code:    def login=(login)     @login = login   end    def login     @login || self.mobile_no || self.email   end 

modify config/initializers/devise.rb have:

config.authentication_keys = [ :login ] 

you can refer link more reference.

https://github.com/plataformatec/devise/wiki/how-to:-allow-users-to-sign-in-using-their-username-or-email-address


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -