查找在我的身份验证过程中起作用。但是我想打破确定用户是否被允许(尝试)登录的代码,以便我可以在多个地方使用它而无需重复代码。
但是(是蒸气/雨燕的新手)我遇到了一个错误,我无法弄清自己在做什么错:
无法将类型'EventLoopFuture'的返回表达式转换为类型'布尔'
错误位于行[[} .all()。map {上(由它本身分隔为一行,因此更易于查找)。明智的数据库结构,我有2个表:
保存我的用户配置文件详细信息的UserAccess(该用户可以进行多少次错误尝试,以及我们在日志中查找登录尝试有多久)
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的函数,并执行一些检查以查看用户是否被锁定在一段时间内没有尝试过多的登录。然后返回一个...