diff --git a/.env.example b/.env.example index 8984a28d..f8365069 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ -APP_NAME=Laravel +APP_NAME=NexusPHP APP_ENV=local APP_KEY=base64:WUbN2wa2kl3E1VDW4iKaH3RBHw3hKY7BK0hWEkBZmGg= APP_DEBUG=true @@ -10,7 +10,7 @@ LOG_LEVEL=debug DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 -DB_DATABASE=laravel +DB_DATABASE=nexusphp DB_USERNAME=root DB_PASSWORD= @@ -45,21 +45,13 @@ MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" - -MYSQL_HOST=127.0.0.1 -MYSQL_PORT=3306 -MYSQL_USERNAME= -MYSQL_PASSWORD= -MYSQL_DATABASE=nexusphp - -REDIS_HOST=127.0.0.1 -REDIS_PASSWORD=null -REDIS_PORT=6379 -REDIS_DATABASE=0 +REDIS_HOST= +REDIS_PASSWORD= +REDIS_PORT= +REDIS_DB= USE_CRON_TRIGGER_CLEANUP=false LOG_FILE=/tmp/nexus.log -LOG_SPLIT=daily TIMEZONE=PRC diff --git a/admin/src/App.vue b/admin/src/App.vue index 641050ff..e609d62b 100644 --- a/admin/src/App.vue +++ b/admin/src/App.vue @@ -97,6 +97,7 @@ export default { next() } } + console.log('showMenu: ', !noMenu.includes(to.path)) state.showMenu = !noMenu.includes(to.path) state.currentPath = to.path document.title = pathMap[to.name] diff --git a/admin/src/components/Header.vue b/admin/src/components/Header.vue index 11bb13cf..d217e3c8 100644 --- a/admin/src/components/Header.vue +++ b/admin/src/components/Header.vue @@ -20,7 +20,7 @@

Username:{{ userInfo && userInfo.username || '' }}

-

Email:{{ userInfo && userInfo.email || '' }}

+

Class:{{ userInfo && userInfo.class_text || '' }}

