Example #1
0
<?php

namespace Gallery;

use Gallery\Views\Page;
use Gallery\Database\DB;
use Gallery\Utilities\UserState;
use Gallery\Utilities\Redirect;
$r = new Redirect();
$db = new DB();
if ($db->checkUser($_POST['login'], $_POST['password'])) {
    $state = new UserState();
    $state->setState("authorized", $_POST['login']);
    $r->with();
} else {
    $r->with(['msg' => "Неправильное имя пользователя или пароль."]);
}
Example #2
0
<?php

namespace Gallery;

use Gallery\Database\DB;
use Gallery\Utilities\UserState;
use Gallery\Utilities\Parameters;
use Gallery\Utilities\Redirect;
$r = new Redirect();
$state = new UserState();
if ($state->isState('authorized')) {
    $login = $state->getState('authorized');
    $db = new DB();
    $images = $db->getImagesByUser($login);
    $db->deleteUser($login);
    $param = new Parameters();
    $path = $param->imagesPath . $login;
    foreach ($images as $img) {
        unlink($path . DIRECTORY_SEPARATOR . $img . '.jpg');
        unlink($path . DIRECTORY_SEPARATOR . $img . $param->previewSuffix . '.jpg');
    }
    rmdir($path);
    $state->unsetState('authorized');
    $r->with(['msg' => "Аккаунт удален."]);
} else {
    Redirect::toRoot();
}
Example #3
0
<?php

namespace Gallery;

use Gallery\Utilities\UserState;
use Gallery\Utilities\Redirect;
$state = new UserState();
$state->unsetState('authorized');
Redirect::toRoot();
Example #4
0
 } else {
     if ($db->checkEMail($email)) {
         $r->with(['msg' => "EMail занят."]);
     } else {
         if (strlen($pswd) < 6) {
             $r->with(['msg' => "Пароль не должен быть меньше 6 символов."]);
         } else {
             if (preg_match('([^a-zA-Z0-9_])', $pswd)) {
                 $r->with(['msg' => "Пароль может содержать только латинские буквы, цифры\r\n            и символ подчеркивания."]);
             } else {
                 if ($pswd !== $pswd2) {
                     $r->with(['msg' => "Пароли не совпадают."]);
                 } else {
                     // данные корректны, отправляем письмо для проверка email:
                     $tag = md5($email + time());
                     $state = new UserState();
                     $state->setState("verifyMailTag", $tag);
                     $state->setState("login", $login);
                     $state->setState("email", $email);
                     $state->setState("password", password_hash($pswd, PASSWORD_DEFAULT));
                     $subject = 'Подтверждение регистрации';
                     $param = new Parameters();
                     $link = $param->hostname . "/verifymail.php?tag={$tag}";
                     $message = "<html>\r\n    <head>\r\n      <title>Подтверждение регистрации</title>\r\n    </head>\r\n    <body>\r\n      Для подтверждения регистрации в галерее картинок пройдите по ссылке:<br>\r\n      <a href={$link}>{$link}</a>\r\n    </body>\r\n    </html>\r\n    ";
                     $headers = 'MIME-Version: 1.0' . "\r\n";
                     $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
                     mail($email, $subject, $message, $headers);
                     $r = new Redirect('verifymail');
                     $r->with(['email' => $email]);
                 }
             }
Example #5
0
<?php

namespace Gallery;

use Gallery\Views\Page;
use Gallery\Data\SimpleData as Data;
use Gallery\Utilities\UserState;
use Gallery\Utilities\Redirect;
use Gallery\Database\DB;
use Gallery\Utilities\Parameters;
$state = new UserState();
if ($state->isState('verifyMailTag')) {
    $tag = isset($_GET['tag']) ? $_GET['tag'] : "";
    if ($state->getState('verifyMailTag') === $_GET['tag']) {
        $login = $state->getState("login");
        $email = $state->getState("email");
        $pswd = $state->getState("password");
        $db = new DB();
        $db->addUser($login, $email, $pswd);
        $param = new Parameters();
        mkdir($param->imagesPath . $login);
        $state->setState("authorized", $login);
        $state->unsetState("verifyMailTag");
        $state->unsetState("login");
        $state->unsetState("email");
        $state->unsetState("password");
        Redirect::toRoot();
    }
}
$page = new Page('VerifyMail', new Data(['email' => $_GET['email']]));
$page->render();
Example #6
0
<?php

namespace Gallery;

use Gallery\Utilities\Parameters;
use Gallery\Database\DB;
use Gallery\Utilities\UserState;
$state = new UserState();
if ($state->isState('authorized')) {
    $img = $_GET['img'];
    $login = $state->getState("authorized");
    $param = new Parameters();
    $path = $param->imagesPath . $login . DIRECTORY_SEPARATOR;
    $db = new DB();
    $db->deleteImage($img);
    unlink($path . $img . '.jpg');
    unlink($path . $img . $param->previewSuffix . '.jpg');
}