forked from evolution-cms/UserManager
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
caf21cd
commit 926532d
Showing
6 changed files
with
83 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace EvolutionCMS\UserManager\Exceptions; | ||
|
||
class TokenExpiredException extends \Exception { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php namespace EvolutionCMS\UserManager\Services\Users; | ||
|
||
use Carbon\Carbon; | ||
use EvolutionCMS\Exceptions\ServiceActionException; | ||
use EvolutionCMS\Exceptions\ServiceValidationException; | ||
use EvolutionCMS\UserManager\Exceptions\TokenExpiredException; | ||
use EvolutionCMS\UserManager\Interfaces\UserServiceInterface; | ||
use \EvolutionCMS\Models\User; | ||
use Illuminate\Support\Facades\Lang; | ||
|
||
class UserTokenLogin extends UserLogin | ||
{ | ||
public function getValidationRules(): array | ||
{ | ||
return [ | ||
'token' => ['required'], | ||
'context' => ['nullable', 'in:web,mgr'], | ||
]; | ||
} | ||
|
||
public function getValidationMessages(): array | ||
{ | ||
return [ | ||
'token.required' => Lang::get("global.required_field", ['field' => 'token']), | ||
]; | ||
} | ||
|
||
/** | ||
* @return \Illuminate\Database\Eloquent\Model | ||
* @throws ServiceActionException | ||
* @throws ServiceValidationException | ||
*/ | ||
public function process(): \Illuminate\Database\Eloquent\Model | ||
{ | ||
if (!$this->checkRules()) { | ||
throw new ServiceActionException(\Lang::get('global.login_processor_unknown_user')); | ||
} | ||
|
||
$this->user = \EvolutionCMS\Models\User::query() | ||
->where('access_token', $this->userData['token'])->first(); | ||
if (is_null($this->user)) { | ||
throw new ServiceActionException(\Lang::get('global.login_processor_unknown_user')); | ||
} | ||
|
||
if(Carbon::now()->greaterThan($this->user->valid_to)) { | ||
throw new TokenExpiredException(\Lang::get('global.login_token_expired')); | ||
} | ||
|
||
$this->userSettings = $this->user->settings->pluck('setting_value', 'setting_name')->toArray(); | ||
|
||
$this->validateAuth(); | ||
$this->authProcess(); | ||
$this->clearActiveUsers(); | ||
|
||
if ($this->events) { | ||
// invoke OnManagerLogin event | ||
EvolutionCMS()->invokeEvent('OnUserLogin', array( | ||
'userid' => $this->user->getKey(), | ||
'username' => $this->user->username, | ||
)); | ||
} | ||
|
||
return $this->user; | ||
} | ||
} |