예제 #1
0
파일: account.go 프로젝트: rmasoni/heim
func (m *accountManager) RequestPasswordReset(
	ctx scope.Context, kms security.KMS, namespace, id string) (
	proto.Account, *proto.PasswordResetRequest, error) {

	m.b.Lock()
	defer m.b.Unlock()

	key := fmt.Sprintf("%s:%s", namespace, id)
	pi, ok := m.b.accountIDs[key]
	if !ok {
		return nil, nil, proto.ErrAccountNotFound
	}

	req, err := proto.GeneratePasswordResetRequest(kms, pi.accountID)
	if err != nil {
		return nil, nil, err
	}

	if m.b.resetReqs == nil {
		m.b.resetReqs = map[snowflake.Snowflake]*proto.PasswordResetRequest{req.ID: req}
	} else {
		m.b.resetReqs[req.ID] = req
	}

	return m.b.accounts[pi.accountID], req, nil
}
예제 #2
0
파일: account.go 프로젝트: NotAMoose/heim
func (b *AccountManagerBinding) RequestPasswordReset(
	ctx scope.Context, kms security.KMS, namespace, id string) (
	proto.Account, *proto.PasswordResetRequest, error) {

	t, err := b.DbMap.Begin()
	if err != nil {
		return nil, nil, err
	}

	rollback := func() {
		if err := t.Rollback(); err != nil {
			backend.Logger(ctx).Printf("rollback error: %s", err)
		}
	}

	account, err := b.resolve(t, namespace, id)
	if err != nil {
		rollback()
		return nil, nil, err
	}

	req, err := proto.GeneratePasswordResetRequest(kms, account.ID())
	if err != nil {
		rollback()
		return nil, nil, err
	}

	stored := &PasswordResetRequest{
		ID:        req.ID.String(),
		AccountID: req.AccountID.String(),
		Key:       req.Key,
		Requested: req.Requested,
		Expires:   req.Expires,
	}
	if err := t.Insert(stored); err != nil {
		rollback()
		return nil, nil, err
	}

	if err := t.Commit(); err != nil {
		rollback()
		return nil, nil, err
	}

	return account, req, nil
}