Skip to content

Commit

Permalink
adiciona configuração para habilitar o login após o registro e corrig…
Browse files Browse the repository at this point in the history
…e redirecionamento após o login/criação de conta
  • Loading branch information
rafaelchavesfreitas committed Dec 28, 2023
1 parent 5390b60 commit 3743030
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
27 changes: 22 additions & 5 deletions Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ function __construct ($config) {
$config += [
'salt' => env('AUTH_SALT', null),
'timeout' => env('AUTH_TIMEOUT', '24 hours'),

'loginOnRegister' => env('AUTH_LOGIN_ON_REGISTER', false),

'enableLoginByCPF' => env('AUTH_LOGIN_BY_CPF', true),
'passwordMustHaveCapitalLetters' => env('AUTH_PASS_CAPITAL_LETTERS', true),
Expand Down Expand Up @@ -318,7 +320,8 @@ protected function _init() {
$registration = $app->auth->doRegister();

if ($registration['success']) {
$this->json(['error' => false, 'emailSent' => $registration['emailSent']]);
$registration['error'] = false;
$this->json($registration);
} else {
$this->errorJson($registration['errors'], 200);
}
Expand All @@ -332,7 +335,10 @@ protected function _init() {
$login = $app->auth->doLogin();

if ($login['success']) {
$this->json(['error' => false]);
$this->json([
'error' => false,
'redirectTo' => $app->auth->getRedirectPath()
]);
} else {
$this->errorJson($login['errors'], 200);
}
Expand Down Expand Up @@ -1231,8 +1237,16 @@ function doRegister() {
$user->save();
$app->enableAccessControl();


$authenticated = false;
if ($this->_config['loginOnRegister']) {
$this->authenticateUser($user);
$authenticated = true;
}
return [
'success' => true,
'authenticated' => $authenticated,
'redirectTo' => $authenticated ? $this->getRedirectPath() : '',
'emailSent' => (
isset($config['auth.config']) &&
isset($config['auth.config']['userMustConfirmEmailToUseTheSystem']) &&
Expand Down Expand Up @@ -1401,7 +1415,7 @@ public function processResponse(){
$user = $this->createUser($response);

$profile = $user->profile;
$this->_setRedirectPath($profile->editUrl);
// $this->_setRedirectPath($profile->editUrl);
}
$this->_setAuthenticatedUser($user);

Expand Down Expand Up @@ -1533,9 +1547,12 @@ protected function _createUser($response) {
}

$app->enableAccessControl();
$redirectUrl = $agent->editUrl;
$redirectUrl = $agent->status == Agent::STATUS_DRAFT ? $agent->editUrl : $this->getRedirectPath();
$app->applyHookBoundTo($this, 'auth.createUser:redirectUrl', [&$redirectUrl]);
$this->_setRedirectPath($redirectUrl);

if ($redirectUrl) {
$this->_setRedirectPath($redirectUrl);
}

return $user;
}
Expand Down
3 changes: 3 additions & 0 deletions components/create-account/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ app.component('create-account', {
if (dataReturn.error) {
this.throwErrors(dataReturn.data);
} else {
if (dataReturn.redirectTo) {
window.location = dataReturn.redirectTo;
}
this.created = true;
if (dataReturn.emailSent) {
this.emailSent = true;
Expand Down
6 changes: 5 additions & 1 deletion components/login/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ app.component('login', {
if (dataReturn.error) {
this.throwErrors(dataReturn.data);
} else {
window.location.href = $MAPAS.baseURL+'panel';
if(dataReturn.redirectTo) {
window.location.href = dataReturn.redirectTo;
} else {
window.location.href = Utils.createUrl('panel', 'index');
}
}
}));
},
Expand Down

0 comments on commit 3743030

Please sign in to comment.