From 374303082b1671f68bed925aaeeac4f1659f8bd5 Mon Sep 17 00:00:00 2001 From: Rafael Chaves Freitas Date: Thu, 28 Dec 2023 17:56:53 -0300 Subject: [PATCH] =?UTF-8?q?adiciona=20configura=C3=A7=C3=A3o=20para=20habi?= =?UTF-8?q?litar=20o=20login=20ap=C3=B3s=20o=20registro=20e=20corrige=20re?= =?UTF-8?q?direcionamento=20ap=C3=B3s=20o=20login/cria=C3=A7=C3=A3o=20de?= =?UTF-8?q?=20conta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Provider.php | 27 ++++++++++++++++++++++----- components/create-account/script.js | 3 +++ components/login/script.js | 6 +++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Provider.php b/Provider.php index 2310ba9..6987029 100644 --- a/Provider.php +++ b/Provider.php @@ -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), @@ -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); } @@ -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); } @@ -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']) && @@ -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); @@ -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; } diff --git a/components/create-account/script.js b/components/create-account/script.js index 29ca1a5..a1cd600 100644 --- a/components/create-account/script.js +++ b/components/create-account/script.js @@ -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; diff --git a/components/login/script.js b/components/login/script.js index 4481828..d616b91 100644 --- a/components/login/script.js +++ b/components/login/script.js @@ -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'); + } } })); },