Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
refactor(View): Change template system
Browse files Browse the repository at this point in the history
First step to change Template System from Twig to Plates,
With frontend ui framework change from bootstrap to layui

BREAKING CHANGE: frontend framework and backend driver change
  • Loading branch information
Rhilip committed Mar 8, 2019
1 parent d644d0b commit ae2a7b7
Show file tree
Hide file tree
Showing 68 changed files with 1,557 additions and 1,795 deletions.
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,4 @@ So that tracker can record the peer's ip address.
| MAILER_FROM | String | The from address of this message. |
| ~~MAILER_FROM_NICKNAME~~ | String | Not use now. |

## Copyright

### This project

Apache License 2.0

### our dependency

- [MixPHP](https://github.com/mix-php/mix-framework) : Apache License 2.0
- [Symfony Components](https://symfony.com/) , Like [twig](https://twig.symfony.com), [swiftmailer](https://swiftmailer.symfony.com) : MIT
- [sandfoxme/bencode](https://github.com/sandfoxme/bencode) : MIT
- [RobThree/TwoFactorAuth](https://github.com/RobThree/TwoFactorAuth) : MIT

48 changes: 25 additions & 23 deletions apps/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AdminController extends Controller
{
public function actionIndex()
{
return $this->render('admin/index.html.twig');
return $this->render('admin/index');
}

public function actionService()
Expand All @@ -27,7 +27,7 @@ public function actionService()
case 'redis':
return $this->infoRedis();
default:
return $this->render('errors/action_fail.html.twig', ['title' => 'Not Support Action', 'msg' => 'not support']);
return $this->render('errors/action_fail', ['title' => 'Not Support Action', 'msg' => 'not support']);
}
}

Expand All @@ -36,6 +36,9 @@ private function infoRedis()
$panel = app()->request->get('panel', 'status');

if ($panel === 'keys') {
$offset = app()->request->get('offset', 0);
$perpage = app()->request->get('perpage', 50);

if (app()->request->isPost()) {
$action = app()->request->post('action');
if ($action == 'delkey') {
Expand All @@ -46,57 +49,56 @@ private function infoRedis()
app()->redis->del(app()->redis->keys($pattern));
}
}

$render_data = [];
$dbsize = app()->redis->dbSize();
$pattern = app()->request->get('pattern');
if ($pattern) {
$offset = app()->request->get('offset', 0);
$perpage = app()->request->get('perpage', 50);

$render_data = [
'dbsize' => $dbsize,
'offset' => $offset,
'perpage' => $perpage,
];

if ($pattern) {
$keys = app()->redis->keys($pattern);
sort($keys);
$limited_keys = array_slice($keys, $offset * $perpage, $perpage);

$types = [];
foreach ($limited_keys as $key) {
$types[$key] = app()->redis->typeof($key);
$types[$key] = app()->redis->type($key);
}

$dbsize = app()->redis->dbSize();
$render_data = [
'offset' => $offset,
'perpage' => $perpage,
$render_data = $render_data + [
'pattern' => $pattern,
'keys' => $limited_keys,
'types' => $types,
'num_keys' => count($keys),
'dbsize' => $dbsize
];
}
return $this->render('admin/redis_keys.html.twig', $render_data);
return $this->render('admin/redis_keys', $render_data);
} elseif ($panel === 'key') {
$key = app()->request->get('key');
$dump = app()->redis->dump($key);
if ($dump === false) {
return app()->response->setStatusCode(404);
}
$size = strlen($dump);
$t = app()->redis->typeof($key);
$t = app()->redis->type($key);
$ttl = app()->redis->ttl($key);
if ($t == 'String') {
if ($t == \Redis::REDIS_STRING) {
$val = app()->redis->get($key);
} elseif ($t == 'List') {
} elseif ($t == \Redis::REDIS_LIST) {
$val = app()->redis->lRange($key, 0, -1);
} elseif ($t == 'Hash') {
} elseif ($t == \Redis::REDIS_HASH) {
$val = app()->redis->hGetAll($key);
} elseif ($t == 'Set') {
} elseif ($t == \Redis::REDIS_SET) {
$val = app()->redis->sMembers($key);
} elseif ($t == 'Sorted Set') {
} elseif ($t == \Redis::REDIS_ZSET) {
$val = app()->redis->zRange($key, 0, -1, true);
} else {
$val = '';
}
return $this->render('admin/redis_key.html.twig', [
return $this->render('admin/redis_key', [
'key' => $key,
'value' => $val,
'type' => $t,
Expand All @@ -114,7 +116,7 @@ private function infoRedis()
return $m;
}, $cmdstat_raw);

return $this->render('admin/redis_status.html.twig', ['info' => $info, 'dbsize' => $dbsize, 'cmdstat' => $cmdstat]);
return $this->render('admin/redis_status', ['info' => $info, 'dbsize' => $dbsize, 'cmdstat' => $cmdstat]);
}
}

Expand All @@ -134,7 +136,7 @@ private function infoMysql()
}
}

return $this->render('admin/mysql_status.html.twig', [
return $this->render('admin/mysql_status', [
'serverStatus' => $serverStatus,
'startAt' => $startAt,
'queryStats' => $queryStats,
Expand Down
22 changes: 11 additions & 11 deletions apps/controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ public function actionRegister()
$user->importAttributes(app()->request->post());
$error = $user->validate();
if (count($error) > 0) {
return $this->render("errors/action_fail.html.twig", [
return $this->render('errors/action_fail', [
'title' => 'Register Failed',
'msg' => $error->get(0)
]);
} else {
$user->flush(); // Save this user in our database and do clean work~

if ($user->status == User::STATUS_CONFIRMED) {
return app()->response->redirect("/index");
return app()->response->redirect('/index');
} else {
return $this->render('auth/register_pending.html.twig', [
"confirm_way" => $user->confirm_way,
"email" => $user->email
return $this->render('auth/register_pending', [
'confirm_way' => $user->confirm_way,
'email' => $user->email
]);
}
}
} else {
return $this->render("auth/register.html.twig");
return $this->render('auth/register');
}
}

Expand All @@ -53,13 +53,13 @@ public function actionConfirm()
$confirm->importAttributes(app()->request->get());
$error = $confirm->validate();
if (count($error) > 0) {
return $this->render("errors/action_fail.html.twig", [
return $this->render('errors/action_fail', [
'title' => 'Confirm Failed',
'msg' => $error->get(0)
]);
} else {
$confirm->flush();
return $this->render('auth/confirm_success.html.twig');
return $this->render('auth/confirm_success');
}
}

Expand All @@ -80,7 +80,7 @@ public function actionLogin()

if (count($error) > 0) {
$login->LoginFail();
return $this->render("auth/login.html.twig", [
return $this->render('auth/login', [
"username" => $login->username,
"error_msg" => $error->get(0),
'left_attempts' => $left_attempts
Expand All @@ -92,11 +92,11 @@ public function actionLogin()
$return_to = app()->session->pop('login_return_to') ?? '/index';
return app()->response->redirect($return_to);
} else {
return $this->render('errors/action_fail.html.twig', ['title' => 'Login Failed', 'msg' => 'Reach the limit of Max User Session.']);
return $this->render('errors/action_fail', ['title' => 'Login Failed', 'msg' => 'Reach the limit of Max User Session.']);
}
}
} else {
return $this->render("auth/login.html.twig", ['left_attempts' => $left_attempts]);
return $this->render('auth/login', ['left_attempts' => $left_attempts]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ class IndexController extends Controller
// 默认动作
public function actionIndex()
{
return $this->render("index.html.twig");
return $this->render('index');
}
}
26 changes: 13 additions & 13 deletions apps/controllers/TorrentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class TorrentsController extends Controller
public function actionIndex()
{
// TODO add pagination support
$fetch = app()->pdo->createCommand("SELECT `id` FROM torrents ORDER BY added_at DESC LIMIT 50;")->queryAll();
$fetch = app()->pdo->createCommand('SELECT `id` FROM torrents ORDER BY added_at DESC LIMIT 50;')->queryAll();

$torrents = array_map(function ($id) {
return new Torrent($id);
}, $fetch);

return $this->render("torrents/list.html.twig", [
"torrents" => $torrents
return $this->render('torrents/list', [
'torrents' => $torrents
]);

}
Expand All @@ -41,20 +41,20 @@ public function actionUpload()
$torrent->importFileAttributes(app()->request->files());
$error = $torrent->validate();
if (count($error) > 0) {
return $this->render("errors/action_fail.html.twig", ['title' => 'Upload Failed', 'msg' => $torrent->getError()]);
return $this->render('errors/action_fail', ['title' => 'Upload Failed', 'msg' => $torrent->getError()]);
} else {
try {
$torrent->flush();
} catch (\Exception $e) {
return $this->render("errors/action_fail.html.twig", ['title' => 'Upload Failed', 'msg' => $e->getMessage()]);
return $this->render('errors/action_fail', ['title' => 'Upload Failed', 'msg' => $e->getMessage()]);
}

return app()->response->redirect("/torrents/details?id=" . $torrent->id);
return app()->response->redirect('/torrents/details?id=' . $torrent->id);
}

} else {
// TODO Check user can upload
return $this->render("torrents/upload.html.twig");
return $this->render('torrents/upload');
}

}
Expand All @@ -70,21 +70,21 @@ public function actionDetails()

$torrent = new Torrent($tid);

return $this->render("torrents/details.html.twig", ["torrent" => $torrent]);
return $this->render('torrents/details', ['torrent' => $torrent]);
}

public function actionDownload()
{
$tid = app()->request->get('id');

$torrent = new Torrent($tid); // If torrent is not exist or can't visit , a notfound exception will throw out........
$filename = "[" . app()->config->get("base.site_name") . "]" . $torrent->getTorrentName() . ".torrent";
$filename = '[' . app()->config->get('base.site_name') . ']' . $torrent->getTorrentName() . '.torrent';

app()->response->setHeader("Content-Type", "application/x-bittorrent");
if (strpos(app()->request->header("user-agent"), "IE")) {
app()->response->setHeader("Content-Disposition", "attachment; filename=" . str_replace("+", "%20", rawurlencode($filename)));
app()->response->setHeader('Content-Type', 'application/x-bittorrent');
if (strpos(app()->request->header('user-agent'), 'IE')) {
app()->response->setHeader('Content-Disposition', 'attachment; filename=' . str_replace('+', '%20', rawurlencode($filename)));
} else {
app()->response->setHeader("Content-Disposition", "attachment; filename=\"$filename\" ; charset=utf-8");
app()->response->setHeader('Content-Disposition', "attachment; filename=\"$filename\" ; charset=utf-8");
}

return $torrent->getDownloadDict(true);
Expand Down
10 changes: 5 additions & 5 deletions apps/controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function actionIndex()

public function actionSetting()
{
return $this->render('user/setting.html.twig');
return $this->render('user/setting');
}

public function actionPanel()
Expand All @@ -32,7 +32,7 @@ public function actionPanel()
} else {
$user = app()->user;
}
return $this->render('user/panel.html.twig', ['user' => $user]);
return $this->render('user/panel', ['user' => $user]);
}

public function actionSessions()
Expand All @@ -51,14 +51,14 @@ public function actionSessions()
if ($success > 0) {
app()->redis->zRem(app()->user->sessionSaveKey, $to_del_session);
} else {
return $this->render('errors/action_fail.html.twig', ['title' => 'Remove Session Failed', 'msg' => 'Remove Session Failed']);
return $this->render('errors/action_fail', ['title' => 'Remove Session Failed', 'msg' => 'Remove Session Failed']);
}
}
}

$sessions = app()->pdo->createCommand('SELECT sid,login_at,INET6_NTOA(login_ip) as login_ip,user_agent,last_access_at FROM users_session_log WHERE uid=:uid and expired=0')->bindParams([
$sessions = app()->pdo->createCommand('SELECT sid,login_at,login_ip,user_agent,last_access_at FROM users_session_log WHERE uid = :uid and expired = 0')->bindParams([
'uid' => app()->user->getId()
])->queryAll();
return $this->render('user/sessions.html.twig', ['sessions' => $sessions]);
return $this->render('user/sessions', ['sessions' => $sessions]);
}
}
2 changes: 1 addition & 1 deletion apps/models/form/UserRegisterForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public function flush()
])->execute();
$confirm_url = app()->request->root() . '/auth/confirm?secret=' . urlencode($confirm_key);

$mail_sender = \Rid\Libraries\Mailer::newInstanceByConfig('library.[swiftmailer]');
$mail_sender = \Rid\Libraries\Mailer::newInstanceByConfig('libraries.[swiftmailer]');
$mail_sender->send([$this->email], 'Please confirm your accent', "Click this link $confirm_url to confirm.");
}

Expand Down
Binary file modified apps/public/favicon.ico
Binary file not shown.
Loading

0 comments on commit ae2a7b7

Please sign in to comment.