Beispiel #1
0
func (u *userModel) user() (user.User, error) {
	usr := user.User{
		ID:            u.ID,
		DisplayName:   u.DisplayName,
		Email:         u.Email,
		EmailVerified: u.EmailVerified,
		Admin:         u.Admin,
	}

	if u.CreatedAt != 0 {
		usr.CreatedAt = time.Unix(u.CreatedAt, 0).UTC()
	}

	return usr, nil
}
Beispiel #2
0
// CreateUser creates a new user with the given hashedPassword; the connID should be the ID of the local connector.
// The userID of the created user is returned as the first argument.
func (m *UserManager) CreateUser(usr user.User, hashedPassword user.Password, connID string) (string, error) {
	tx, err := m.begin()
	if err != nil {
		return "", err
	}

	insertedUser, err := m.insertNewUser(tx, usr.Email, usr.EmailVerified)
	if err != nil {
		rollback(tx)
		return "", err
	}

	usr.ID = insertedUser.ID
	usr.CreatedAt = insertedUser.CreatedAt
	err = m.userRepo.Update(tx, usr)
	if err != nil {
		rollback(tx)
		return "", err
	}

	rid := user.RemoteIdentity{
		ConnectorID: connID,
		ID:          usr.ID,
	}
	if err := m.addRemoteIdentity(tx, usr.ID, rid); err != nil {
		rollback(tx)
		return "", err
	}

	pwi := user.PasswordInfo{
		UserID:   usr.ID,
		Password: hashedPassword,
	}
	err = m.pwRepo.Create(tx, pwi)
	if err != nil {
		rollback(tx)
		return "", err
	}

	err = tx.Commit()
	if err != nil {
		rollback(tx)
		return "", err
	}
	return usr.ID, nil
}
Beispiel #3
0
func (m *UserManager) SetDisplayName(usr user.User, displayName string) error {
	tx, err := m.begin()
	if err != nil {
		return err
	}
	defer rollback(tx)

	usr.DisplayName = displayName
	if err = m.userRepo.Update(tx, usr); err != nil {
		return err
	}

	if err = tx.Commit(); err != nil {
		return err
	}

	return nil
}