예제 #1
0
파일: users.go 프로젝트: 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
}
예제 #2
0
파일: sessions.go 프로젝트: coddo/gost
// 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
}
예제 #3
0
파일: users.go 프로젝트: 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
}
예제 #4
0
파일: users.go 프로젝트: 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
}
예제 #5
0
파일: cache.go 프로젝트: coddo/gost
// ResetExpireTime resets the timer for when the current entity will expire
func (cache *Cache) ResetExpireTime() {
	go func() {
		cache.ExpireTime = util.NextDateFromNow(selectedCacheExpireTime)
	}()
}
예제 #6
0
파일: sessions.go 프로젝트: coddo/gost
// 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()
}