Пример #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")
}
Пример #2
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
}