How to log in automatically using Device after registration?

时光总嘲笑我的痴心妄想 提交于 2019-12-05 21:36:26

问题


In my rails application I am using devise gem for to manage users. I am using mobile_fu gem for to separate users coming from different users.

What I want to achieve here is:

  1. If a user opens my site from a mobile device I will extract its MSISDN number reading header it is already done
  2. If that MSISDN number falls in a particular series then I want to automatic login that user to my website so that he will not have to fill the sign_in form.

How I can achieve this?


回答1:


You have to:

1) Register the user into the website for devise. 2) Login the user.

For option 1, you can do something like:

user = User.find_by_msisdn(params[:msisdn])
if user.nil?
  user = User.create(field_1: value1, field_2: value2)    
end

sign_in(user)

redirect_to after_sign_in_path(user)

The things to have in mind, the first line tries to find for the user, on the second line, if it cannot find the user, it creates the user right away, then it sign_in the user, and finally redirect the user to where he should go after the login.



来源:https://stackoverflow.com/questions/13774852/how-to-log-in-automatically-using-device-after-registration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!