示例#1
0
文件: main.go 项目: gwanted/crud
func Register(w http.ResponseWriter, r *http.Request) {
	user := r.FormValue("user")
	pwd := r.FormValue("pwd")
	if user == "" {
		ReturnEFormat(w, 1, "user is null")
		return
	}
	if pwd == "" {
		ReturnEFormat(w, 1, "pwd is null")
		return
	}
	db := mydb.GetDbCollection("local", "user")
	var dddd []U
	err := db.Find(bson.M{"account": user, "pwd": pwd}).All(&dddd)
	if err != nil {
		ReturnEFormat(w, 1, err.Error())
		return
	}
	if len(dddd) != 0 {
		ReturnEFormat(w, 1, "user is already exist")
		return
	}
	err = db.Insert(bson.M{"account": user, "pwd": pwd, "status": "N"})
	if err != nil {
		ReturnEFormat(w, 1, err.Error())
		return
	}
	ReturnFormat(w, 0, nil, "SUCCESS")
}
示例#2
0
文件: main.go 项目: gwanted/crud
func Login(w http.ResponseWriter, r *http.Request) {
	user := r.FormValue("user")
	pwd := r.FormValue("pwd")
	if user == "" {
		ReturnEFormat(w, 1, "user is null")
		return
	}
	if pwd == "" {
		ReturnEFormat(w, 1, "pwd is null")
		return
	}
	var dddd U
	db := mydb.GetDbCollection("local", "user")
	err := db.Find(bson.M{"account": user, "pwd": pwd}).One(&dddd)
	if err != nil {
		ReturnEFormat(w, 1, err.Error())
		return
	}
	ReturnFormat(w, 0, dddd, "SUCCESS")
}