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
// 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. 3
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. 4
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
}
Esempio n. 5
0
File: cache.go Progetto: coddo/gost
// ResetExpireTime resets the timer for when the current entity will expire
func (cache *Cache) ResetExpireTime() {
	go func() {
		cache.ExpireTime = util.NextDateFromNow(selectedCacheExpireTime)
	}()
}
Esempio n. 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()
}