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.
Comments
Post a Comment