Exemplo n.º 1
0
 public function login($email, $password)
 {
     if ($this->loggedIn) {
         return true;
     }
     $user = new UserModel();
     $user->filter('email', $email);
     $user->filter('password', $this->hashPassword($email, $password));
     if ($user->count() < 1) {
         return false;
     }
     $user = $user->current();
     $secret = sha1(uniqid() . microtime(true));
     /* Valid user; create a session. */
     $sess = new SessionModel();
     $in = $sess->create();
     $in->user = $user->id;
     $in->remote_ip = ip2long($_SERVER['REMOTE_ADDR']);
     $in->created_unix = time();
     $in->secret = $secret;
     $in->push();
     setcookie('dn_uid', $user->id, time() + 315576000);
     setcookie('dn_secret', $secret, time() + 315576000);
     return true;
 }
Exemplo n.º 2
0
<?php

use Documnet\Services\Session;
use Documnet\Models\User;
$session = Session::load();
$m_user = new User();
$m_user->filter('id', $session->getUserId());
if ($m_user->count()) {
    $currentUser = $m_user->current();
    define('user_role', $currentUser->role);
    $secret = sha1($_COOKIE['dn_secret']);
    define('secret', $secret);
} else {
    $currentUser = null;
    define('user_role', null);
    $secret = null;
    define('secret', null);
}
function safe($str)
{
    return htmlspecialchars($str);
}
function dump_flash()
{
    if (empty($_SESSION['dn_flash'])) {
        $_SESSION['dn_flash'] = array();
    }
    foreach ($_SESSION['dn_flash'] as $flash) {
        echo '<div class="alert alert-' . $flash[0] . ' alert-dismissible" role="alert">';
        echo '<button type="button" class="close" data-dismiss="alert">';
        echo '<span aria-hidden="true">&times;</span><span class="sr-only">';