Ejemplo n.º 1
0
Archivo: app.go Proyecto: huntaub/list
// Remove Class from User Class List
func (c App) ClassRemove(dept string, num int) revel.Result {
	user, ok := c.Session["user"]
	if !ok {
		c.Response.Status = 403
		return c.Render()
	}

	var u models.User
	err := users.Find(map[string]string{"email": user}).One(&u)
	if err != nil {
		panic(err)
	}

	newBucket := make([]string, len(u.ClassBucket)-1)
	found := false
	i := 0
	for _, v := range u.ClassBucket {
		if v == fmt.Sprintf("%v %v", dept, num) && !found {
			found = true
			continue
		}
		newBucket[i] = v
		i++
	}
	u.ClassBucket = newBucket

	err = users.Update(map[string]string{"email": user}, u)
	if err != nil {
		panic(err)
	}

	return c.Redirect(routes.App.Index())
}
Ejemplo n.º 2
0
Archivo: app.go Proyecto: huntaub/list
// Add Class to User Class List
func (c App) ClassAdd(dept string, num int) revel.Result {
	user, ok := c.Session["user"]
	if !ok {
		c.Response.Status = 403
		return c.Render()
	}

	var u models.User
	err := users.Find(map[string]string{"email": user}).One(&u)
	if err != nil {
		panic(err)
	}

	u.ClassBucket = append(u.ClassBucket, fmt.Sprintf("%v %v", dept, num))

	err = users.Update(map[string]string{"email": user}, u)
	if err != nil {
		panic(err)
	}

	return c.Redirect(routes.App.Index())
}
Ejemplo n.º 3
0
// Verify User Email
func (u *Users) VerifyEmail(verification string, email string) revel.Result {
	// Grab the User Verifying
	var user *models.User
	err := users.Find(map[string]string{"email": email, "verificationkey": verification}).One(&user)
	if err != nil {
		u.Flash.Error("Incorrect verification key.")
		return u.Redirect(routes.App.Index())
	}

	// Update the User - They are Verified
	user.Verified = true
	err = users.Update(map[string]string{"email": email}, user)
	if err != nil {
		u.Flash.Error("Unable to verify you at this time.")
		return u.Redirect(routes.App.Index())
	}

	// Log them in
	u.Session["user"] = email

	// Show success
	u.Flash.Success("Email Successfully verified.")
	return u.Redirect(routes.App.Index())
}