1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Controller\Front\User; |
4
|
|
|
|
5
|
|
|
use Apps\ActiveRecord\User; |
6
|
|
|
use Apps\Model\Front\User\FormLogin; |
7
|
|
|
use Ffcms\Core\App; |
8
|
|
|
use Ffcms\Core\Arch\View; |
9
|
|
|
use Ffcms\Core\Exception\ForbiddenException; |
10
|
|
|
use Ffcms\Core\Helper\Type\Str; |
11
|
|
|
use Ffcms\Core\Network\Request; |
12
|
|
|
use Ffcms\Core\Network\Response; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Trait ActionApprove |
16
|
|
|
* @package Apps\Controller\Front\User |
17
|
|
|
* @property View $view |
18
|
|
|
* @property Request $request |
19
|
|
|
* @property Response $response |
20
|
|
|
*/ |
21
|
|
|
trait ActionApprove |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Approve user profile via $email and $token params |
26
|
|
|
* @param string $email |
27
|
|
|
* @param string $token |
28
|
|
|
* @throws ForbiddenException |
29
|
|
|
*/ |
30
|
|
|
public function approve($email, $token) |
31
|
|
|
{ |
32
|
|
|
// validate token length and email format |
33
|
|
|
if (App::$User->isAuth() || Str::length($token) < 32 || !Str::isEmail($email)) { |
34
|
|
|
throw new ForbiddenException(__('Wrong recovery data')); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// lets find token&email |
38
|
|
|
/** @var User $user */ |
39
|
|
|
$user = App::$User->where('approve_token', $token) |
|
|
|
|
40
|
|
|
->where('email', '=', $email) |
41
|
|
|
->first(); |
42
|
|
|
|
43
|
|
|
// check if record is exist by token and email |
44
|
|
|
if (!$user) { |
45
|
|
|
throw new ForbiddenException(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// update approve_token value to confirmed |
49
|
|
|
$user->approve_token = '0'; |
50
|
|
|
$user->save(); |
51
|
|
|
|
52
|
|
|
// open session and redirect to main |
53
|
|
|
$loginModel = new FormLogin(); |
54
|
|
|
$loginModel->openSession($user); |
55
|
|
|
$this->response->redirect('/'); // session is opened, refresh page |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: