mongodb - 邮递员不验证现有的电子邮件 golang
问题描述
我正在用 Go 语言做一个项目,我已经在 mongodb 中创建了我的集合,并且我创建了插入用户数据并验证电子邮件和昵称的函数(如果它们有这么多字符或者它们已经存在于数据库中)问题是当在邮递员中尝试时,会验证两者中的任何一个是否具有字符,但如果它们存在于数据库中则不会验证,只需将它们始终以相同的用户和相同的电子邮件插入数据库,我觉得代码还不错,你怎么看?
//这是验证用户是否存在的功能,我为电子邮件制作了另一个完全相同的功能
func CheckUserExist(nick string) (models.Useer, bool, string) {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
db := MongoC.Database("DebMan_N01")
col := db.Collection("users")
condition := bson.M{"nick": nick}
var results models.Useer
err := col.FindOne(ctx, condition).Decode(&results)
ID := results.ID.Hex()
if err != nil {
return results, false, ID
}
return results, true, ID }
//这里我调用了函数,并表示如果它返回的值为真,即如果为真则用户已经存在
_, founded, _ := bd.CheckUserExist(t.Nick)
if founded == true {
http.Error(w, "Ya existe un nombre de usuario registrado", 400)
return
}
_, foundedE, _ := bd.CheckEmailExist(t.Email)
if foundedE == true {
http.Error(w, "Ya existe un usuario con el email", 400)
return
}
解决方案
推荐阅读
- python - Wagtail:调用 routeablepageurl 的模板标签抛出 AttributeError
- java - 将输入流打印到文本文件
- node.js - NodeJS socket.io 无法处理性能测试中的到达率
- object - objcopy 生成巨大的二进制文件(265M)
- java - 谷歌地理编码 SSL 握手异常
- java - ExpandableListView 对于列表中的最后一项表现异常
- html - 具有 IE11 规范的 CSS Grid - 网格自身折叠
- jquery - 如何使用 .on() 传递 2 个参数?
- c# - dbml linq 中 where 子句中比较日期的问题
- r - 是否可以使用 group by 和 tidy 将多级模型 (lme) 拟合到重复测量/纵向数据?