<?php
final class ForceUsernameSuffixListener
extends PhabricatorAutoEventListener {
public function register() {
$this->listen(PhabricatorEventType::TYPE_AUTH_WILLREGISTERUSER);
}
public function handleEvent(PhutilEvent $event) {
$account = $event->getValue('account');
$profile = $event->getValue('profile');
// ($account is a PhabricatorExternalAccount)
// ($profile is a PhabricatorRegistrationProfile)
if ($account->getAccountType() == 'ldap') {
// Allow LDAP users to do whatever they want.
return;
}
// Lock the usernames for other users.
$username = $profile->getDefaultUsername();
$username = $username.'-contrib';
$profile->setDefaultUsername($username);
$profile->setCanEditUsername(false);
}
}