Exemplo n.º 1
0
func fillTables() {

	var err error

	for _, up := range dev_users {

		ub := &user.UserBasic{
			UserId:   up.UserId,
			UserName: up.UserName,
		}
		err = user.AddUserBasic(TestDB, ub)
		checkERROR(err)

		created_at := ub.CreatedAt
		updated_at := ub.UpdatedAt

		if created_at.IsZero() {
			revel.ERROR.Println("Should have created_at after create")
		}
		if updated_at.IsZero() {
			revel.ERROR.Println("Should have updated_at after create")
		}

		_, err = auth.AddUserAuth(TestDB, up)
		checkERROR(err)
	}

	revel.INFO.Println("Filled DBs")
}
Exemplo n.º 2
0
func fillUserTables() {
	var err error
	for _, devuser := range dev_users {
		err = user.AddUserBasic(TestDB, devuser.UserId, devuser.UserName)
		checkERROR(err)

		err = auth.AddUser(TestDB, devuser.UserId, devuser.Password)
		checkERROR(err)
	}
	revel.INFO.Println("Filled User DBs")
}
Exemplo n.º 3
0
func (c App) addNewMaillistUser(email, list string) error {

	// uuid := get random number (that isn't used already)
	uuid, err := user.GenerateNewUserId(c.Txn)
	if err != nil {
		return err
	}

	err = user.AddUserBasic(TestDB, uuid, email)
	checkERROR(err)

	err = maillist.AddUser(TestDB, uuid, email, list)
	checkERROR(err)

	return nil
}
Exemplo n.º 4
0
func (c App) RegisterPost(userregister *models.UserRegister) revel.Result {
	userregister.Validate(c.Validation)

	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Register())
	}

	// check that this email is not in the DB already
	UB, err := user.GetUserBasicByName(c.Txn, userregister.Email)
	checkERROR(err)

	if UB != nil {
		c.Validation.Error("Email already taken").Key("userregister.Email")
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Signup())
	}

	// uuid := get random number (that isn't used already)
	uuid, err := user.GenerateNewUserId(c.Txn)
	checkERROR(err)

	// add user to tables
	// TODO do something more with the errors
	err = user.AddUserBasic(TestDB, uuid, userregister.Email)
	checkERROR(err)

	err = auth.AddUser(TestDB, UB.UserId, userregister.Password)
	checkERROR(err)

	// TODO  which mailing lists did they check off?
	err = maillist.AddUser(TestDB, uuid, userregister.Email, "weekly")
	checkERROR(err)

	// TODO add address / phone DB insert
	// ...

	c.Flash.Out["heading"] = "Thanks for Joining!"
	c.Flash.Out["message"] = "you should be receiving an email at " +
		userregister.Email + " to confirm and activate your account."

	return c.Redirect(routes.App.Result())
}
Exemplo n.º 5
0
func (c App) SignupPost(usersignup *models.UserSignup) revel.Result {
	usersignup.Validate(c.Validation)

	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Signup())
	}

	// check that this email is not in the DB already
	UB, err := user.GetUserBasicByName(c.Txn, usersignup.Email)
	checkERROR(err)

	if UB != nil {
		c.Validation.Error("Email already taken").Key("usersignup.Email")
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Signup())
	}

	// uuid := get random number (that isn't used already)
	uuid, err := user.GenerateNewUserId(c.Txn)
	checkERROR(err)

	// update visitor info in DB with UserId
	c.updateVisitorWithUserIdPanic()

	// add user to tables
	// TODO do something more with the errors
	err = user.AddUserBasic(TestDB, uuid, usersignup.Email)
	checkERROR(err)

	err = auth.AddUser(TestDB, UB.UserId, usersignup.Password)
	checkERROR(err)

	c.Flash.Out["heading"] = "Thanks for Joining!"
	c.Flash.Out["message"] = "you should be receiving an email at " +
		usersignup.Email + " to confirm and activate your account."

	return c.Redirect(routes.App.Result())

}
Exemplo n.º 6
0
func (c App) addNewUser(email, password string) (*user.UserBasic, error) {
	// check for user in basic table
	UB := user.GetUserBasicByName(c.Txn, email)
	if UB != nil {
		c.Flash.Out["message"] = "Email: " + email + " already used"
		c.Validation.Keep()
		c.FlashParams()
		return nil, errors.New("UserBasic already in use")
	}

	// uuid := get random number (that isn't used already)
	uuid := int64(1001)
	UB = &user.UserBasic{
		UserId:   uuid,
		UserName: email,
	}

	// check for user in auth table
	UP := &user.UserPass{UB.UserId, email, password}
	UA, err := auth.Authenticate(c.Txn, UP)
	if UA != nil {
		c.Flash.Out["message"] = "Authentication Error"
		c.Validation.Keep()
		c.FlashParams()
		return nil, errors.New("UserAuth already in use")
	}

	// add user to tables

	err = user.AddUserBasic(TestDB, UB)
	checkERROR(err)

	_, err = auth.AddUserAuth(TestDB, UP)
	checkERROR(err)

	return UB, nil
}
Exemplo n.º 7
0
func (c App) RegisterPost(userregister *models.UserRegister) revel.Result {
	userregister.Validate(c.Validation)

	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Register())
	}

	// check that this email is not in the DB already
	UB, err := user.GetUserBasicByName(c.Txn, userregister.Email)
	checkERROR(err)

	if UB != nil {
		c.Validation.Error("Email already taken").Key("userregister.Email")
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.App.Signup())
	}

	// uuid := get random number (that isn't used already)
	uuid, err := user.GenerateNewUserId(c.Txn)
	checkERROR(err)

	// update visitor info in DB with UserId
	c.updateVisitorWithUserIdPanic()

	// add user to tables
	// TODO do something more with the errors
	err = user.AddUserBasic(TestDB, uuid, userregister.Email)
	checkERROR(err)

	err = auth.AddUser(TestDB, UB.UserId, userregister.Password)
	checkERROR(err)

	// TODO  which mailing lists did they check off?
	err = maillist.AddUser(TestDB, uuid, userregister.Email, "weekly")
	checkERROR(err)

	// TODO add address / phone DB insert
	// ...
	addy := &user.UserAddress{
		UserId:       uuid,
		AddressType:  "default",
		AddressLine1: userregister.Address1,
		AddressLine2: userregister.Address2,
		City:         userregister.City,
		State:        userregister.State,
		Zip:          userregister.Zipcode,
		Country:      userregister.Country,
	}
	err = user.AddUserAddress(TestDB, addy)
	checkERROR(err)

	err = user.AddUserPhone(TestDB, uuid, "default", userregister.PhoneNumber)
	checkERROR(err)

	c.Flash.Out["heading"] = "Thanks for Joining!"
	c.Flash.Out["message"] = "you should be receiving an email at " +
		userregister.Email + " to confirm and activate your account."

	return c.Redirect(routes.App.Result())
}