-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAuthSettingsController.php
More file actions
121 lines (106 loc) · 3.24 KB
/
AuthSettingsController.php
File metadata and controls
121 lines (106 loc) · 3.24 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* AuthSettings Controller
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @author Mitsuru Mutaguchi <mutaguchi@opensource-workshop.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('SystemManagerAppController', 'SystemManager.Controller');
/**
* システム管理【ログイン設定】
* 外部プラグインの認証設定を行う。
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @author Mitsuru Mutaguchi <mutaguchi@opensource-workshop.jp>
* @package NetCommons\SystemManager\Controller
*/
class AuthSettingsController extends SystemManagerAppController {
/**
* use model
*
* @var array
*/
public $uses = array(
'SiteManager.SiteSetting',
);
/**
* Other components
*
* @var array
*/
public $components = array(
'Auth.AuthPlugin',
);
/**
* beforeFilter
*
* @return void
* @see SystemManagerHelper::tabs()
**/
public function beforeFilter() {
$this->set('authTabs', $this->_getAuthTabs());
$this->set('activeAuthTab', $this->_getActiveAuthTab());
parent::beforeFilter();
}
/**
* 外部認証プラグインのタブを取得
*
* @return array
*/
protected function _getAuthTabs() {
$tabs = array();
$authExternalPlugins = $this->AuthPlugin->getExternals();
foreach ($authExternalPlugins as $plugin) {
//elementを読み込み設定
$tagId = strtr(Inflector::underscore($plugin), '_', '-');
$tabs[$tagId] = array(
'label' => __d(Inflector::underscore($plugin), $plugin . '.setting.label'),
'element' => $plugin . '.setting'
);
}
return $tabs;
}
/**
* get active auth tab
*
* @return string
*/
protected function _getActiveAuthTab() {
$authExternalPlugins = $this->AuthPlugin->getExternals();
$initTagId = strtr(Inflector::underscore($authExternalPlugins[0]), '_', '-');
if ($this->request->is('post')) {
$activeAuthTab = Hash::get($this->request->data['SiteSetting'], 'activeAuthTab', $initTagId);
} else {
$activeAuthTab = Hash::get($this->request->query, 'activeAuthTab', $initTagId);
}
return $activeAuthTab;
}
/**
* edit
*
* @return void
*/
public function edit() {
// activeAuthTabを除去
$this->request->data = Hash::remove($this->request->data, 'SiteSetting.activeAuthTab');
$authExternalPlugins = $this->AuthPlugin->getExternals();
foreach ($authExternalPlugins as $plugin) {
// プラグイン名(キャメル)に変更
$plugin = strtr($plugin, '-', '_');
$plugin = Inflector::camelize($plugin);
// AuthXXXX.AuthXXXXSetting
$pluginComponent = $plugin . '.' . $plugin . 'Setting';
// コンポーネントの動的ロード
$this->$pluginComponent = $this->Components->load($pluginComponent);
// @see https://book.cakephp.org/2.0/ja/controllers/components.html#id4
// > コンポーネントを動的にロードした場合、初期化メソッドが実行されないことを覚えておいて下さい。 このメソッドで読込んだ場合、ロード後に手動で実行する必要があります。
$this->$pluginComponent->initialize($this);
// $this->AuthXXXXSetting->edit()
$this->$pluginComponent->edit();
}
}
}