mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 09:21:46 +08:00 
			
		
		
		
	optimization install
This commit is contained in:
		| @@ -41,6 +41,7 @@ class V2boardInstall extends Command | ||||
|      */ | ||||
|     public function handle() | ||||
|     { | ||||
|         try { | ||||
|             $this->info(" | ||||
|                 __     ______  ____                      _ | ||||
|                 \ \   / /___ \| __ )  ___   __ _ _ __ __| | | ||||
| @@ -49,11 +50,11 @@ class V2boardInstall extends Command | ||||
|                    \_/  |_____|____/ \___/ \__,_|_|  \__,_| | ||||
|             "); | ||||
|             if (\File::exists(base_path() . '/.lock')) { | ||||
|             $this->error('V2board 已安装,如需重新安装请删除目录下.lock文件'); | ||||
|                 abort(500, 'V2board 已安装,如需重新安装请删除目录下.lock文件'); | ||||
|             } | ||||
|             if (!\File::exists(base_path() . '/.env')) { | ||||
|                 if (!copy(base_path() . '/.env.example', base_path() . '/.env')) { | ||||
|                 $this->error('复制环境文件失败,请检查目录权限'); | ||||
|                     abort(500, '复制环境文件失败,请检查目录权限'); | ||||
|                 } | ||||
|             } | ||||
|             $this->saveToEnv([ | ||||
| @@ -68,16 +69,16 @@ class V2boardInstall extends Command | ||||
|             try { | ||||
|                 DB::connection()->getPdo(); | ||||
|             } catch (\Exception $e) { | ||||
|             $this->error('数据库连接失败'); | ||||
|                 abort(500, '数据库连接失败'); | ||||
|             } | ||||
|             $file = \File::get(base_path() . '/database/install.sql'); | ||||
|             if (!$file) { | ||||
|             $this->error('数据库文件不存在'); | ||||
|                 abort(500, '数据库文件不存在'); | ||||
|             } | ||||
|             $sql = str_replace("\n", "", $file); | ||||
|             $sql = preg_split("/;/", $sql); | ||||
|             if (!is_array($sql)) { | ||||
|             $this->error('数据库文件格式有误'); | ||||
|                 abort(500, '数据库文件格式有误'); | ||||
|             } | ||||
|             $this->info('正在导入数据库请稍等...'); | ||||
|             foreach ($sql as $item) { | ||||
| @@ -96,11 +97,14 @@ class V2boardInstall extends Command | ||||
|                 $password = $this->ask('请输入管理员密码?'); | ||||
|             } | ||||
|             if (!$this->registerAdmin($email, $password)) { | ||||
|             $this->error('管理员账号注册失败,请重试'); | ||||
|                 abort(500, '管理员账号注册失败,请重试'); | ||||
|             } | ||||
|  | ||||
|             $this->info('一切就绪'); | ||||
|             \File::put(base_path() . '/.lock', time()); | ||||
|         } catch (\Exception $e) { | ||||
|             $this->error($e->getMessage()); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private function registerAdmin($email, $password) | ||||
| @@ -108,7 +112,7 @@ class V2boardInstall extends Command | ||||
|         $user = new User(); | ||||
|         $user->email = $email; | ||||
|         if (strlen($password) < 8) { | ||||
|             $this->error('管理员密码长度最小为8位字符'); | ||||
|             abort(500, '管理员密码长度最小为8位字符'); | ||||
|         } | ||||
|         $user->password = password_hash($password, PASSWORD_DEFAULT); | ||||
|         $user->v2ray_uuid = Helper::guid(true); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user