新版本 devise 1.5 和omniauth 1.0.0 facebook 与 Mongoid 的手册

发布于 2024-12-19 01:54:49 字数 911 浏览 5 评论 0原文

中的新版本设计安装新版本omniauth 1.0.0 的新手册

我正在按照https ://github.com/plataformatec/devise/wiki/OmniAuth:-Overview

但我认为本手册适用于 Mysql。我正在使用Mongoid。

我尝试更新mongoid语法的查询:

omniauth_callbacks_controller.rb中,

如果@user.persisted?我已经更改通过 if @user.create

在模型 user.rb 中,

我更改了 if user = User.find_by_email(data.email) 通过if user = User.where(email: (data.email))

问题是,当用户从 facebook 返回时,在回调中我收到下一个错误:

Could not find a valid mapping for #<Mongoid::Criteria
  selector: {:email=>"emailusercomebackfacebook"},
  options:  {},
  class:    User,
  embedded: false>

知道吗?我在哪里可以获得 Mongoid 的新设备和omniauth 的指南或手册?

谢谢你!

I am following the new manual for install new version omniauth 1.0.0 with new version devise in

https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview

But this manual its for Mysql I think. Im working with Mongoid.

I have try update the query for the mongoid syntax:

In omniauth_callbacks_controller.rb

if @user.persisted? I have changed by if @user.create

In the model user.rb

I have change if user = User.find_by_email(data.email) by if user = User.where(email: (data.email))

The problem is that in callback when the user come back from facebook I get the next error:

Could not find a valid mapping for #<Mongoid::Criteria
  selector: {:email=>"emailusercomebackfacebook"},
  options:  {},
  class:    User,
  embedded: false>

Any idea? Where can I get a guide or manual for new devise and omniauth for Mongoid?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

云淡风轻 2024-12-26 01:54:49

是的,您需要做两处更改:

1) User.find_by_email(data.email) 需要是 User.where(:email => data.email).first

2) User.create!(:email => data.email, :encrypted_pa​​ssword => Devise.Friendly_token[0,20]) 需要User.create!(:email => data.email, :password => Devise.friend_token[0,20], :name => "Dummy Name")

注意我正在使用 "上面的虚拟名称,您应该从 Facebook 数据中获取名称。

Yes, you need to do two changes:

1) User.find_by_email(data.email) needs to be User.where(:email => data.email).first

2) User.create!(:email => data.email, :encrypted_password => Devise.friendly_token[0,20]) needs to be User.create!(:email => data.email, :password => Devise.friendly_token[0,20], :name => "Dummy Name")

Notice I am using "Dummy Name" above, you should get the name from facebook data instead.

蓬勃野心 2024-12-26 01:54:49

尝试获取第一个元素,看看它是否是您想要的实例。 Mongoid 似乎正在返回一个带有元素的 Enumerable 。

Try to get the first element and see if it is the instance you want. Mongoid seems to be returning a Enumerable with the elements.

2024-12-26 01:54:49

我已将下一个查询添加到模型中:

if user = (User.where(email:(data.email)).map.first)

现在错误出现在模型中:

Mongoid::Errors::Validations in 

Users::OmniauthCallbacksController#facebook

Validation failed - Password can't be blank, Name can't be blank.

Rails.root: /home/ubuntu/Desktop/app
Application Trace | Framework Trace | Full Trace
app/models/user.rb:21:in 'find_for_facebook_oauth'
app/controllers/users/omniauth_callbacks_controller.rb:4:in 'facebook'

使用新查询,脚本将转到 if 句子中的 else

产生错误的行其他是:

else # Create a user with a stub password. 
    User.create!(:email => data.email, :encrypted_password => Devise.friendly_token[0,20]) 

尝试使用存根密码创建用户

I have add the next query to model:

if user = (User.where(email:(data.email)).map.first)

Now the error is in the model:

Mongoid::Errors::Validations in 

Users::OmniauthCallbacksController#facebook

Validation failed - Password can't be blank, Name can't be blank.

Rails.root: /home/ubuntu/Desktop/app
Application Trace | Framework Trace | Full Trace
app/models/user.rb:21:in 'find_for_facebook_oauth'
app/controllers/users/omniauth_callbacks_controller.rb:4:in 'facebook'

With the new query the script go to else in the if sentence

The line that produce the error in the else is:

else # Create a user with a stub password. 
    User.create!(:email => data.email, :encrypted_password => Devise.friendly_token[0,20]) 

To try create the user with stub password

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文