Exemple #1
0
		f := form.NewForm(email, name)
		f.FillByRequest(ctx.Request)

		errorMsgs := make([]string, 0)
		userId := int64(0)
		if f.Valid() {
			m := f.CleanValues()
			// 检查email地址是否已经注册
			emailExist := models.User_IsEmailExist(m["email"].(string))
			userExist := models.User_IsUserExist(m["name"].(string))
			if !emailExist && !userExist {
				m["reference_id"] = ctx.Get("uid")
				m["reference_system"] = 1
				m["reference_token"] = ctx.Get("token")
				m["create_time"] = time.Now()
				result, err := models.User_SaveMap(m) // TODO:
				if err != nil {
					errorMsgs = append(errorMsgs, golink.ERROR_DATABASE)
					goku.Logger().Errorln(err)
				} else {
					userId, _ = result.LastInsertId()
				}
			} else {
				if userExist {
					errorMsgs = append(errorMsgs, "用户名已经被注册,请换一个")
				}
				if emailExist {
					errorMsgs = append(errorMsgs, "Email地址已经被注册,请换一个")
				}
			}
		} else {
Exemple #2
0
		errorMsgs := make([]string, 0)
		if f.Valid() {
			m := f.CleanValues()
			if m["pwd"] == m["repwd"] {

				// 检查email地址是否已经注册
				emailExist := models.User_IsEmailExist(m["email"].(string))
				userExist := models.User_IsUserExist(m["name"].(string))
				regKey := models.VerifyInviteKey(m["key"].(string))
				if !emailExist && !userExist && regKey != nil {
					m["pwd"] = utils.PasswordHash(m["pwd"].(string))
					delete(m, "repwd")
					delete(m, "key")
					m["create_time"] = time.Now()
					_, err := models.User_SaveMap(m)
					if err == nil {
						models.UpdateIsRegister(regKey)
					} else {
						errorMsgs = append(errorMsgs, golink.ERROR_DATABASE)
						goku.Logger().Errorln(err)
					}
				} else {
					if userExist {
						errorMsgs = append(errorMsgs, "用户名已经被注册,请换一个")
					}
					if emailExist {
						errorMsgs = append(errorMsgs, "Email地址已经被注册,请换一个")
					}
					if regKey == nil {
						errorMsgs = append(errorMsgs, "邀请码不正确,可能已经被注册或过期")