Vapor 4 / Fluent,具有嵌套数据库查找功能,以返回返回EventLoopF uture [<

问题描述 投票:0回答:1
我正在尝试编写一个接受我的UserModel的函数,并执行几项检查以查看用户是否是

    被锁定
  1. 在一段时间内未尝试过多登录。
  2. 然后返回结果的布尔值指示。

查找在我的身份验证过程中起作用。但是我想打破确定用户是否被允许(尝试)登录的代码,以便我可以在多个地方使用它而无需重复代码。

但是(是蒸气/雨燕的新手)我遇到了一个错误,我无法弄清自己在做什么错:

无法将类型'EventLoopF​​uture'的返回表达式转换为类型'布尔'

错误位于行[[} .all()。map {上(由它本身分隔为一行,因此更易于查找)。

明智的数据库结构,我有2个表:

保存我的用户配置文件详细信息的UserAccess(该用户可以进行多少次错误尝试,以及我们在日志中查找登录尝试有多久)

    UserLog,它如何记录每个用户的登录尝试以及尝试登录的时间
  • 到目前为止,这是我的代码段:
  • func CanUserLogin(user: UserModel, req: Request) -> EventLoopFuture<Bool> { if(!(user.locked ?? false)) { let userProfileId = user.userprofile return Usertype.query(on: req.db) .filter(\.$profilenum == userProfileId) .first().map { useraccess in let badloginperiod = Double((useraccess!.badloginperiod ?? 0) * -1 * 60) // convert minutes to seconds (we need a negative number) let lookUpDate = Date().addingTimeInterval(badloginperiod) return Userlog.query(on: req.db).group(.and) { and in and.filter(\.$username == user.username) and.filter(\.$datecreated >= lookUpDate) }.all().map { UserLogs -> Bool in let value = userLogs.count // the account is locked or the max attempts for the time peroid if(value >= (useraccess.maxloginattempts ?? 3)) { return false } else { return true } } } } }

    任何方向将不胜感激。

    我正在尝试编写一个包含我的UserModel的函数,并执行一些检查以查看用户是否被锁定在一段时间内没有尝试过多的登录。然后返回一个...
  • arrays vapor vapor-fluent
    1个回答
    0
    投票
    © www.soinside.com 2019 - 2024. All rights reserved.