注册后如何自动登录设备? [英] How to log in automatically using Device after registration?

查看:99
本文介绍了注册后如何自动登录设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的rails应用程序中,我使用 devise gem来管理用户。我正在使用 mobile_fu gem来分隔来自不同用户的用户。

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.

我想要实现的是:


  1. 如果用户从移动设备打开我的网站,我将提取其 MSISDN 数字阅读标题已经完成

  2. 如果 MSISDN 数字属于一个特定的系列,那么我想自动登录该用户到我的网站,以便他不必填写sign_in表单。

  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.

我该如何实现?

推荐答案

您必须:

1)将用户注册到设计网站。
2)登录用户。

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

对于选项1,您可以执行以下操作:

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.

这篇关于注册后如何自动登录设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