/
UserMigration.php
280 lines (240 loc) · 9.95 KB
/
UserMigration.php
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?php
/**
* UserMigration.php
*
* PHP version 7
*
* @category Migrations
* @package Xpressengine\Migrations
* @author XE Developers <developers@xpressengine.com>
* @copyright 2015 Copyright (C) NAVER Corp. <http://www.navercorp.com>
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html LGPL-2.1
* @link https://xpressengine.io
*/
namespace Xpressengine\Migrations;
use Illuminate\Database\Schema\Blueprint;
use DB;
use Schema;
use Xpressengine\Support\Migration;
/**
* Class UserMigration
*
* @category Migrations
* @package Xpressengine\Migrations
* @author XE Developers <developers@xpressengine.com>
* @copyright 2015 Copyright (C) NAVER Corp. <http://www.navercorp.com>
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html LGPL-2.1
* @link https://xpressengine.io
*/
class UserMigration extends Migration
{
/**
* Run when install the application.
*
* @return void
*/
public function install()
{
Schema::create('user', function (Blueprint $table) {
$table->engine = "InnoDB";
$table->string('id', 36)->comment('user ID');
$table->string('display_name', 255)->unique()->comment('display name.');
$table->string('email', 255)->nullable()->comment('email');
$table->string('password', 255)->nullable()->comment('password');
$table->string('rating', 15)->default('user')->comment('user rating. guest/user/manager/super');
$table->string('status', 20)->comment('account status. activated/deactivated');
$table->text('introduction')->default(null)->nullable()->comment('user introduction');
$table->string('profile_image_id', 36)->nullable()->comment('profile image file ID');
$table->string('remember_token', 255)->nullable()->comment('token for keep login');
$table->timestamp('login_at')->nullable()->comment('login date');
$table->timestamp('created_at')->nullable()->index()->comment('created date');
$table->timestamp('updated_at')->nullable()->index()->comment('updated date');
$table->timestamp('password_updated_at')->nullable()->comment('password updated date');
$table->primary('id');
});
Schema::create('user_group', function (Blueprint $table) {
$table->engine = "InnoDB";
$table->string('id', 36)->comment('group ID');
$table->string('name')->comment('group name');
$table->string('description', 1000)->comment('group description');
$table->integer('order')->default(0)->index()->comment('order number');
$table->timestamp('created_at')->nullable()->index()->comment('created date');
$table->timestamp('updated_at')->nullable()->comment('updated date');
$table->primary('id');
});
Schema::create('user_group_user', function (Blueprint $table) {
// user IDs included in the use group
$table->engine = "InnoDB";
$table->increments('id')->comment('ID');
$table->string('group_id', 36)->comment('group ID');
$table->string('user_id', 36)->comment('user ID');
$table->timestamp('created_at')->nullable()->comment('created date');
$table->unique(['group_id', 'user_id']);
$table->index('group_id');
$table->index('user_id');
});
Schema::create('user_account', function (Blueprint $table) {
// user account. Login via account information provided by other providers. As like OAuth.
$table->engine = "InnoDB";
$table->string('id', 36)->comment('ID');
$table->string('user_id')->comment('user ID');
$table->string('account_id')->comment('account Id');
$table->string('email')->nullable()->comment('email');
$table->char('provider', 20)->comment('OAuth provider. naver/twitter/facebook/...');
$table->string('token', 500)->comment('token');
$table->string('token_secret', 500)->comment('token secret');
$table->timestamp('created_at')->nullable()->comment('created date');
$table->timestamp('updated_at')->nullable()->comment('updated date');
$table->primary('id');
$table->unique(['provider', 'account_id']);
});
Schema::create('user_email', function (Blueprint $table) {
$table->engine = "InnoDB";
$table->increments('id')->comment('ID');
$table->string('user_id', 36)->comment('user ID');
$table->string('address')->comment('email address');
$table->timestamp('created_at')->nullable()->index()->comment('created date');
$table->timestamp('updated_at')->nullable()->comment('updated date');
$table->index('user_id');
$table->index('address');
});
Schema::create('user_pending_email', function (Blueprint $table) {
// email confirm
$table->engine = "InnoDB";
$table->increments('id')->comment('ID');
$table->string('user_id', 36)->comment('user ID');
$table->string('address')->comment('email address');
$table->string('confirmation_code')->nullable()->comment('confirmation code');
$table->timestamp('created_at')->nullable()->index()->comment('created date');
$table->timestamp('updated_at')->nullable()->comment('updated date');
$table->index('user_id');
$table->index('address');
});
Schema::create('user_password_resets', function (Blueprint $table) {
// find account password
$table->engine = "InnoDB";
$table->increments('id')->comment('ID');
$table->string('email')->index()->comment('email address');
$table->string('token')->index()->comment('token');
$table->timestamp('created_at')->nullable()->comment('created date');
});
Schema::create('user_register_token', function (Blueprint $table) {
// find account password
$table->engine = "InnoDB";
$table->string('id', 36)->comment('user ID');
$table->string('guard', 100)->comment('the guard creating token');
$table->text('data')->comment('token data');
$table->timestamp('created_at')->nullable()->comment('created date');
});
Schema::create('user_terms', function (Blueprint $table) {
$table->string('id', 36);
$table->string('title');
$table->string('content')->nullable();
$table->integer('order')->default(0);
$table->boolean('is_enabled')->default(false);
$table->primary('id');
$table->engine = "InnoDB";
});
Schema::create('user_login_log', function (Blueprint $table) {
$table->engine = "InnoDB";
$table->bigIncrements('id')->comment('row id');
$table->string('user_id', 36)->comment('user ID');
$table->string('user_agent')->comment('user agent');
$table->string('ip', 15)->comment('ip');
$table->timestamp('created_at')->nullable()->comment('created date');
$table->index('user_id');
});
}
/**
* Run after installation.
*
* @return void
*/
public function installed()
{
DB::table('config')->insert([
['name' => 'user', 'vars' => '[]'],
['name' => 'user.common', 'vars' => '{"secureLevel":"low","useCaptcha":false,"webmasterName":"webmaster","webmasterEmail":"webmaster@domain.com", "joinable":true}'],
['name' => 'toggleMenu@user', 'vars' => '{"activate":["user\/toggleMenu\/xpressengine@profile","user\/toggleMenu\/xpressengine@manage"]}']
]);
}
/**
* Run after service activation.
*
* @return void
*/
public function init()
{
// add default user groups
$joinGroup = app('xe.user')->groups()->create(
[
'name' => '정회원',
'description' => 'default user group'
]
);
app('xe.user')->groups()->create(
[
'name' => '준회원',
'description' => 'sub user group'
]
);
$joinConfig = app('xe.config')->get('user.common');
$joinConfig->set('joinGroup', $joinGroup->id);
app('xe.config')->modify($joinConfig);
// set admin's group
auth()->user()->joinGroups($joinGroup);
}
/**
* check updated
*
* @param null $installedVersion installed version
*
* @return bool
*/
public function checkUpdated($installedVersion = null)
{
if ($this->checkNeedMergeConfig() == true) {
return false;
}
return true;
}
/**
* run update
*
* @param null $installedVersion installed version
*
* @return void
*/
public function update($installedVersion = null)
{
if ($this->checkNeedMergeConfig() == true) {
$this->mergeConfig();
}
}
/**
* check need user setting merge(common, join)
*
* @return bool
*/
private function checkNeedMergeConfig()
{
return app('xe.config')->get('user.join') !== null ? true : false;
}
/**
* run user setting merge(common, join)
*
* @return void
*/
private function mergeConfig()
{
$commonConfig = app('xe.config')->get('user.common');
$joinConfig = app('xe.config')->get('user.join');
$commonConfigAttribute = $commonConfig->getPureAll();
$joinConfigAttribute = $joinConfig->getPureAll();
foreach ($joinConfigAttribute as $name => $value) {
$commonConfigAttribute[$name] = $value;
}
app('xe.config')->put('user.common', $commonConfigAttribute);
app('xe.config')->remove($joinConfig);
}
}