Esempio n. 1
0
File: users.go Progetto: coddo/gost
// CreateAppUser creates a new ApplicationUser with the given data, generates an activation token
// and sends an email containing a link used for activating the account
func CreateAppUser(emailAddress, password string, accountType int, activationServiceLink string) (*identity.ApplicationUser, error) {
	var token, err = util.GenerateUUID()
	if err != nil {
		return nil, err
	}

	passwordHash, err := util.HashString(password)
	if err != nil {
		return nil, err
	}

	var user = &identity.ApplicationUser{
		ID:                             bson.NewObjectId(),
		Email:                          emailAddress,
		Password:                       passwordHash,
		AccountType:                    accountType,
		ActivateAccountToken:           token,
		ActivateAccountTokenExpireDate: util.NextDateFromNow(accountActivationTokenExpireTime),
	}

	err = identity.CreateUser(user)
	if err != nil {
		return nil, err
	}

	go sendAccountActivationEmail(emailAddress, activationServiceLink, token)

	return user, nil
}
Esempio n. 2
0
func testFetchInexistentCache(t *testing.T, mockQuery combinedKey) {
	t.Log("[info] Testing the cache querying system with inexistent or invalid data")

	// Will never be added
	var inexistentKey, _ = util.GenerateUUID()
	var inexistentDataKey, _ = util.GenerateUUID()
	data, _ := Query(inexistentKey, inexistentDataKey)
	if data != nil {
		t.Fatal("[error] Unexpected output from cache")
	}

	// Will be added later during the test
	data, _ = Query(mockQuery.Key, mockQuery.DataKey)
	if data != nil {
		t.Fatal("[error] Unexpected output from cache")
	}
}
Esempio n. 3
0
// NewSession generates a new Session pointer that contains the given userID and
// a unique token used as an identifier
func NewSession(userID bson.ObjectId, accountType int, client *Client) (*Session, error) {
	token, err := util.GenerateUUID()
	if err != nil {
		return nil, err
	}

	session := &Session{
		ID:          bson.NewObjectId(),
		UserID:      userID,
		AccountType: accountType,
		Token:       token,
		ExpireTime:  util.NextDateFromNow(tokenExpireTime),
		Client:      client,
	}

	return session, nil
}
Esempio n. 4
0
File: users.go Progetto: coddo/gost
// RequestResetPassword generates a reset token and sends an email with the link where to perform the change
func RequestResetPassword(emailAddress, passwordResetServiceLink string) error {
	var user, err = identity.GetUserByEmail(emailAddress)
	if err != nil {
		return err
	}

	token, err := util.GenerateUUID()
	if err != nil {
		return err
	}

	user.ResetPasswordToken = token
	user.ResetPasswordTokenExpireDate = util.NextDateFromNow(passwordResetTokenExpireTime)

	err = identity.UpdateUser(user)
	if err != nil {
		return err
	}

	go sendPasswordResetEmail(emailAddress, passwordResetServiceLink, token)

	return nil
}
Esempio n. 5
0
File: users.go Progetto: coddo/gost
// ResendAccountActivationEmail resends the email with the details for activating their user account
func ResendAccountActivationEmail(emailAddress, activationServiceLink string) error {
	var user, err = identity.GetUserByEmail(emailAddress)
	if err != nil {
		return err
	}

	token, err := util.GenerateUUID()
	if err != nil {
		return err
	}

	user.ActivateAccountToken = token
	user.ActivateAccountTokenExpireDate = util.NextDateFromNow(accountActivationTokenExpireTime)

	err = identity.UpdateUser(user)
	if err != nil {
		return err
	}

	go sendAccountActivationEmail(emailAddress, activationServiceLink, token)

	return nil
}