Пример #1
0
 public function runTask()
 {
     $user = filter_input(INPUT_POST, 'user');
     $pass = filter_input(INPUT_POST, 'pass');
     try {
         if (!UserController::processLogin($user, $pass)) {
             $this->failure("Login failed");
         }
         $usermanager = new SQLUserManager();
         $new_user_id = $usermanager->createUser();
         $_SESSION['user_id'] = $new_user_id;
         $this->success();
     } catch (Exception $e) {
         $err_msg = "Operation failed: Error code " . $e->getCode();
         //Code 0 means that this is none-system error.
         //In this case we should be able to display the message text itself.
         if ($e->getCode() == 0) {
             $err_msg = "Operation failed: " . $e->getMessage();
         }
         $this->failure($err_msg);
     }
 }
Пример #2
0
session_start();
$router = new Router();
if (!isset($_SESSION['user_id'])) {
    $url = $router->getDestination('login');
    header('Location: ' . $url . '?src=explain');
    exit;
}
$length = 5;
$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
    $randomString .= $characters[rand(0, $charactersLength - 1)];
}
$score = $_SESSION['score'];
$user_id = $_SESSION['user_id'];
$bonus = $score * 0.05;
$error_msg = "";
$info = new GameCompInfo($user_id, $randomString, $score);
try {
    $user_manager = new SQLUserManager();
    $user_manager->updateCompInfo($info);
} catch (\Exception $ex) {
    $error_msg = "ERROR USER:{$user_id}:SCORE:{$score}:STRING:{$randomString}:BONUS:{$bonus}";
}
$page_cont = array('comp_code' => $info->comp_code, 'score' => $info->score, 'bonus' => $bonus, 'error' => $error_msg);
session_unset();
session_destroy();
$view = new View(__DIR__ . '/u311/carexperiment/resources/templates/');
$view->loadTemplate('debriefing.twig');
echo $view->render($page_cont);