Esempio n. 1
0
File: user.go Progetto: zeuson/wego
func (this *UserRouter) getUser(user *models.User) bool {
	username := this.Params().Get(":username")
	user.UserName = username

	u, err := models.GetUserByName(username)
	if err != nil {
		this.NotFound()
		return true
	}
	*user = *u

	IsFollowed := false

	if this.IsLogin {
		if this.User.Id != user.Id {
			IsFollowed = models.IsExist(&models.Follow{
				UserId:       this.User.Id,
				FollowUserId: user.Id,
			})
		}
	}

	this.Data["TheUser"] = &user
	this.Data["IsFollowed"] = IsFollowed

	return false
}
Esempio n. 2
0
// register create user
func RegisterUser(user *models.User, username, email, password string, locale i18n.Locale) error {
	// use random salt encode password
	salt := models.GetUserSalt()
	pwd := utils.EncodePassword(password, salt)

	user.UserName = strings.ToLower(username)
	user.Email = strings.ToLower(email)

	// save salt and encode password, use $ as split char
	user.Password = fmt.Sprintf("%s$%s", salt, pwd)

	// save md5 email value for gravatar
	user.GrEmail = utils.EncodeMd5(user.Email)

	// Use username as default nickname.
	user.NickName = user.UserName

	//set default language
	if locale.Lang == "en-US" {
		user.Lang = setting.LangEnUS
	} else {
		user.Lang = setting.LangZhCN
	}

	//set default avatar
	user.AvatarType = setting.AvatarTypeGravatar
	return models.Insert(user)
}
Esempio n. 3
0
// check if exist user by username or email
func HasUser(user *models.User, username string) bool {
	var userTemp models.User
	if strings.IndexRune(username, '@') == -1 {
		userTemp.UserName = username
	} else {
		userTemp.Email = username
	}
	err := models.GetByExample(&userTemp)
	if err == nil {
		*user = userTemp
		return true
	}
	return false
}
Esempio n. 4
0
// get user by erify code
func getVerifyUser(user *models.User, code string) bool {
	if len(code) <= utils.TimeLimitCodeLength {
		return false
	}

	// use tail hex username query user
	hexStr := code[utils.TimeLimitCodeLength:]
	if b, err := hex.DecodeString(hexStr); err == nil {
		user.UserName = string(b)
		if u, err := models.GetUserByName(string(b)); err == nil {
			*user = *u
			return true
		}
	}

	return false
}