Example #1
0
 /**
  * Retourne toutes les clés
  * 
  * @return array
  */
 public static function getInvites()
 {
     $oMysqli = Database::getInstance();
     $oResults = $oMysqli->query("SELECT i.*,p.login as parrain,f.login as filleul FROM tks_invites i \r\n                                        LEFT OUTER JOIN tks_users p\r\n                                        ON p.id = i.id_parrain \r\n                                        LEFT OUTER JOIN tks_users f \r\n                                        ON f.id = i.id_filleul");
     $aResults = array();
     while ($aResult = $oResults->fetch_assoc()) {
         $oInvite = new Invites($aResult['id_parrain'], $aResult['code'], $aResult['id_filleul']);
         $oInvite->setFilleulLogin($aResult['filleul']);
         $oInvite->setParrainLogin($aResult['parrain']);
         $aResults[] = $oInvite;
     }
     return $aResults;
 }
 /**
  * The function save new user in database
  */
 public function save()
 {
     if (!$this->isHasLogin($this->login)) {
         $invite = new Invites();
         if ($invite->inviteStatus($this->invite)) {
             $sql = 'INSERT INTO USERS (login, password, phone, id_city, invite) VALUES (?, ?, ?, ?, ?)';
             $statement = $this->connection->prepare($sql);
             $statement->execute(array($this->login, md5($this->password), $this->phone, $this->id_city, $this->invite));
             $invite->statusUpdate($this->invite);
         } else {
             echo json_encode(array('notice' => 'Ошибка: введенный инвайт-код зарегестрирован на другого пользователя'));
             return;
         }
         echo json_encode(array('notice' => 'Пользователь успешно добавлен!'));
         return;
     }
     echo json_encode(array('notice' => 'Ошибка: попытка добавления существующего пользователя'));
 }
