forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSocialTrait.php
More file actions
82 lines (75 loc) · 2.08 KB
/
Copy pathSocialTrait.php
File metadata and controls
82 lines (75 loc) · 2.08 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
<?php
/**
* Copyright 2010 - 2015, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2015, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace CakeDC\Users\Controller\Traits;
use CakeDC\Users\Auth\Factory\OpauthFactory;
use Cake\Core\Configure;
use Cake\Network\Exception\NotFoundException;
use Cake\Routing\Router;
/**
* Covers registration features and email token validation
*
*/
trait SocialTrait
{
/**
* Start Opauth authentication
*
* @param bool|false $callback callback
* @return void
*/
public function opauthInit($callback = null)
{
$this->autoRender = false;
$Opauth = $this->_getOpauthInstance();
$response = $Opauth->run();
if (empty($callback)) {
return;
}
$url = $this->_generateOpauthCompleteUrl();
$this->request->session()->write(Configure::read('Users.Key.Session.social'), $response);
return $this->redirect($url);
}
/**
* Generates the opauth callback url
*
* @return string Full translated URL with base path.
*/
protected function _generateOpauthCompleteUrl()
{
$url = Configure::read('Opauth.complete_url');
if (!is_array($url)) {
$url = Router::parse($url);
}
$url['?'] = ['social' => $this->request->query('code')];
return Router::url($url, true);
}
/**
* Render the social email form
*
* @throws NotFoundException
* @return void
*/
public function socialEmail()
{
if (!$this->request->session()->check(Configure::read('Users.Key.Session.social'))) {
throw new NotFoundException();
}
}
/**
* Gets OpauthFactory instance
*
* @return OpauthFactory
*/
protected function _getOpauthInstance()
{
return OpauthFactory::create(Configure::read('Opauth'));
}
}