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
94 lines (86 loc) · 3.23 KB
/
Copy pathSocialAccountsController.php
File metadata and controls
94 lines (86 loc) · 3.23 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
93
94
<?php
/**
* Copyright 2010 - 2017, Cake Development Corporation (https://www.cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2017, Cake Development Corporation (https://www.cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace CakeDC\Users\Controller;
use CakeDC\Users\Controller\AppController;
use CakeDC\Users\Exception\AccountAlreadyActiveException;
use CakeDC\Users\Model\Table\SocialAccountsTable;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Response;
/**
* SocialAccounts Controller
*
* @property SocialAccountsTable $SocialAccounts
*/
class SocialAccountsController extends AppController
{
/**
* Init
*
* @return void
*/
public function initialize()
{
parent::initialize();
$this->Auth->allow(['validateAccount', 'resendValidation']);
}
/**
* Validates social account
*
* @param string $provider provider
* @param string $reference reference
* @param string $token token
* @return Response
*/
public function validateAccount($provider, $reference, $token)
{
try {
$result = $this->SocialAccounts->validateAccount($provider, $reference, $token);
if ($result) {
$this->Flash->success(__d('CakeDC/Users', 'Account validated successfully'));
} else {
$this->Flash->error(__d('CakeDC/Users', 'Account could not be validated'));
}
} catch (RecordNotFoundException $exception) {
$this->Flash->error(__d('CakeDC/Users', 'Invalid token and/or social account'));
} catch (AccountAlreadyActiveException $exception) {
$this->Flash->error(__d('CakeDC/Users', 'Social Account already active'));
} catch (\Exception $exception) {
$this->Flash->error(__d('CakeDC/Users', 'Social Account could not be validated'));
}
return $this->redirect(['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'login']);
}
/**
* Resends validation email if required
*
* @param string $provider provider
* @param string $reference reference
* @return mixed
* @throws AccountAlreadyActiveException
*/
public function resendValidation($provider, $reference)
{
try {
$result = $this->SocialAccounts->resendValidation($provider, $reference);
if ($result) {
$this->Flash->success(__d('CakeDC/Users', 'Email sent successfully'));
} else {
$this->Flash->error(__d('CakeDC/Users', 'Email could not be sent'));
}
} catch (RecordNotFoundException $exception) {
$this->Flash->error(__d('CakeDC/Users', 'Invalid account'));
} catch (AccountAlreadyActiveException $exception) {
$this->Flash->error(__d('CakeDC/Users', 'Social Account already active'));
} catch (\Exception $exception) {
$this->Flash->error(__d('CakeDC/Users', 'Email could not be resent'));
}
return $this->redirect(['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'login']);
}
}