Ejemplo n.º 1
0
function downloadImageFromUrl($fileUrl)
{
    $fullname = basename($fileUrl);
    list($filename, $extension) = explode(".", $fullname);
    $uploadfile = UPLOAD_DIR . $fullname;
    $f = fopen($fileUrl, 'rb');
    if ($f) {
        $content = "";
        while ($data = fread($f, 1024)) {
            $content .= $data;
        }
        fclose($f);
        file_put_contents($uploadfile, $content);
        return [$filename, $extension];
    } else {
        addFlashMessage('error', 'The URL couldn\'t not be found');
    }
}
Ejemplo n.º 2
0
<?php

require_once 'bootstrap.php';
# Get values of variables
$username = $_POST['username'];
$password = $_POST['password'];
$retype = $_POST['retype'];
if ($username == '' || $password == '' || $retype == '') {
    addFlashMessage('All fields must be filled in order to register <br/>');
    redirect("index.php");
}
if ($password !== $retype) {
    addFlashMessage('Provided passwords have to be identical <br/>');
    redirect("index.php");
}
$existance = userExistance($username);
if ($existance != 0) {
    addFlashMessage('You are known here, no need to introduce again. <br/>');
    redirect("index.php");
}
try {
    $adduser = "******";
    $prepare_add_user_querry = $database->prepare($adduser);
    $prepare_add_user_querry->execute(array(':username' => $username, ':password' => md5($password)));
} catch (PDOException $exception) {
    echo $exception->getMessage();
}
addFlashMessage('We will remember you!');
redirect("index.php");
Ejemplo n.º 3
0
            addFlashMessage('error', 'Something went wrong. You must fill all the fields');
        } else {
            $username = trim($_POST['username']);
            // To improve the ux of the user, you can trim the input
            $password = trim($_POST['password']);
            $stmt = $conn->prepare("SELECT * FROM users WHERE username = ?");
            if ($stmt->execute(array($username))) {
                $result = $stmt->fetchAll();
                if (count($result) === 1 && password_verify($password, $result[0]['password'])) {
                    $_SESSION['id'] = $result[0]["id"];
                    $_SESSION['username'] = $result[0]["username"];
                    addFlashMessage('success', 'You\'ve successfully logged in');
                    redirect($_SERVER['PHP_SELF']);
                }
            }
            addFlashMessage('error', 'Something went wrong. You must fill all the fields');
        }
    }
}
?>
  <div>
    
    <form method="post" action="">
      <fieldset>
        <legend>Connexion</legend>
        <p>
          <label for="username">Pseudo :</label>
          <input name="username" type="text" id="username" /><br />

          <label for="password">Mot de Passe :</label>
          <input type="password" name="password" id="password" />
Ejemplo n.º 4
0
<?php

require_once 'session.php';
require_once 'functions.php';
require_once 'connect.php';
session_destroy();
$stmt = $conn->prepare("DELETE FROM users WHERE id=:id");
$stmt->bindParam(':id', $_SESSION['id']);
if (!$stmt->execute()) {
    addFlashMessage('error', 'Could not delete the user');
} else {
    addFlashMessage('success', 'Your account has been deleted');
}
redirect('login.php');
Ejemplo n.º 5
0
 * Time: 18:55
 */
require_once __DIR__ . '/app/init.php';
$data = isset($_POST['post']) ? $_POST['post'] : [];
$post = [];
$errors = [];
if (isset($data['id'])) {
    $id = $data['id'];
} else {
    if (isset($_GET['id'])) {
        $id = $_GET['id'];
    }
}
if (isset($id)) {
    $post = getPostById((int) $id);
    if (!$post) {
        header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not found');
        exit('Post not found');
    }
}
if ($data) {
    $msg = 'Запись успешно ' . isset($post['id']) ? 'изменена' : 'добавлена';
    $post = savePost($data, $errors);
    if (!$errors) {
        addFlashMessage($msg);
        //Запись успешно сохарнена
        header('location: edit.php?id=' . $post['id']);
        exit;
    }
}
require_once __DIR__ . 'app/views/edit.php';
Ejemplo n.º 6
0
<?php

require_once 'bootstrap.php';
# Get values of variables
$username = $_POST['username'];
$password = $_POST['password'];
if ($username == '' || $password == '') {
    addFlashMessage('All fields must be filled in <br/>');
    redirect("login.php");
}
try {
    $get_user_password = "******";
    $prepare_get_user_password_querry = $database->prepare($get_user_password);
    $prepare_get_user_password_querry->execute(array(':username' => $username, ':password' => md5($password)));
    $user = $prepare_get_user_password_querry->fetchObject();
    if (null == $user) {
        addFlashMessage("Wrong username or password");
        redirect("login.php");
    }
    $activated = $user->Activated;
    if (null == $activated) {
        addFlashMessage("Your account wasn't activated yet.");
        redirect("login.php");
    } else {
        setLoggedIn(true);
        redirect("logged.php");
    }
} catch (PDOException $exception) {
    echo $exception->getMessage();
}
echo render('templates/', array('users' => $users));