[DB] Remove unique constraint from GSActor.nickname and fix register and related functionality
This commit is contained in:
parent
68de1b09b1
commit
faa362e2e2
@ -14,7 +14,9 @@ use App\Entity\Note;
|
||||
use App\Security\Authenticator;
|
||||
use App\Security\EmailVerifier;
|
||||
use app\Util\Common;
|
||||
use App\Util\Exception\NicknameTakenException;
|
||||
use App\Util\Nickname;
|
||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
@ -89,18 +91,22 @@ class Security extends Controller
|
||||
|
||||
$valid_nickname = Nickname::normalize($data['nickname'], check_already_used: true);
|
||||
|
||||
$actor = GSActor::create(['nickname' => $data['nickname']]);
|
||||
DB::persist($actor);
|
||||
DB::flush();
|
||||
$id = $actor->getId();
|
||||
$user = LocalUser::create([
|
||||
'id' => $id,
|
||||
'nickname' => $data['nickname'],
|
||||
'outgoing_email' => $data['email'],
|
||||
'incoming_email' => $data['email'],
|
||||
'password' => LocalUser::hashPassword($data['password']),
|
||||
]);
|
||||
DB::persist($user);
|
||||
try {
|
||||
$actor = GSActor::create(['nickname' => $data['nickname']]);
|
||||
DB::persist($actor);
|
||||
DB::flush();
|
||||
$id = $actor->getId();
|
||||
$user = LocalUser::create([
|
||||
'id' => $id,
|
||||
'nickname' => $data['nickname'],
|
||||
'outgoing_email' => $data['email'],
|
||||
'incoming_email' => $data['email'],
|
||||
'password' => LocalUser::hashPassword($data['password']),
|
||||
]);
|
||||
DB::persist($user);
|
||||
} catch (UniqueConstraintViolationException $e) {
|
||||
throw new NicknameTakenException;
|
||||
}
|
||||
|
||||
// generate a signed url and email it to the user
|
||||
if (Common::config('site', 'use_email')) {
|
||||
|
@ -149,6 +149,12 @@ abstract class DB
|
||||
}
|
||||
}
|
||||
|
||||
public static function count(string $table, array $criteria)
|
||||
{
|
||||
$repo = self::getRepository($table);
|
||||
return $repo->count($table, $criteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* Intercept static function calls to allow refering to entities
|
||||
* without writing the namespace (which is deduced from the call
|
||||
|
@ -296,10 +296,7 @@ class GSActor extends Entity
|
||||
'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
|
||||
],
|
||||
'primary key' => ['id'],
|
||||
'unique keys' => [
|
||||
'gsactor_nickname_uniq' => ['nickname'],
|
||||
],
|
||||
'indexes' => [
|
||||
'indexes' => [
|
||||
'gsactor_nickname_idx' => ['nickname'],
|
||||
],
|
||||
'fulltext indexes' => [
|
||||
|
@ -358,7 +358,7 @@ class LocalUser extends Entity implements UserInterface
|
||||
'description' => 'local users, bots, etc',
|
||||
'fields' => [
|
||||
'id' => ['type' => 'int', 'foreign key' => true, 'target' => 'GSActor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to gsactor table'],
|
||||
'nickname' => ['type' => 'varchar', 'foreign key' => true, 'target' => 'GSActor.nickname', 'multiplicity' => 'one to one', 'not null' => true, 'length' => 64, 'description' => 'nickname or username, foreign key to gsactor'],
|
||||
'nickname' => ['type' => 'varchar', 'not null' => true, 'length' => 64, 'description' => 'nickname or username, foreign key to gsactor'],
|
||||
'password' => ['type' => 'varchar', 'length' => 191, 'description' => 'salted password, can be null for users with federated authentication'],
|
||||
'outgoing_email' => ['type' => 'varchar', 'length' => 191, 'description' => 'email address for password recovery, notifications, etc.'],
|
||||
'incoming_email' => ['type' => 'varchar', 'length' => 191, 'description' => 'email address for post-by-email'],
|
||||
|
@ -42,12 +42,13 @@
|
||||
namespace App\Util\Exception;
|
||||
|
||||
use function App\Core\I18n\_m;
|
||||
use App\Entity\GSActor;
|
||||
|
||||
class NicknameTakenException extends NicknameException
|
||||
{
|
||||
public ?Profile $profile = null; // the Profile which occupies the nickname
|
||||
public ?GSActor $profile = null; // the GSActor which occupies the nickname
|
||||
|
||||
public function __construct(Profile $profile, string $msg = null, int $code = 400)
|
||||
public function __construct(?GSActor $profile = null, ?string $msg = null, int $code = 400)
|
||||
{
|
||||
$this->profile = $profile;
|
||||
parent::__construct($msg, $code);
|
||||
|
@ -22,7 +22,6 @@
|
||||
namespace App\Util;
|
||||
|
||||
use App\Core\DB\DB;
|
||||
use App\Core\Log;
|
||||
use App\Entity\GSActor;
|
||||
use App\Entity\LocalGroup;
|
||||
use App\Entity\LocalUser;
|
||||
@ -156,7 +155,6 @@ class Nickname
|
||||
if (mb_strlen($original_nickname) < 1) {
|
||||
throw new NicknameEmptyException();
|
||||
} elseif (mb_strlen($original_nickname) < Common::config('nickname', 'min_length')) {
|
||||
Log::critical(var_dump($original_nickname, mb_strlen($original_nickname), Common::config('nickname', 'min_length'), mb_strlen($original_nickname) < Common::config('nickname', 'min_length')));
|
||||
throw new NicknameTooShortException();
|
||||
} elseif (!self::isCanonical($original_nickname) && !filter_var($original_nickname, FILTER_VALIDATE_EMAIL)) {
|
||||
throw new NicknameInvalidException();
|
||||
@ -223,12 +221,12 @@ class Nickname
|
||||
{
|
||||
$found = DB::findBy('local_user', ['nickname' => $nickname]);
|
||||
if ($found instanceof LocalUser) {
|
||||
return $found->getProfile();
|
||||
return $found->getGSActor();
|
||||
}
|
||||
|
||||
$found = DB::findBy('local_group', ['nickname' => $nickname]);
|
||||
if ($found instanceof LocalGroup) {
|
||||
return $found->getProfile();
|
||||
return $found->getGSActor();
|
||||
}
|
||||
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user