示例#1
0
文件: user.go 项目: yonglehou/ohlala
// 检查账号密码是否正确
// 如果正确,则返回用户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
}
示例#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
}
示例#3
0
	Post("reg", func(ctx *goku.HttpContext) goku.ActionResulter {

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

		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 {
示例#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 {
示例#5
0
	Post("reg", func(ctx *goku.HttpContext) goku.ActionResulter {

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

		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 {