给定一个 HStack,如下所示:
HStack{
Text("View1")
Text("Centre")
Text("View2")
Text("View3")
}
Run Code Online (Sandbox Code Playgroud)
如何强制“中心”视图位于中心?
我让用户最初登录时没有确认他们的电子邮件地址 - 但是在7天之后,如果他们还没有确认 - 我阻止访问,直到他们确认他们的地址.
(注意 - 这可以通过设置config.allow_unconfirmed_access_for = 7.daysDevise初始化程序来实现)
如果他们达到'宽限'限制(例如他们没有确认并且7天通过)那么我想:
做#2我需要访问用户才能获得电子邮件地址.
设计显然"知道"用户是谁 - 这就是它知道他们已经通过确认到期的方式.
如果用户刚刚尝试登录,那么我可以通过查看参数来获得此信息.但是,如果用户已经在他们的会话中有一个实时登录令牌,那么当他们通过神奇的一周 - 他们将突然开始被设计拒绝.在这种情况下如何访问用户?
#based on
#https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-when-the-user-can-not-be-authenticated
#https://stackoverflow.com/questions/9223555/devise-with-confirmable-redirect-user-to-a-custom-page-when-users-tries-to-sig
class CustomFailure < Devise::FailureApp
def redirect_url
if warden_message == :unconfirmed
user = User.find_by_email(params.dig(:user,:email))
user&.send_confirmation_instructions
if user.nil?
#if the user had a valid login session when they passed the grace period, they will end up here
!! how do I get the user in this scenario !!
end
confirmation_required_info_path(params: {found: !user.nil?})
elsif warden_message == :invalid …Run Code Online (Sandbox Code Playgroud)