forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocialAccountsController.php
More file actions
92 lines (84 loc) · 3.1 KB
/
Copy pathSocialAccountsController.php
File metadata and controls
92 lines (84 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
declare(strict_types=1);
/**
* Copyright 2010 - 2019, Cake Development Corporation (https://www.cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2018, Cake Development Corporation (https://www.cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace CakeDC\Users\Controller;
use Cake\Datasource\Exception\RecordNotFoundException;
use CakeDC\Users\Exception\AccountAlreadyActiveException;
use CakeDC\Users\Utility\UsersUrl;
/**
* SocialAccounts Controller
*
* @property \CakeDC\Users\Model\Table\SocialAccountsTable $SocialAccounts
*/
class SocialAccountsController extends AppController
{
/**
* Init
*
* @return void
*/
public function initialize(): void
{
parent::initialize();
}
/**
* Validates social account
*
* @param string $provider provider
* @param string $reference reference
* @param string $token token
* @return \Cake\Http\Response
*/
public function validateAccount($provider, $reference, $token)
{
try {
$result = $this->SocialAccounts->validateAccount($provider, $reference, $token);
if ($result) {
$this->Flash->success(__d('cake_d_c/users', 'Account validated successfully'));
} else {
$this->Flash->error(__d('cake_d_c/users', 'Account could not be validated'));
}
} catch (RecordNotFoundException $exception) {
$this->Flash->error(__d('cake_d_c/users', 'Invalid token and/or social account'));
} catch (AccountAlreadyActiveException $exception) {
$this->Flash->error(__d('cake_d_c/users', 'Social Account already active'));
} catch (\Exception $exception) {
$this->Flash->error(__d('cake_d_c/users', 'Social Account could not be validated'));
}
return $this->redirect(UsersUrl::actionUrl('login'));
}
/**
* Resends validation email if required
*
* @param string $provider provider
* @param string $reference reference
* @return mixed
* @throws \CakeDC\Users\Exception\AccountAlreadyActiveException
*/
public function resendValidation($provider, $reference)
{
try {
$result = $this->SocialAccounts->resendValidation($provider, $reference);
if ($result) {
$this->Flash->success(__d('cake_d_c/users', 'Email sent successfully'));
} else {
$this->Flash->error(__d('cake_d_c/users', 'Email could not be sent'));
}
} catch (RecordNotFoundException $exception) {
$this->Flash->error(__d('cake_d_c/users', 'Invalid account'));
} catch (AccountAlreadyActiveException $exception) {
$this->Flash->error(__d('cake_d_c/users', 'Social Account already active'));
} catch (\Exception $exception) {
$this->Flash->error(__d('cake_d_c/users', 'Email could not be resent'));
}
return $this->redirect(UsersUrl::actionUrl('login'));
}
}