Beispiel #1
0
 public function login()
 {
     extract($_REQUEST);
     $data = DB::query("select * from users \n\t\t\twhere email = '" . $email . "' and pass = '******' \n\t\t\tor username = '******' and pass = '******'", 1);
     DB::write('update users set lastlogin_ts = ' . time() . ' where id = ' . $data['id']);
     $json = 0;
     if ($data) {
         $json = 1;
         AuthController::add_session($data);
     }
     return array('result' => $json);
 }
 public function index($instanceId)
 {
     $user = AuthController::auth();
     $scoreRepo = new ScoreRepository();
     $scores = $scoreRepo->getScoreByInstanceId($instanceId);
     $instanceRepo = new InstanceRepository();
     $instance = $instanceRepo->get($instanceId);
     usort($scores, function ($a, $b) {
         if ($a->score == $b->score) {
             return 0;
         }
         return $a->score < $b->score ? 1 : -1;
     });
     $this->view('score.php', ['user' => $user, 'scores' => $scores, 'instance' => $instance]);
 }
 public function upsert()
 {
     $user = AuthController::auth();
     if ($this->isValid($_POST)) {
         $instanceRepo = new InstanceRepository();
         $pdo = Connection::connect();
         $pdo->beginTransaction();
         try {
             if ($_POST['id'] != "") {
                 $instance = $instanceRepo->get($_POST['id']);
                 $instance->name = $_POST['name'];
                 $instance->description = $_POST['description'];
                 $instanceRepo->update($instance);
                 $_SESSION['success'] = ['Successfully update an instance.'];
             } else {
                 $instance = new Instance();
                 $instance->id = $this->generateId();
                 $instance->password = $this->generatePassword();
                 $instance->userId = $user->id;
                 $instance->name = $_POST['name'];
                 $instance->description = $_POST['description'];
                 $instanceRepo->insert($instance);
                 $_SESSION['success'] = ['Successfully add an instance.'];
             }
             $pdo->commit();
         } catch (\Exception $e) {
             $pdo->rollBack();
             unset($_SESSION['success']);
         }
         header('Location: /');
     } else {
         if ($_POST['id'] != "") {
             header('Location: /instance/edit?id=' . $_POST['id']);
         } else {
             header('Location: /instance/edit');
         }
     }
 }