Logout
@@ -67,7 +67,7 @@ export default { router.back() } router.afterEach((to) => { - // console.log("Head afterEach to", to) + console.log("Head afterEach to", to) const { id } = to.query state.name = pathMap[to.name] }) diff --git a/admin/src/utils/axios.js b/admin/src/utils/axios.js index ecc3cb36..c9a3485d 100644 --- a/admin/src/utils/axios.js +++ b/admin/src/utils/axios.js @@ -8,13 +8,14 @@ axios.defaults.withCredentials = true axios.defaults.headers['X-Requested-With'] = 'XMLHttpRequest' axios.defaults.headers['Content-Type'] = 'application/json' axios.defaults.headers['Accept'] = 'application/json' -axios.defaults.headers['Authorization'] = 'Bearer ' + localGet('token') +// axios.defaults.headers['Authorization'] = 'Bearer ' + localGet('token') -// axios.interceptors.request.use(config => { -// // console.log('before request', config) -// config.headers['Authorization'] = 'Bearer ' + localGet('token') -// return config -// }) +axios.interceptors.request.use(config => { + config.headers['Authorization'] = 'Bearer ' + localGet('token') + return config +}, error => { + return Promise.reject(error) +}) axios.interceptors.response.use(res => { console.log(res) diff --git a/admin/src/views/login.vue b/admin/src/views/login.vue index 048647c2..2a89c5af 100644 --- a/admin/src/views/login.vue +++ b/admin/src/views/login.vue @@ -57,11 +57,9 @@ export default { if (valid) { api.login(state.ruleForm).then(res => { console.log(res) - localSet('token', res.data.token) - router.push({name: 'dashboard'}) - // api.getUserBase().then(res => { - // localSet('userInfo', res.data) - // }) + localSet('token', res.data.token) + localSet('userInfo', res.data) + router.push({name: 'dashboard'}) }) } else { console.log('error submit!!') diff --git a/app/Http/Resources/UserResource.php b/app/Http/Resources/UserResource.php index cf7c9835..aa43a62f 100644 --- a/app/Http/Resources/UserResource.php +++ b/app/Http/Resources/UserResource.php @@ -29,7 +29,9 @@ class UserResource extends JsonResource 'downloaded_text' => mksize($this->downloaded), 'bonus' => $this->seedbonus, 'seedtime' => $this->seedtime, + 'seedtime_text' => mkprettytime($this->seedtime), 'leechtime' => $this->leechtime, + 'leechtime_text' => mkprettytime($this->leechtime), ]; } } diff --git a/app/Repositories/AuthenticateRepository.php b/app/Repositories/AuthenticateRepository.php index 5b0e59c0..4b3e8d30 100644 --- a/app/Repositories/AuthenticateRepository.php +++ b/app/Repositories/AuthenticateRepository.php @@ -1,6 +1,7 @@ where('username', $username) - ->firstOrFail(['id', 'secret', 'passhash']); - if (md5($user->secret . $password . $user->secret) != $user->passhash) { - throw new \InvalidArgumentException('username or password invalid'); + ->first(array_merge(User::$commonFields, ['secret', 'passhash'])); + if (!$user || md5($user->secret . $password . $user->secret) != $user->passhash) { + throw new \InvalidArgumentException('Username or password invalid.'); } - $token = DB::transaction(function () use ($user) { + $tokenName = __METHOD__ . __LINE__; + $token = DB::transaction(function () use ($user, $tokenName) { $user->tokens()->delete(); - $tokenResult = $user->createToken(__CLASS__ . __FUNCTION__ . __LINE__); + $tokenResult = $user->createToken($tokenName); return $tokenResult->plainTextToken; }); - $result = $user->toArray(); + $result = (new UserResource($user))->response()->getData(true)['data']; $result['token'] = $token; return $result; } diff --git a/bootstrap/app.php b/bootstrap/app.php index 195fbfd7..b4756cd0 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -1,11 +1,7 @@ nexus_env('USE_CRON_TRIGGER_CLEANUP', false), 'mysql' => [ - 'host' => nexus_env('MYSQL_HOST', '127.0.0.1'), - 'port' => nexus_env('MYSQL_PORT', 3306), - 'username' => nexus_env('MYSQL_USERNAME', 'root'), - 'password' => nexus_env('MYSQL_PASSWORD', ''), - 'database' => nexus_env('MYSQL_DATABASE', 'nexusphp'), + 'host' => nexus_env('DB_HOST', '127.0.0.1'), + 'port' => nexus_env('DB_PORT', 3306), + 'username' => nexus_env('DB_USERNAME', 'root'), + 'password' => nexus_env('DB_PASSWORD', ''), + 'database' => nexus_env('DB_DATABASE', 'nexusphp'), ], 'redis' => [ 'host' => nexus_env('REDIS_HOST', '127.0.0.1'), 'port' => nexus_env('REDIS_PORT', 6379), - 'database' => nexus_env('REDIS_DATABASE', 0), + 'database' => nexus_env('REDIS_DB', 0), ], ]; diff --git a/include/core.php b/include/core.php index f59b9705..32affd9d 100644 --- a/include/core.php +++ b/include/core.php @@ -7,7 +7,8 @@ define('ROOT_PATH', $rootpath); define('VERSION_NUMBER', '1.6.0'); define('CURRENT_SCRIPT', strstr(basename($_SERVER['SCRIPT_FILENAME']), '.', true)); define('IS_ANNOUNCE', CURRENT_SCRIPT == 'announce'); -define('REQUEST_ID', $_SERVER['HTTP_X_REQUEST_ID'] ?? $_SERVER['REQUEST_ID'] ?? intval(NEXUS_START * 10000)); +define('REQUEST_ID', $_SERVER['HTTP_X_REQUEST_ID'] ?? $_SERVER['REQUEST_ID'] ?? str_pad(str_replace('.', '', NEXUS_START), 14, "0", STR_PAD_RIGHT));; +require $rootpath . 'vendor/autoload.php'; if (!file_exists($rootpath . '.env')) { $installScriptRelativePath = 'install/install.php'; $installScriptFile = $rootpath . "public/$installScriptRelativePath"; @@ -15,7 +16,6 @@ if (!file_exists($rootpath . '.env')) { nexus_redirect($installScriptRelativePath); } } -require $rootpath . 'vendor/autoload.php'; require $rootpath . 'nexus/Database/helpers.php'; require $rootpath . 'classes/class_cache_redis.php'; require $rootpath . 'include/eloquent.php'; diff --git a/nexus/Install/Install.php b/nexus/Install/Install.php index 92fedb52..73a2aa53 100644 --- a/nexus/Install/Install.php +++ b/nexus/Install/Install.php @@ -20,9 +20,7 @@ class Install 'searchbox', 'secondicons', 'sources', 'standards', 'stylesheets', 'sysoppanel', 'teams', 'torrents_state', 'uploadspeed', 'agent_allowed_family', ]; - protected $envNames = ['MYSQL_HOST', 'MYSQL_PORT', 'MYSQL_USERNAME', 'MYSQL_PASSWORD', 'MYSQL_DATABASE', 'REDIS_HOST', 'REDIS_PORT', 'REDIS_DATABASE']; - - + protected $envNames = ['DB_HOST', 'DB_PORT', 'DB_USERNAME', 'DB_PASSWORD', 'DB_DATABASE', 'REDIS_HOST', 'REDIS_PORT', 'REDIS_DB']; public function __construct() { @@ -423,15 +421,15 @@ class Install } $this->doLog("[CREATE ENV] final newData: " . json_encode($newData)); unset($key, $value); - mysql_connect($newData['MYSQL_HOST'], $newData['MYSQL_USERNAME'], $newData['MYSQL_PASSWORD'], $newData['MYSQL_DATABASE'], $newData['MYSQL_PORT']); + mysql_connect($newData['DB_HOST'], $newData['DB_USERNAME'], $newData['DB_PASSWORD'], $newData['DB_DATABASE'], $newData['DB_PORT']); if (extension_loaded('redis') && !empty($newData['REDIS_HOST'])) { $redis = new \Redis(); $redis->connect($newData['REDIS_HOST'], $newData['REDIS_PORT'] ?: 6379); - if (isset($newData['REDIS_DATABASE'])) { - if (!ctype_digit($newData['REDIS_DATABASE']) || $newData['REDIS_DATABASE'] < 0 || $newData['REDIS_DATABASE'] > 15) { - throw new \InvalidArgumentException("invalid redis database: " . $newData['redis_database']); + if (isset($newData['REDIS_DB'])) { + if (!ctype_digit($newData['REDIS_DB']) || $newData['REDIS_DB'] < 0 || $newData['REDIS_DB'] > 15) { + throw new \InvalidArgumentException("invalid redis database: " . $newData['REDIS_DB']); } - $redis->select($newData['REDIS_DATABASE']); + $redis->select($newData['REDIS_DB']); } } $content = ""; @@ -502,8 +500,13 @@ class Install $sqlFile = ROOT_PATH . '_db/dbstructure_v1.6.sql'; } $string = file_get_contents($sqlFile); - $pattern = "/INSERT INTO `(\w+)` VALUES \(.*\);\n/i"; + if ($string === false) { + throw new \RuntimeException("can't not read dbstructure file: $sqlFile"); + } + //@todo test in php 7.3 + $pattern = "/INSERT INTO `(\w+)` VALUES \(.*\);/i"; preg_match_all($pattern, $string, $matches, PREG_SET_ORDER); + $this->doLog("[IMPORT DATA] matches count: " . count($matches)); foreach ($matches as $match) { $table = $match[1]; $sql = trim($match[0]); diff --git a/nexus/Install/install/install.php b/nexus/Install/install/install.php index b59a41ff..70c7d461 100644 --- a/nexus/Install/install/install.php +++ b/nexus/Install/install/install.php @@ -25,7 +25,8 @@ if ($currentStep == 1) { } if ($currentStep == 2) { - $envExampleFile = "$rootpath.env.example"; + $envExampleFile = $rootpath . ".env.example"; + $dbstructureFile = $rootpath . "_db/dbstructure_v1.6.sql"; $envExampleData = readEnvFile($envExampleFile); $envFormControls = $install->listEnvFormControls(); $newData = array_column($envFormControls, 'value', 'name'); @@ -41,11 +42,17 @@ if ($currentStep == 2) { } $tableRows = [ [ - 'label' => '.env.example', + 'label' => basename($envExampleFile), 'required' => 'exists && readable', 'current' => $envExampleFile, 'result' => $install->yesOrNo(file_exists($envExampleFile) && is_readable($envExampleFile)), ], + [ + 'label' => basename($dbstructureFile), + 'required' => 'exists && readable', + 'current' => $dbstructureFile, + 'result' => $install->yesOrNo(file_exists($dbstructureFile) && is_readable($dbstructureFile)), + ], ]; $fails = array_filter($tableRows, function ($value) {return $value['result'] == 'NO';}); $pass = empty($fails); diff --git a/nexus/Install/settings.default.php b/nexus/Install/settings.default.php index 672910b1..0cab93c0 100644 --- a/nexus/Install/settings.default.php +++ b/nexus/Install/settings.default.php @@ -354,8 +354,8 @@ 'code' => array ( 'mainversion' => 'NexusPHP', - 'subversion' => 'v1.6.0-beta4', - 'releasedate' => '2021-03-19', + 'subversion' => 'v1.6.0-beta5', + 'releasedate' => '2021-04-30', 'website' => 'https://nexusphp.org', ), );