Exemple #1
0
// 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
}
Exemple #2
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
}
Exemple #3
0
// 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
}
Exemple #4
0
// 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
}
Exemple #5
0
// ResetExpireTime resets the timer for when the current entity will expire
func (cache *Cache) ResetExpireTime() {
	go func() {
		cache.ExpireTime = util.NextDateFromNow(selectedCacheExpireTime)
	}()
}
Exemple #6
0
// ResetToken generates a new token and resets the expire time target of the session
// This also triggers a Save() action, to update the cookie store
func (session *Session) ResetToken() error {
	session.ExpireTime = util.NextDateFromNow(tokenExpireTime)

	return session.Save()
}