fixup! merge signup and google signup handling with username support

This commit is contained in:
Bence Pőcze 2023-09-24 01:12:30 +02:00
parent aca8bdb4b1
commit e2dd78fca3
Signed by: bence
GPG Key ID: DC5BD6E95A333E6D

View File

@ -271,6 +271,8 @@ class LoginController
return new JsonContent(['redirect' => ['target' => $this->redirectUrl]]);
}
$newUser = new User();
$googleUserData = \Container::$request->session()->get('google_user_data');
if ($googleUserData !== null) {
$user = $this->userRepository->getByEmail($googleUserData['email']);
@ -285,9 +287,9 @@ class LoginController
]);
}
$active = true;
$email = $googleUserData['email'];
$googleSub = $googleUserData['sub'];
$newUser->setActive(true);
$newUser->setEmail($googleUserData['email']);
$newUser->setGoogleSub($googleUserData['sub']);
} else {
$user = $this->userRepository->getByEmailOrUsername(\Container::$request->post('email'));
@ -361,36 +363,31 @@ class LoginController
}
}
$active = false;
$email = \Container::$request->post('email');
$googleSub = null;
$newUser->setActive(false);
$newUser->setEmail(\Container::$request->post('email'));
$newUser->setPlainPassword(\Container::$request->post('password'));
}
$user = new User();
$user->setActive($active);
$user->setEmail($email);
$user->setUsername(strlen(\Container::$request->post('username')) > 0 ? \Container::$request->post('username') : Factory::create()->userName);
$user->setPlainPassword(\Container::$request->post('password'));
$user->setGoogleSub($googleSub);
$user->setCreatedDate(new DateTime());
$newUser->setUsername(strlen(\Container::$request->post('username')) > 0 ? \Container::$request->post('username') : Factory::create()->userName);
$newUser->setCreatedDate(new DateTime());
\Container::$persistentDataManager->saveToDb($user);
\Container::$persistentDataManager->saveToDb($newUser);
if ($active) {
$this->sendWelcomeEmail($user->getEmail());
if ($googleUserData !== null) {
$this->sendWelcomeEmail($newUser->getEmail());
\Container::$request->setUser($user);
} else {
$token = bin2hex(random_bytes(16));
$confirmation = new UserConfirmation();
$confirmation->setUser($user);
$confirmation->setUser($newUser);
$confirmation->setToken($token);
$confirmation->setLastSentDate(new DateTime());
\Container::$persistentDataManager->saveToDb($confirmation);
$this->sendConfirmationEmail($user->getEmail(), $token, $user->getCreatedDate());
$this->sendConfirmationEmail($newUser->getEmail(), $token, $newUser->getCreatedDate());
}
\Container::$request->session()->delete('tmp_user_data');