Example #3
0
 public function procede()
 {
     try {
         if ($this->oRequest->existParam('code')) {
             if (!$this->oRequest->existParam('password')) {
                 throw new Error('Vous devez renseigner un password.', 1043);
             }
             if (!$this->oRequest->existParam('email')) {
                 throw new Error('Vous devez renseigner une adresse email.', 1043);
             }
             if (!$this->oRequest->existParam('login')) {
                 throw new Error('Vous devez renseigner un nom d\'utilisateur.', 1043);
             }
             $oInvite = new Invites(0, $this->oRequest->getParam('code', 'string'));
             if (!$oInvite->checkInvite()) {
                 throw new Error('Votre code d\'invitation n\'est pas valide.', 1043);
             }
             $sPassword = $this->oRequest->getParam('password', 'string');
             $sConfirmation = $this->oRequest->getParam('confirmation', 'string');
             if ($sPassword != $sConfirmation) {
                 throw new Error("Le password et la confirmation ne correspondent pas.", 1043);
             }
             $sPassword = User::cryptPassword($sPassword);
             $oUser = new User(0, $this->oRequest->getParam('login', 'string'), $sPassword, $this->oRequest->getParam('email', 'string'), md5(time() * rand()));
             $oUser->store();
             //On demande au modèle de vérifier l'identification
             $this->oCurrentUser->loadFromFormular($this->oRequest->getParam('login', 'string'), $this->oRequest->getParam('password', 'string'), false);
             $oInvite->usedBy($this->oCurrentUser->getId());
             Logger::log('admin', $this->oCurrentUser->getLogin() . ' a rejoint le site avec le code : ' . $this->oRequest->getParam('code', 'string'));
             $this->oView->addAlert("Redirection en cours ...", 'success');
             header("Location: http://" . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\') . "/index.php");
         }
     } catch (Error $e) {
         $this->oView->addAlert($e, 'danger');
     } finally {
         $this->oView->Create();
     }
 }
Example #4
0
    public function register($data)
    {
        $db = new Database();
        $db->update('JudgeInvitations', array('Replied' => date('Y-m-d H:i:s'), 'Response' => 1), "id ='" . $data->id . "'");
        $res = $db->getResult();
        if ($res[0] !== 1) {
            return "Invalid invitation link.";
        }
        $db->insert('Judges', array('Title' => $data->Title, 'Affiliation' => $data->Affiliation));
        $res = $db->getResult();
        $id = $res[0];
        foreach ($data->Conflicts as $studentId) {
            $db->insert('JudgeStudentConflicts', array('JudgeId' => $id, 'StudentId' => $studentId));
        }
        $db->select('Settings', 'StudentsPerJudge,Subject,Date,Time,Location');
        $res = $db->getResult();
        $maxStudents = $res['StudentsPerJudge'];
        $db->sql('insert into JudgeStudentGrade (JudgeId, StudentId)
                select ' . $id . ' as JudgeId, s.id as StudentId
                from Students as s
                left outer join JudgeStudentGrade as g on g.StudentId = s.id
                where s.id not in (select StudentId from JudgeStudentConflicts where JudgeId = ' . $id . ')
                group by s.id
                order by count(g.JudgeId), rand()
                limit ' . $maxStudents);
        $db->select('Users', 'Email,FirstName,LastName,StudentId,JudgeId,Roles,DefaultRole', null, "Email ='" . $data->Email . "'");
        $studentUser = $db->getResult();
        if (count($studentUser) > 0) {
            $newRoles = "";
            $defaultRole = "judge";
            if ($studentUser['Roles'] == "admin;student") {
                $newRoles = "admin;judge;student";
            } else {
                if ($studentUser['Roles'] == "student") {
                    $newRoles = "judge;student";
                } else {
                    if ($studentUser['Roles'] == "") {
                        $newRoles = "judge";
                    }
                }
            }
            $success = $db->update('Users', array('Roles' => $newRoles), "Email ='" . $data->Email . "';");
            if (!$success) {
                return "Roles update failed";
            }
            $success = $db->update('Users', array('DefaultRole' => $defaultRole), "Email ='" . $data->Email . "';");
            if (!$success) {
                return "Default update failed";
            }
            $success = $db->sql("UPDATE Users SET Password=password('" . $data->Password . "') WHERE Email ='" . $data->Email . "';");
            // and Password=NULL;");
            if (!$success) {
                return "Password update failed";
            }
            $success = $db->update('Users', array('JudgeId' => ".{$id}."), "Email ='" . $data->Email . "';");
            if (!$success) {
                return "ID update failed";
            }
        } else {
            $db->sql("insert into Users (Email, FirstName, LastName, Password, JudgeId, Roles, DefaultRole) VALUES ('" . $data->Email . "', '" . $data->FirstName . "', '" . $data->LastName . "', password('" . $data->Password . "'), " . $id . ", 'judge', 'judge');");
        }
        $date = date_format(DateTime::createFromFormat('Y-m-d', $res['Date']), "l, F j");
        $sent = mail($data->Email, 'Confirmation: ' . $res['Subject'], '<html>
<body>
    <div style="width: 600px; border: 2px solid #E9EBF6; margin: auto; font-size: 16px; color: #555555;">
        <h1 style="margin: 0; padding: 8px; background-color: #E9EBF6; text-align: center;">
            Dear ' . $data->FirstName . ' ' . $data->LastName . ',
        </h1>
        <div style="overflow: hidden; padding: 8px; padding-top: 0; background-color: #F5F6FB;">
            <p>We are pleased to confirm your participation in the FIU Computer Science Senior Project Event!</p>
			<p>The day of the event will be ' . $date . ' ' . $res['Time'] . ' at ' . $res['Location'] . '.<br /> You will be able to login on this <a href="' . Invites::getRSVPUrl() . '">Web Application</a> with the following credentials:</p>
			<p>Username: '******' <br />Password: '******' <p>
			<p>Keep this information safe for the day of the event.</p>
            <br />
            <p>Sincerely,</p>
            <p>Masoud Sadjadi</p>
        </div>
    </div>
</body>
</html>', "From: Masoud Sadjadi <*****@*****.**>\r\nMIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\n");
        return $sent;
    }
<?php

include_once '../src/models/Invites.class.php';
include_once '../src/util/DatabaseConnector.class.php';
$invites = new Invites(null);
?>

<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <title>Инвайты</title>
    <link rel="icon" type="public/image/gif" href="./images/ajb.gif">
    <link href="css/registration.css" rel="stylesheet">
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="back">
    <a href="../index.php"><img src="images/back-min.png"></a>
</div>
<div align="center">
    <img id="invites-page" src="images/invites.png">

    <div id="users">
        <h1><strong>Инвайт коды</strong></h1>
    </div>
    <table id="table" border="solid 1px">
        <tr>
            <td><h4>&nbsp&nbspИнвайт код&nbsp&nbsp</h4></td>
            <td><h4>&nbsp&nbspСтатус&nbsp&nbsp</h4></td>
            <td><h4>Дата</h4></td>
    $res = $db->getResult();
    if (count($res) == 0) {
        http_response_code(404);
    } else {
        if ($res['Response'] == null) {
            switch ($_GET['rsvp']) {
                case 'accept':
                    header('Location: ' . Invites::getRSVPUrl() . '#/rsvp=' . $id);
                    break;
                case 'decline':
                    $db->update('JudgeInvitations', array('Replied' => date('Y-m-d H:i:s'), 'Response' => 0), "id ='" . $id . "'");
                    $res = $db->getResult();
                    if ($res[0] == 1) {
                        echo "You have successfully declined the invitation";
                    } else {
                        http_response_code(404);
                    }
                    break;
                default:
                    $body = Invites::getEmailBody($id);
                    if ($body == '') {
                        http_response_code(404);
                    } else {
                        echo $body;
                    }
            }
        } else {
            echo 'You already ' . ($res['Response'] == "1" ? 'accepted' : 'declined') . ' the invitation on ' . date_format(DateTime::createFromFormat('Y-m-d H:i:s', $res['Replied']), "l, F jS Y h:i:s A");
        }
    }
}
Example #7
0
 /**
  * Supprime l'invitation de la BDD
  */
 private function delete()
 {
     $oInvite = new Invites(0, $this->oRequest->getParam('edit', 'string'));
     $oInvite->delete();
     Logger::log('admin', 'Une invitation a été supprimée par ' . $this->oCurrentUser->getLogin());
     $this->oView->addAlert('L\'invitation a été supprimée.', 'success');
 }