diff --git a/app/Controllers/SkinlibController.php b/app/Controllers/SkinlibController.php index 8962df89..6a6e80fb 100644 --- a/app/Controllers/SkinlibController.php +++ b/app/Controllers/SkinlibController.php @@ -96,7 +96,7 @@ class SkinlibController extends BaseController { if (!isset($_GET['tid'])) Http::abort(404, 'No specified tid.'); $texture = Texture::find($_GET['tid']); - +/* if (!$texture || $texture && !\Storage::exist(BASE_DIR."/textures/".$texture->hash)) { if (Option::get('auto_del_invalid_texture') == "1") { if ($texture) $texture->delete(); @@ -104,7 +104,7 @@ class SkinlibController extends BaseController } Http::abort(404, '请求的材质文件已经被删除,请联系管理员删除该条目'); } - +*/ if ($texture->public == "0") { if (is_null($this->user) || ($this->user->uid != $texture->uploader && !$this->user->is_admin)) Http::abort(404, '请求的材质已经设为隐私,仅上传者和管理员可查看'); diff --git a/app/Middlewares/CheckLoggedInMiddleware.php b/app/Middlewares/CheckLoggedInMiddleware.php index 071ea251..56f6ce3a 100644 --- a/app/Middlewares/CheckLoggedInMiddleware.php +++ b/app/Middlewares/CheckLoggedInMiddleware.php @@ -5,7 +5,10 @@ namespace App\Middlewares; use Pecee\Http\Middleware\IMiddleware; use Pecee\Http\Request; use App\Models\User; +use App\Models\UserModel; use App\Exceptions\E; +use View; +use Http; class CheckLoggedInMiddleware implements IMiddleware { @@ -20,20 +23,42 @@ class CheckLoggedInMiddleware implements IMiddleware $user = new User($_SESSION['uid']); if ($_SESSION['token'] != $user->getToken()) - \Http::redirect('../auth/login', '无效的 token,请重新登录~'); + Http::redirect('../auth/login', '无效的 token,请重新登录~'); if ($user->getPermission() == "-1") { // delete cookies - setcookie("uid", "", time() - 3600, '/'); - setcookie("token", "", time() - 3600, '/'); + setcookie('uid', '', time() - 3600, '/'); + setcookie('token', '', time() - 3600, '/'); session_destroy(); throw new E('你已经被本站封禁啦,请联系管理员解决', 5, true); } + // ask for filling email + if ($user->email == "") { + if (isset($_POST['email'])) { + if (\Validate::email($_POST['email'])) { + if (UserModel::where('email', $_POST['email'])->get()->isEmpty()) { + $user->setEmail($_POST['email']); + // refresh token + $_SESSION['token'] = $user->getToken(true); + setcookie('token', $_SESSION['token'], time() + 3600, '/'); + return $user; + } else { + echo View::make('auth.bind')->with('msg', '该邮箱已被占用'); + } + } else { + echo View::make('auth.bind')->with('msg', '邮箱格式错误'); + } + exit; + } + View::show('auth.bind'); + exit; + } + return $user; } else { - \Http::redirect('../auth/login', '非法访问,请先登录'); + Http::redirect('../auth/login', '非法访问,请先登录'); } } } diff --git a/app/Models/User.php b/app/Models/User.php index 5765fddb..04f01071 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -130,9 +130,9 @@ class User return $this->model->save(); } - public function getToken() + public function getToken($refresh = false) { - if ($this->token === "") + if ($this->token === "" || $refresh) $this->token = md5($this->model->email . $this->model->password . $_ENV['SALT']); return $this->token; } diff --git a/app/Services/Migration.php b/app/Services/Migration.php index 3d9f75b6..e35334d4 100644 --- a/app/Services/Migration.php +++ b/app/Services/Migration.php @@ -14,9 +14,15 @@ class Migration require BASE_DIR."/setup/tables.php"; } - public static function importV2Textures() + public static function __callStatic($method, $args) { - return require BASE_DIR."/setup/migrations/import_v2_textures.php"; + if (strpos($method, 'import') !== false) { + $filename = BASE_DIR."/setup/migrations/".snake_case($method).".php"; + if (Storage::exist($filename)) { + return require $filename; + } + } + throw new \InvalidArgumentException('Non-existent migration'); } } diff --git a/resources/views/auth/bind.tpl b/resources/views/auth/bind.tpl new file mode 100644 index 00000000..65831c12 --- /dev/null +++ b/resources/views/auth/bind.tpl @@ -0,0 +1,40 @@ +@extends('auth.master') + +@section('title', '绑定邮箱') + +@section('content') + +
欢迎!您需要填写邮箱以继续使用本站。
+ + + +本功能用于导入 v2 的用户账户数据至 v3,请先将 v2 的 users 表改名导入到当前 v3 的同一数据库中
+注意: v3 当前设置的密码加密方式必须和之前 v2 的一致,否则导入后的用户将无法登录。
+ +已导入 {{ $result['imported'] }} 个用户,{{ $result['duplicated'] }} 个用户因重复而未导入。
+ ++导入完成 +
+ +@endif + +@endsection diff --git a/resources/views/setup/migrations/index.tpl b/resources/views/setup/migrations/index.tpl index e1d815b3..c2d6de99 100644 --- a/resources/views/setup/migrations/index.tpl +++ b/resources/views/setup/migrations/index.tpl @@ -4,8 +4,7 @@欢迎使用 Blessing Skin Server 数据迁移工具,此工具用于迁移 v2 的数据至 v3。
-目前仅支持从 v2 导入用户皮肤至 v3 的皮肤库中。
-更多功能等我有时间再些吧(学业为重
+目前支持导入 v2 的用户数据以及导入用户皮肤至 v3 的皮肤库中。
导入 v2 皮肤库 - 导入 v2 用户数据 + 导入 v2 用户数据
@endsection diff --git a/setup/index.php b/setup/index.php index f9806dad..bbbaf880 100644 --- a/setup/index.php +++ b/setup/index.php @@ -85,7 +85,7 @@ switch ($step) { } // register super admin - $user = new App\Models\User(0, ['email' => $_POST['email']]); + $user = new App\Models\User(null, ['email' => $_POST['email']]); $user->register($_POST['password'], Http::getRealIP()); $user->setPermission('2'); diff --git a/setup/migrations/import_v2_textures.php b/setup/migrations/import_v2_textures.php index 0682517b..5cdf1853 100644 --- a/setup/migrations/import_v2_textures.php +++ b/setup/migrations/import_v2_textures.php @@ -3,12 +3,14 @@ * @Author: printempw * @Date: 2016-08-09 21:44:13 * @Last Modified by: printempw - * @Last Modified time: 2016-08-14 08:00:49 + * @Last Modified time: 2016-08-19 22:48:54 * * There are still some coupling relationships here but, * Just let it go :) */ +if (!defined('BASE_DIR')) exit('Permission denied.'); + $v2_table_name = $_POST['v2_table_name']; $v3_table_name = Config::getDbConfig()['prefix']."textures"; @@ -20,6 +22,8 @@ $db = Database::table($v2_table_name, true); $steps = ceil($db->getRecordNum() / 250); +$public = isset($_POST['import_as_private']) ? '1' : '0'; + // chunked for ($i = 0; $i <= $steps; $i++) { $start = $i * 250; @@ -42,14 +46,14 @@ for ($i = 0; $i <= $steps; $i++) { 'hash' => $row['hash_steve'], 'size' => 0, 'uploader' => $_POST['uploader_uid'], - 'public' => '1', + 'public' => $public, 'upload_at' => Utils::getTimeFormatted() ], $v3_table_name); - $imported += 1; + $imported++; // echo $row['hash_steve']." saved.