[SECURITY][DB] Make user register 'atomic', by using a single transaction for inserting all objects, to avoid partial inserts
This commit is contained in:
@@ -93,17 +93,19 @@ class Security extends Controller
|
||||
|
||||
try {
|
||||
$actor = GSActor::create(['nickname' => $data['nickname']]);
|
||||
DB::persist($actor);
|
||||
DB::flush();
|
||||
$id = $actor->getId();
|
||||
$user = LocalUser::create([
|
||||
'id' => $id,
|
||||
$user = LocalUser::create([
|
||||
'nickname' => $data['nickname'],
|
||||
'outgoing_email' => $data['email'],
|
||||
'incoming_email' => $data['email'],
|
||||
'password' => LocalUser::hashPassword($data['password']),
|
||||
]);
|
||||
DB::persist($user);
|
||||
DB::persistWithSameId(
|
||||
$actor,
|
||||
$user,
|
||||
// Self follow
|
||||
fn (int $id) => DB::persist(Follow::create(['follower' => $id, 'followed' => $id]))
|
||||
);
|
||||
DB::flush();
|
||||
} catch (UniqueConstraintViolationException $e) {
|
||||
throw new NicknameTakenException;
|
||||
}
|
||||
@@ -123,11 +125,6 @@ class Security extends Controller
|
||||
$user->setIsEmailVerified(true);
|
||||
}
|
||||
|
||||
// Self follow
|
||||
$follow = Follow::create(['follower' => $id, 'followed' => $id]);
|
||||
DB::persist($follow);
|
||||
DB::flush();
|
||||
|
||||
return $guard_handler->authenticateUserAndHandleSuccess(
|
||||
$user,
|
||||
$request,
|
||||
|
Reference in New Issue
Block a user