Ejemplo n.º 1
0
func ExampleGetAvatarURL() {
	// get URL to avatar image of size 256x256
	// fall back to "monster" generated avatar
	emailHash := gr.EmailHash("*****@*****.**")
	url := gr.GetAvatarURL("https", emailHash, gr.DefaultMonster, 256)
	fmt.Println(url.String())
}
Ejemplo n.º 2
0
//generate gravatar url
func genGravatarUrl(email string) string {
	return gravatar.GetAvatarURL(
		"https",
		gravatar.EmailHash(email),
		gravatar.DefaultMonster,
		256).String()

}
Ejemplo n.º 3
0
func ExampleSetAvatarURLOptions() {
	// get URL to avatar image of default size
	emailHash := gr.EmailHash("*****@*****.**")
	url := gr.GetAvatarURL("https", emailHash)
	fmt.Printf("default URL: %s", url.String())
	// set size to 256x256
	// fall back to "monster" generated avatar
	gr.SetAvatarURLOptions(url, gr.DefaultMonster, 256)
	fmt.Printf("modified URL: %s", url.String())
	// reset back to the default one
	gr.SetAvatarURLOptions(url)
	fmt.Printf("URL after reset: %s", url.String())
}
Ejemplo n.º 4
0
func (c Account) SaveUser(user models.User, username, name string) r.Result {

	// Lower case username
	username = strings.ToLower(username)
	lcPass := strings.ToLower(user.Password)

	// Validate User components
	models.ValidateUserEmail(c.Validation, user.Email).Key("user.Email")
	models.ValidateUserPassword(c.Validation, user.Password).Key("user.Password")

	// Additional user components verification
	c.Validation.Required(user.Password != user.Email).Message("Password cannot be the same as your email address").Key("user.Password")
	c.Validation.Required(lcPass != username).Message("Password cannot be the same as your user name").Key("user.Password")

	// Validate Profile components
	models.ValidateProfileUserName(c.Validation, username).Key("username")
	models.ValidateProfileName(c.Validation, name).Key("name")

	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		c.Flash.Error("Registration failed.")
		return c.Redirect(routes.Account.Register())
	}

	userExists := c.getProfileByEmailAddress(user.Email)

	if userExists != nil {
		c.Validation.Keep()
		c.FlashParams()
		c.Flash.Error("Email '" + user.Email + "' is already registered.")
		return c.Redirect(routes.Account.Register())
	}

	userExists = c.getProfileByUserName(username)

	if userExists != nil {
		c.Validation.Keep()
		c.FlashParams()
		c.Flash.Error("User name '" + username + "' is already taken.")
		return c.Redirect(routes.Account.Register())
	}

	user.HashedPassword, _ = bcrypt.GenerateFromPassword([]byte(user.Password), bcrypt.DefaultCost)

	user.Created = time.Now()

	user.Confirmed = false

	err := c.Txn.Insert(&user)
	if err != nil {
		panic(err)
	}

	// Create profile (and assign correct UserId)
	profile := &models.Profile{0, user.UserId, username, name, "", "", "", 0, 0, &user}

	// Get Gravatar Icon
	emailHash := gr.EmailHash(user.Email)
	gravatarUrl := gr.GetAvatarURL("https", emailHash, gr.DefaultIdentIcon, 128)

	if gravatarUrl != nil {
		profile.PhotoUrl = gravatarUrl.String()
	}

	err = c.Txn.Insert(profile)
	if err != nil {
		panic(err)
	}

	// Send out confirmation email
	err = c.sendAccountConfirmEmail(&user)

	if err != nil {
		c.Flash.Error("Could not send confirmation email")
		fmt.Println(err.Error())
	}

	c.Session["userEmail"] = string(user.Email)
	c.Flash.Success("Welcome, " + profile.Name)
	return c.Redirect(routes.Profile.Show(profile.UserName))
}