以前有人问过这个问题,但我找不到真正的答案:我怎样才能让我的用户通过他们注册的相同表单登录?顺便说一句,这是客户的要求/需求,我意识到这远非理想......
用户
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
render :json => @user.to_json(:only => [:id])
else
render :json => @user.errors, :status => ""
end
end
end
会议
class SessionsController < ApplicationController
def create
user = User.find_by_email(params[:session][:email])
if user && user.authenticate(params[:session][:email])
sign_in user
render :json => @user.to_json(:only => [:id])
else
render :json => @user.errors, :status => ""
end
end
end
形式
<%= form_for(@user, :html => { :class => "access"}) do |f| %>
<%= f.label :firstname, "Firstname" %>
<%= f.text_field :firstname, :placeholder => "Your firstname" %>
<%= f.label :surname, "Surname" %>
<%= f.text_field :surname, :placeholder => "Your surname" %>
<%= f.label :email, "Email Address" %>
<%= f.text_field :email, :placeholder => "Your email address" %>
<%= f.submit "Verify" %>
<% end %>
电子邮件被验证为唯一的,这可能是一个入口点吗?例如。如果电子邮件不是唯一的,请检查名称和电子邮件或其他内容。
我不知道该怎么做。