protected function postProcess() { try { $this->_validate(); } catch (\MyApp\Exception\EmptyPost $e) { $this->setErrors('login', $e->getMessage()); } $this->setValues('club', $_POST['club']); if ($this->hasError()) { return; } else { try { $userModel = new \MyApp\Model\User(); $user = $userModel->login(['club' => $_POST['club'], 'password' => $_POST['password']]); } catch (\MyApp\Exception\UnmatchEmailOrPassword $e) { $this->setErrors('login', $e->getMessage()); return; } // login処理 session_regenerate_id(true); $_SESSION['me'] = $user; // redirect to home header('Location: ' . SITE_URL); exit; } }
protected function postProcess() { //validate try { $this->_validate(); } catch (\MyApp\Exception\InvalidEmail $e) { //echo $e->getMessage(); //exit; $this->setErrors('email', $e->getMessage()); } catch (\MyApp\Exception\InvalidPassword $e) { //echo $e->getMessage(); // exit; $this->setErrors('password', $e->getMessage()); } //echo "success"; //exit; $this->setValues('email', $_POST['email']); if ($this->hasError()) { return; } else { // create user try { $userModel = new \MyApp\Model\User(); $userModel->create(['club' => $_POST['club'], 'email' => $_POST['email'], 'password' => $_POST['password']]); } catch (\MyApp\Exception\DuplicateEmail $e) { $this->setErrors('email', $e->getMessage()); return; } //redirect to login header('Location:' . SITE_URL . '/login.php'); exit; } }
public function run() { if (!$this->isLoggedIn()) { //login header('Location: ' . SITE_URL . '/login.php'); exit; } //get users info $userModel = new \MyApp\Model\User(); $this->setValues('users', $userModel->findAll()); }
public function run() { if (!$this->isLoggedIn()) { // login header('login.php'); exit; } // get users info $userModel = new \MyApp\Model\User(); $this->setValues('users', $userModel->findAll()); try { //connect $db = new PDO(PDO_DSN, DB_USERNAME, DB_PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //スレッド取得 $sql = $db->query("select * from threads order by created_at desc"); $result = $sql->FETCHAll(PDO::FETCH_CLASS); foreach ($result as $thread) { $thread->show(); echo "<tr><td><a href=thread.php?id= {$this->id}>"; echo "{$this->title}</a></td>"; echo "<td>{$this->created_at}</td></tr><br>"; echo "<td><a href='thread_del.php?id={$id}'>削除</a></td>"; } //disconnect //$db = null; //データ更新 $type = isset($_POST['type']) ? $_POST['type'] : null; if ($type == 'create') { $sql_thread = $db->prepare("update thread set title = :title body = :body name = :name created_at = now()"); $sql_thread->bindValue(':title', $_POST['title'], PDO::PARAM_STR); $sql_thread->bindValue(':body', $_POST['body'], PDO::PARAM_STR); $sql_thread->execute(); } } catch (PDOException $e) { echo $e->getMessage(); exit; } }