Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.php
More file actions
Latest commit
147 lines (120 loc) · 4.59 KB
/
Copy pathplugin.php
File metadata and controls
147 lines (120 loc) · 4.59 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
* @author XE Developers <developers@xpressengine.com>
* @copyright 2015 Copyright (C) NAVER Corp. <http://www.navercorp.com>
* @license LGPL-2.1
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
* @link https://xpressengine.io
*/
namespaceXpressengine\Plugins\Ipin;
useDB;
useRoute;
useSchema;
useSymfony\Component\HttpKernel\Exception\HttpException;
useValidator;
useXeFrontend;
useXeRegister;
useXpressengine\Plugin\AbstractPlugin;
class Plugin extends AbstractPlugin
{
protected$table = 'user_ipin';
publicfunctionboot()
{
$this->routes();
$this->hooks();
$this->extendValidation();
}
publicfunctionregister()
{
app()->singleton('xe.plugin.ipin', function ($app) {
returnnewManager($app);
});
}
protectedfunctionroutes()
{
Route::fixed($this->getId(), function () {
Route::get('pop', ['as' => 'plugin.ipin.pop', 'uses' => 'UserController@pop']);
Route::get('callback', ['as' => 'plugin.ipin.callback', 'uses' => 'UserController@callback']);
}, ['namespace' => 'Xpressengine\\Plugins\\Ipin\\Controllers']);
Route::settings($this->getId(), function () {
Route::get('/', ['as' => 'setting.plugin.ipin', 'uses' => 'SettingController@index']);
Route::post('/', ['as' => 'setting.plugin.ipin', 'uses' => 'SettingController@store']);
}, ['namespace' => 'Xpressengine\\Plugins\\Ipin\\Controllers']);
}
protectedfunctionhooks()
{
// 회원 가입 항목 추가
intercept('XeUser@getRegisterForms', 'ipin::inject', function ($method, $token) {
XeRegister::push(
'user/register/form',
'ipin',
function ($data) {
XeFrontend::html('ipin.script')->content("
<script>
$('#__xe_btn-ipin').click(function () {
window.open('".route('plugin.ipin.pop')."', 'ipin', 'width=450,height=550');
});
</script>
")->load();
returnview('ipin::views.button');
}
);
return$method($token);
});
// 회원 등록
intercept('XeUser@create', 'ipin::certify', function ($method, $data, $token) {
$ipinToken = app('session')->get('ipin_token');
$dupInfo = app('session')->get('ipin_dup');
if ($ipinToken !== request('ipin_token')) {
thrownewHttpException(400, '인증정보가 잘못되었습니다.');
}
if ($row = DB::table($this->table)->where('dupInfo', $dupInfo)->first()) {
thrownewHttpException(400, '본인 확인 정보로 가입된 내역이 존재합니다.');
}
$user = $method($data, $token);
DB::table($this->table)->insert([
'userId' => $user->getkey(),
'dupInfo' => $dupInfo,
]);
app('session')->forget(['ipin_token', 'ipin_dup']);
return$user;
});
// 회원 탈퇴
intercept('XeUser@leave', 'ipin::delete', function ($method, $userIds) {
$userIds = (array)$userIds;
DB::table($this->table)->whereIn('userId', $userIds)->delete();
return$method($userIds);
});
}
protectedfunctionextendValidation()
{
Validator::extend('ipin_cb_txt', function ($attribute, $value) {
returnpreg_match('#[^0-9a-zA-Z+/=]#', $value);
});
Validator::replacer('ipin_cb_txt', function ($message, $attribute, $rule, $parameters) {
return'입력값 확인이 필요합니다.';
// return xe_trans('validation.mimes', ['attribute' => $attribute, 'values' => 'json']);
});
}
publicfunctioninstall()
{
Schema::create($this->table, function ($table) {
$table->increment('id');
$table->string('userId', 36);
$table->string('dupInfo');
$table->index('userId');
});
app('files')->makeDirectory(app('xe.plugin.ipin')->getKeyDir(), 0755, true);
app('xe.config')->set('ipin', ['code' => '']);
}
publicfunctionuninstall()
{
Schema::dropIfExists($this->table);
app('files')->deleteDirectory(app('xe.plugin.ipin')->getKeyDir());
app('xe.config')->removeByName('ipin');
}
publicfunctiongetSettingsURI()
{
returnroute('setting.plugin.ipin');
}
}