Exemplo n.º 1
0
// 检查账号密码是否正确
// 如果正确,则返回用户id
func User_CheckPwd(email, pwd string) int {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	pwd = utils.PasswordHash(pwd)
	rows, err := db.Query("select id from `user` where `email_lower`=? and pwd=? limit 1", strings.ToLower(email), pwd)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return 0
	}
	defer rows.Close()
	if rows.Next() {
		var id int
		err = rows.Scan(&id)
		if err != nil {
			goku.Logger().Errorln(err.Error())
		} else {
			return id
		}
	}
	return 0
}
Exemplo n.º 2
0
func ThirdParty_CreateAndBind(email string, name string, profile *ThirdPartyUserProfile) (u *ThirdPartyUser, err error) {
	if len(email) == 0 {
		err = NewThirdPartyBindError("邮箱不能为空")
		return
	}
	if len(name) == 0 {
		err = NewThirdPartyBindError("昵称不能为空")
		return
	}

	if User_IsEmailExist(email) {
		err = NewThirdPartyBindError("邮箱已经被注册过了,使用登录并绑定吧~~~")
		return
	}
	if User_IsUserExist(name) {
		err = NewThirdPartyBindError("哎呀,昵称已经被占用了哟,换一个试一下吧~~~")
		return
	}

	pwd, _ := utils.GenerateRandomString(5)
	pwdHash := utils.PasswordHash(pwd)

	//TODO: send notification email
	m := make(map[string]interface{})
	m["name"] = name
	m["email"] = email
	m["pwd"] = pwdHash
	m["create_time"] = time.Now()
	_, err = User_SaveMap(m)

	if err != nil {
		return
	}

	user, err := User_GetByEmail(email)
	u, err = ThirdParty_BindExistedUser(user, profile)

	return
}
Exemplo n.º 3
0
	/**
	 * 更新用户密码
	 */
	Post("change-pwd", func(ctx *goku.HttpContext) goku.ActionResulter {

		user := ctx.Data["user"].(*models.User)
		f := createUpdatePwdForm()
		f.FillByRequest(ctx.Request)

		errorMsgs := make([]string, 0)
		if f.Valid() {
			m := f.CleanValues()
			if m["new-pwd"] == m["new-pwd2"] {
				// 检查原密码是否正确
				if utils.PasswordHash(m["old-pwd"].(string)) == user.Pwd {
					saveMap := map[string]interface{}{"pwd": utils.PasswordHash(m["new-pwd"].(string))}
					_, err := models.User_Update(user.Id, saveMap)
					if err != nil {
						errorMsgs = append(errorMsgs, golink.ERROR_DATABASE)
						goku.Logger().Errorln(err)
					}
				} else {
					errorMsgs = append(errorMsgs, "原密码不正确,请重新输入")
				}
			} else {
				errorMsgs = append(errorMsgs, "两次输入的新密码不一致")
			}
		} else {
			errs := f.Errors()
			for _, v := range errs {
Exemplo n.º 4
0
		return ctx.View(models.User_ToVUser(user, ctx))
	}).
	Post("recover", func(ctx *goku.HttpContext) goku.ActionResulter {
		user, ur, r := userRecoverPreProcess(ctx)
		if r != nil {
			return r
		}

		f := createResetPasswordForm()
		f.FillByRequest(ctx.Request)

		errorMsgs := make([]string, 0)
		if f.Valid() {
			m := f.CleanValues()
			if m["new-pwd"] == m["new-pwd2"] {
				saveMap := map[string]interface{}{"pwd": utils.PasswordHash(m["new-pwd"].(string))}
				_, err := models.User_Update(user.Id, saveMap)
				if err != nil {
					errorMsgs = append(errorMsgs, golink.ERROR_DATABASE)
					goku.Logger().Errorln(err)
				} else {
					ur.Active = false
					ur.RecoveryTime = time.Now().UTC()
					ur.Update()
				}
			} else {
				errorMsgs = append(errorMsgs, "两次输入的新密码不一致")
			}
		} else {
			errs := f.Errors()
			for _, v := range errs {