gpt4 book ai didi

mysql - Ruby on Rails IF 语句验证检查

转载 作者:行者123 更新时间:2023-11-29 07:32:51 25 4
gpt4 key购买 nike

所以我是 ruby​​ on rails 的新手,我遇到了这个 if 语句的问题,基本上我要检查的是 sql 数据库中是否存在用于登录电子邮件地址的确认 token 。如果它确实会回复您的电子邮件未验证的消息。单击电子邮件中的链接后,它会删除数据库中的 token 。然后你就可以继续登录了。我无法让它为我的生活工作。除了验证检查,其他一切都有效。谢谢你的帮助!!!

 def authenticate(email, password)
command = AuthenticateUser.call(email, password)
user = User.find_by email:(email)
confirmationtoken =
User.find_by_confirmation_token(params[:confirmation_token].to_s)
if user.present? && confirmationtoken.present?
render json: {error: 'Email not verified' }, status: :unauthorized
elsif command.success?
render json: {
access_token: command.result,
message: 'Login Successful'
}
else
render json: { error: command.errors }, status: :unauthorized
end
end

最佳答案

您可以简单地检查是否设置了用户的confirmation_token属性:

user = User.find_by(email: email)
if user && user.confirmation_token.present?
# ...
elsif command.success?
# ...
else
# ...
end

user.confirmation_token.present? 可以简写为 user.confirmation_token?

关于mysql - Ruby on Rails IF 语句验证检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50392595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com