fix installation for beta5

This commit is contained in:
xiaomlove
2021-04-30 15:10:31 +08:00
parent 654419deec
commit 3737d684ee
14 changed files with 71 additions and 65 deletions

View File

@@ -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

View File

@@ -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]

View File

@@ -20,7 +20,7 @@
</template>
<div class="nickname">
<p>Username{{ userInfo && userInfo.username || '' }}</p>
<p>Email{{ userInfo && userInfo.email || '' }}</p>
<p>Class{{ userInfo && userInfo.class_text || '' }}</p>
<el-tag size="small" effect="dark" class="logout" @click="logout">Logout</el-tag>
</div>
</el-popover>
@@ -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]
})

View File

@@ -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)

View File

@@ -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!!')

View File

@@ -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),
];
}
}

View File

@@ -1,6 +1,7 @@
<?php
namespace App\Repositories;
use App\Http\Resources\UserResource;
use App\Models\User;
use Illuminate\Support\Facades\DB;
@@ -10,16 +11,17 @@ class AuthenticateRepository extends BaseRepository
{
$user = User::query()
->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;
}

View File

@@ -1,11 +1,7 @@
<?php
if (!empty($_SERVER['HTTP_X_REQUEST_ID'])) {
define('REQUEST_ID', $_SERVER['HTTP_X_REQUEST_ID']);
} else {
$requestId = str_replace('.', '', LARAVEL_START);
define('REQUEST_ID', str_pad($requestId, 14, "0", STR_PAD_RIGHT));
}
define('REQUEST_ID', $_SERVER['HTTP_X_REQUEST_ID'] ?? $_SERVER['REQUEST_ID'] ?? str_pad(str_replace('.', '', LARAVEL_START), 14, "0", STR_PAD_RIGHT));
define('IN_NEXUS', false);
/*

14
composer.lock generated
View File

@@ -987,16 +987,16 @@
},
{
"name": "laravel/framework",
"version": "v8.35.1",
"version": "v8.40.0",
"source": {
"type": "git",
"url": "https://github.com/laravel/framework.git",
"reference": "d118c0df39e7524131176aaf76493eae63a8a602"
"reference": "a654897ad7f97aea9d7ef292803939798c4a02a4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/d118c0df39e7524131176aaf76493eae63a8a602",
"reference": "d118c0df39e7524131176aaf76493eae63a8a602",
"url": "https://api.github.com/repos/laravel/framework/zipball/a654897ad7f97aea9d7ef292803939798c4a02a4",
"reference": "a654897ad7f97aea9d7ef292803939798c4a02a4",
"shasum": "",
"mirrors": [
{
@@ -1153,7 +1153,11 @@
"framework",
"laravel"
],
"time": "2021-03-30T21:34:17+00:00"
"support": {
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"time": "2021-04-28T14:38:56+00:00"
},
{
"name": "laravel/sanctum",

View File

@@ -11,17 +11,17 @@ return [
'use_cron_trigger_cleanup' => 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),
],
];

View File

@@ -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';

View File

@@ -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]);

View File

@@ -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);

View File

@@ -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' => '<a href="https://nexusphp.org" target="_blank">https://nexusphp.org</a>',
),
);