public function getTplPath(\Baguette\Application $app) : string { $is_ketai = $app->getViewMode() == $app::VIEW_MODE_KETAI; $prefix = $app->getViewMode() . '/'; $suffix = $is_ketai ? '.tpl.xhtml' : '.tpl.html'; return $prefix . $this->tpl_name . $suffix; }
public function action(\Baguette\Application $app, \Teto\Routing\Action $action) { if ($app->session->get('user_id', ['default' => false])) { return new Response\RedirectResponse('/'); } if (!$app->isTokenVerified) { return new Response\RedirectResponse('/'); } // systemは特殊なユーザーなのでログインできない if (isset($_REQUEST['user'], $_REQUEST['password']) && $_REQUEST['user'] != 'system') { $user = trim($_REQUEST['user']); $pass = $_REQUEST['password']; $query = 'SELECT * FROM `users` WHERE `slug` = ?'; $stmt = db()->prepare($query); $stmt->execute([$user]); if ($login = $stmt->fetch(\PDO::FETCH_ASSOC)) { $query = 'SELECT `password` FROM `user_passwords` WHERE `user_id` = ?'; $stmt = db()->prepare($query); $stmt->execute([$login['id']]); $res = $stmt->fetch(\PDO::FETCH_ASSOC); if ($res && password($pass, $res['password']) === true) { $app->refreshSession(); $app->session->set('user_id', $login['id']); $app->session->set('user_slug', $login['slug']); $app->session->set('user_name', $login['name']); return new Response\RedirectResponse('/'); } } } return new Response\TemplateResponse('login.tpl.html', ['user' => isset($_REQUEST['user']) ? $_REQUEST['user'] : null]); }
function action(\Baguette\Application $app, \Teto\Routing\Action $action) { $is_daburi = self::isTyouhuku(isset($_REQUEST['slug']) ?? ''); if (!$is_daburi && isset($_REQUEST['slug'], $_REQUEST['name']) && self::regist($_REQUEST['slug'], $_REQUEST['name'], $app->getLoginUser())) { return new Response\RedirectResponse('/rooms/' . $_REQUEST['slug']); } return new Response\RedirectResponse('/'); }
function action(\Baguette\Application $app, \Teto\Routing\Action $action) { //setされていない時はすぐに返してよし //変数名もっとまともなのに変える。isOverlapRet? あとキャメルケースで統一したい。 $is_daburi = self::isTyouhuku(isset($_REQUEST['slug']) ?? ''); //条件と関数は分ける!registは必ずtrueがかえってくるので、if文の条件式ではなくif文内で行う if (!$is_daburi && isset($_REQUEST['slug'], $_REQUEST['name']) && self::regist($_REQUEST['slug'], $_REQUEST['name'], $app->getLoginUser())) { return new Response\RedirectResponse('/rooms/' . $_REQUEST['slug']); } return new Response\RedirectResponse('/'); }
function action(\Baguette\Application $app, \Teto\Routing\Action $action) { $slug = NULL; if (isset($_REQUEST['slug'])) { preg_match('/[-a-zA-Z0-9]+/', $_REQUEST['slug'], $matches); if (count($matches) > 0) { $slug = $matches[0]; } } $is_daburi = $slug === NULL || self::isTyouhuku($slug); if (!$is_daburi && isset($_REQUEST['slug'], $_REQUEST['name']) && $app->isTokenVerified && self::register($_REQUEST['slug'], $_REQUEST['name'], $app->getLoginUser())) { return new Response\RedirectResponse('/rooms/' . $_REQUEST['slug']); } return new Response\RedirectResponse('/'); }