Exemplo n.º 1
0
func (this *BaseController) LoginUserFromRememberCookie(u *user.User, ctx *context.Context) (success bool) {
	userName := ctx.GetCookie(setting.CookieUsername)
	if len(userName) == 0 {
		return false
	}

	defer func() {
		if !success {
			this.DeleteRememberCookie(ctx)
		}
	}()
	u.Username = userName
	if err := this.UserService.Read(u, "Username"); err != nil {
		return false
	}

	secret := utils.EncodeMd5(u.PasswordSalt + u.Password)
	value, _ := ctx.GetSecureCookie(secret, setting.CookieRememberName)
	if value != userName {
		return false
	}

	this.LoginUserRememberCookie(u, ctx, true)

	return true
}
Exemplo n.º 2
0
func (model *UserAdminModel) SetToUser(u *user.User) {
	// set md5 value if the value is an email
	if strings.IndexRune(model.GrEmail, '@') != -1 {
		model.GrEmail = utils.EncodeMd5(model.GrEmail)
	}

	utils.SetFormValues(model, u)
}
Exemplo n.º 3
0
// compare raw password and encoded password
func (this *UserService) VerifyPassword(rawPwd, encodedPwd string) bool {

	// for discuz accounts
	if len(encodedPwd) == 39 {
		salt := encodedPwd[:6]
		encoded := encodedPwd[7:]
		return encoded == utils.EncodeMd5(utils.EncodeMd5(rawPwd)+salt)
	}

	// split
	var salt, encoded string
	if len(encodedPwd) > 11 {
		salt = encodedPwd[:10]
		encoded = encodedPwd[11:]
	}

	return utils.EncodePassword(rawPwd, salt) == encoded
}
Exemplo n.º 4
0
func (form *ProfileForm) SaveUserProfile(u *user.User) error {
	// set md5 value if the value is an email
	if strings.IndexRune(form.GrEmail, '@') != -1 {
		form.GrEmail = utils.EncodeMd5(form.GrEmail)
	}

	changes := utils.FormChanges(u, form)
	if len(changes) > 0 {
		// if email changed then need re-active
		if u.Email != form.Email {
			u.Active = false
			changes = append(changes, "Active")
		}
		serv := &userServ.UserService{}
		utils.SetFormValues(form, u)
		return serv.Update(u, changes...)
	}
	return nil
}
Exemplo n.º 5
0
func (this *BaseController) WriteRememberCookie(u *user.User, ctx *context.Context) {
	secret := utils.EncodeMd5(u.PasswordSalt + u.Password)
	days := 86400 * setting.LoginRememberDays
	ctx.SetCookie(setting.CookieUsername, u.Username, days)
	ctx.SetSecureCookie(secret, setting.CookieRememberName, u.Username, days)
}