[英]How to authenticate users in Authlogic with usernames that are unique to an account only
为了我的一生,我无法解决这个问题。 我有一个应用程序,其中每个帐户都有一个唯一的子域。 在该帐户中,用户具有唯一的用户名,但该用户名在整个应用程序中可能并非唯一。
def create
@user_session = @current_account.user_sessions.new(params[:user_session])
@user = @current_account.users.find_by_username_or_email(params[:user_session][:username])
if @user_session.save
flash[:notice] = "Welcome back #{current_user.first_name}"
if @user_session.user.account.is_new? && !@current_account.stop_wizard?
redirect_to :controller => "site", :action => "welcome", :id => "one"
else
redirect_to dashboard_url
end
else
render :action => :new
end
end
这似乎在if @user_session.save
行上失败,因为它针对数据库内用户名的第一个实例进行验证,而不是针对范围为当前帐户的用户名进行验证。
任何意见,将不胜感激。
谢谢
罗宾
答案是创建会话时的with scope选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.