设计、OmniAuth 和Facebook - 如何让用户编辑密码?

发布于 2025-01-01 21:46:46 字数 184 浏览 2 评论 0原文

我希望其他人有一个好的解决方案来解决这个问题。我们让用户使用 Facebook 进行注册(通过喜欢某个应用程序),同时他们作为我们网站上的用户进入我们的数据库。

成功注册后,Devise/OmniAuth 似乎正在创建一个随机密码(?)。我怎样才能让用户编辑他们的个人资料,在 Devise 中默认情况下(并且应该)要求他们输入当前密码?

I'm hoping that someone else has a good solution for this issue. We let our users register using facebook (by liking an app), and at the same time they enter our database as users on our site.

Upon successful registration it seems like Devise/OmniAuth is creating a random password(?). How can I let users edit their profile, which (and should) by default in Devise requires that they enter their current password?

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

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

发布评论

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

评论(2

心如狂蝶 2025-01-08 21:46:46

我遇到了完全相同的问题,所以我希望我的解决方案对您有所帮助。

根据您问题中的详细信息,我假设您遵循 devise wiki 中的 OmniAuth 指南: https://github.com/plataformatec/devise/wiki/OmniAuth:-概述

在以下方法中:

def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
  data = access_token.extra.raw_info
  if user = User.where(:email => data.email).first
    user
  else # Create a user with a stub password. 
    User.create!(:email => data.email, :password => Devise.friendly_token[0,20]) 
  end
end

我更改了 else 块中的逻辑,因为它立即在数据库中创建一个新用户并散列密码他们:

else # Create new user 
      user =User.new
      user
end

相反,我只是创建了一个新用户,这样在获取 Facebook 信息后,我将他们引导到注册页面,我将他们的信息填充在表单字段中,他们可以在其中编辑和创建密码。

您只需确保更新

def self.new_with_session(params, session)

以添加您为新用户获取的所有相关 Facebook 信息,并将其分配给新用户对象,以便所有这些字段都在注册页面中填充其信息。这样,在他们输入密码并添加或更改任何信息并单击提交后,即可创建新用户。希望您觉得这有帮助。

这是关于 Devise 的 wiki 页面和 Railscastomniauth 教程的想法的混合体:http:// /railscasts.com/episodes/235-omniauth-part-1

I had the exact same issue so I hope my solution will be helpful.

Based off the details in your question I am assuming you following the OmniAuth guide in the devise wiki: https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview

In the following method:

def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
  data = access_token.extra.raw_info
  if user = User.where(:email => data.email).first
    user
  else # Create a user with a stub password. 
    User.create!(:email => data.email, :password => Devise.friendly_token[0,20]) 
  end
end

I changed the logic in the else block because it was creating a new user in the database right away and hashing a password for them:

else # Create new user 
      user =User.new
      user
end

Instead I just made a new user so that after getting the facebook info I direct them to the sign up page where I have their info populated in the form fields where they can edit and create a password.

You will just need to make sure to update your

def self.new_with_session(params, session)

to add all the relevant facebook information you grabbed for a new user and assign it to the new user object so all those fields are populated with their information in the sign up page. So that after they finish typing their password and adding or changing any info and click submit it create the new user. Hopefully you find this helpful.

This was a mash of ideas for the wiki page on Devise and the railscast omniauth tutorial: http://railscasts.com/episodes/235-omniauth-part-1

枕头说它不想醒 2025-01-08 21:46:46

有类似的问题,但涉及在没有密码确认的情况下更新用户配置文件。发布链接 - 希望它有帮助:

stackoverflow - 允许用户编辑帐户而不在设备中保存密码

Had a similar problem, but in regards to updating a user profile without password confirmation. Posting a link to it - hope it helps:

stackoverflow - Allowing users to edit accounts without saving passwords in devise

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