如何获得在AJAX中使用的未确认或锁定状态的用户帐户
How to get Devise user account unconfirmed or locked state to use in AJAX?
我试图把设计视图使用JS来处理响应。我想使用默认的设计错误消息,但我不能得到个别类型的错误(例如:未经确认;锁定的帐户),因为监狱长。认证。所以,我使用"caught",所以它不会抛出406或其他错误。我的问题是:我知道"caught[:message] ==:unconfirmed"表示用户的"未确认"状态,那么"locked"对应的符号应该是什么呢?:locked不工作,我找不到文档。
我有我的Sessions_controller这样:def创建catch = catch(:典狱长)do自我。资源=监狱长。Authenticate:scope => resource_name
结束 if resource
# User is confirmed
sign_in(resource_name, resource)
puts "LOGGED IN!!!"
respond_to js{
set_flash_message(:success, :signed_in)
render :template => "remote_content/flashes.js.erb"
flash.discard
}
elsif caught and caught[:message] == :unconfirmed
# User is unconfirmed
puts "UNCONFIRMED ACCOUNT!!!"
# send the email or display the flash with link to send email
respond_to js{
set_flash_message(:error, :problem) #:problem is in devise.en.yml "There is problem in your account, check you email."
render :template => "remote_content/form_flashes.js.erb"
flash.discard
}
else
# User is not signed in, should be... error in credentials or locked account....
puts "ERROR IN CREDENTIALS!!!"
respond_to js{
set_flash_message(:error, :invalid)
render :template => "remote_content/form_flashes.js.erb"
flash.discard
}
end
end
flashes.js.erb/form_flashes.js。动词执行得很好,没问题!就像这样:
$('.modal').modal('hide');
// append flash to the body
$('.body').append("<%= escape_javascript raw(flash_normal) %>");
你觉得我的方法怎么样?我应该使用CustomFailure代替吗?我找不到任何CustomFailure的例子,或设计的原始,所以我可以把它响应我的JS文件。
我发现通过检查caught
,唯一的消息是unconfirmed
,它从未捕获unlocked
状态。所以我不得不通过电子邮件获得User
,并使用设计助手access_locked?
来获取他的信息。我知道这可能是一个安全故障,但如果锁上了,你什么也做不了。下面是上面缺少的那部分代码:
...
else
## User is not signed in, should be... error in credentials or locked...
## Let's see if it's locked
# This function is only used like this (without security)
# only when the authentication already failed in that action
# but we still need to get the user in order to check if its locked
user = User.find_by email: params[:user][:email]
if !user.nil? and user.access_locked?
# The small issue: anyone can know that an email is locked without typing the password
puts "ACCOUNT LOCKED!!!"
respond_to js{
set_flash_message(:error, :locked)
render :template => "remote_content/form_flashes.js.erb"
flash.discard
}
else
## If it's not Locked, then it's error in credentials
puts "ERROR IN CREDENTIALS!!!"
respond_to js{
set_flash_message(:error, :invalid)
render :template => "remote_content/form_flashes.js.erb"
flash.discard
}
end
end
我知道这不是最漂亮的方法,但是很有效。
相关文章:
- 事件和状态
- 获取选择框的状态
- 相位器状态未捕获参考错误
- 如何更改reactjs中外部/独立组件的状态或属性
- 如何使用密码检测网络中的状态连接
- Ember.js-接口状态应该存储在哪里
- 混合 ui-sref 和 $state.go 在 Angular ui-router 中进行状态转换
- 在Angular 2中布线期间保持零部件处于活动状态
- 在mvc应用程序中,在回发时保留最初隐藏的文本框的隐藏或可见状态
- XMLHttpRequest未返回值-状态202
- 使用javascript反复检查用户在facebook上的登录状态
- 如何使bxslider仅在移动视图中处于活动状态
- 获取ASP.NET Ajax Timer状态
- React redux初始化功能,无论状态变化如何
- 无法在现有状态转换期间更新-未使用任何非法的setState()
- 悬停下拉菜单即使在鼠标移出后也保持活动状态
- jQuery复选框被锁定为选中状态
- 鼠标在全屏+指针锁定状态下按下任何键时都不会启动
- 如何获得在AJAX中使用的未确认或锁定状态的用户帐户
- 在PHP中是否有可能发现客户端的计算机没有处于睡眠状态或锁定模式?