1

当让用户使用 Facebook 登录时,我在第一次身份验证后创建了一个新的设计用户,问题是关于新创建用户的密码的更好做法是什么?

1.用随机令牌填充它?

那么,用户如何知道新创建的密码呢?

一个。我要给他发一封电子邮件吗?
湾。在他的第一次 Facebook 身份验证后将其写为一条消息?

我知道用户可能不需要密码,因为他可以随时使用 Facebook 登录,但是,他可能需要更新他的设计用户字段,这将需要密码。

2. 留空?

然后,任何知道该电子邮件的人都可以使用设计登录表单进行登录。

3. 显示询问密码的模式窗口?

这样做,它将在用户最终访问该网站之前添加一个步骤。

那么,推荐的方法是什么?有什么建议吗?

编辑

在http://railscasts.com/episodes/236-omniauth-part-2?view=asciicast上 RailsCasts 上的 Ryan Bates

将用户重定向到一个表单,如果在尝试保存新用户时验证失败,他们可以解决任何问题,他避免为全新用户呈现密码字段:

<h2>Sign up</h2>

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  <%= devise_error_messages! %>

  <p><%= f.label :email %><br />
  <%= f.text_field :email %></p>

<% if @user.password_required? %>
  <p><%= f.label :password %><br />
  <%= f.password_field :password %></p>

  <p><%= f.label :password_confirmation %><br />
  <%= f.password_field :password_confirmation %></p>
<% end %>
  <p><%= f.submit "Sign up" %></p>
<% end %>

<%= render :partial => "devise/shared/links" %>

但是,当 OmniAuth 注册用户尝试使用 devise sign in 登录时会发生什么?

4

1 回答 1

0

Ryan Bates covered this on RailsCasts and suggests you redirect them to a page after they've signed up with their oauth account.

This way you can still register users in the normal way plus you're sill validating the model.

We do this so out customers can sign up with different providers and still keep our devise registration in place.

Have a read of this:

http://railscasts.com/episodes/236-omniauth-part-2?view=asciicast

If that's not helpful, let me know and I'll see what else we can find for you

于 2012-12-06T08:54:47.783 回答