예제 #1
0
 public function login()
 {
     if (isset($_POST['username'], $_POST['password'])) {
         try {
             htmlspecialchars($user = $_POST['username']);
             htmlspecialchars($pass = $_POST['password']);
             if (User::tryLog($user, $pass)) {
                 $_SESSION['id'] = User::getUser($user)[0];
                 $nests = Nest::getUserNests($_SESSION['id']);
                 if (empty($_SESSION['nestid'])) {
                     $_SESSION['nestid'] = $nests[0];
                 }
                 header("Location: /MVCProject/home/home");
                 exit;
             } else {
                 throw new \Exception('Wrong Username or Password');
             }
         } catch (Exception $e) {
             echo $e->getMessage();
         }
     }
     $model = new UserRegisterViewModel();
     return new View($model);
 }