How to log in automatically using Device after reg

2019-04-06 10:16发布

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条回答
\"骚年 ilove
2楼-- · 2019-04-06 11:00

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.

查看更多
登录 后发表回答