public function logout() { $auth = \Lib\Auth::get_instance(); $auth->logout(); header('Location: ' . DX_ROOT_URL); exit; }
public function __construct($class_name = '\\Controllers\\Master_Controller', $model = 'master', $views_dir = '/views/master/') { parent::__construct(get_class(), $model, $views_dir); $logged_in = \Lib\Auth::get_instance()->is_logged_in(); if (!$logged_in) { header('Location: ' . DX_ROOT_URL); exit; } }
public function view($name, $data = array()) { $detect = $this->detectDay(); $data['day'] = $detect[0]; $data['name_day'] = $detect[1]; $data['logged'] = Auth::check(); $data['user'] = Auth::get(); $view = new View($name, $data); return $view->render(); }
public function update() { $user = Auth::get(); if ($user) { $notifications = $user->notifications(); foreach ($notifications as $notification) { $notification->new = 0; $notification->update(); } } }
public function update($arr) { $auth = \Lib\Auth::get_instance(); $userModel = User_Model::get_instance(); $currentPassword = $userModel->find(array('table' => 'users', 'columns' => 'password', 'where' => 'id = "' . $_SESSION['user_id'] . '"')); $patterns = ['name' => '/^[a-zA-Z\\d ]{3,20}$/', 'username' => '/^[a-zA-Z\\d_-]{3,30}$/', 'password' => '/^(?=.*[A-Za-z])(?=.*\\d)(?=.*[$@$!%*#?&])[A-Za-z\\d$@$!%*#?&]{8,30}$/', 'email' => '/^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})$/']; foreach ($arr as $key => $value) { switch ($key) { case "name": if (!preg_match($patterns['name'], $value)) { $message = "Only letters and numbers are allowed for Name"; return $message; } break; case 'email': if (!preg_match($patterns['email'], $value)) { $message = "Only letters, numbers, one '@' and one '.' are allowed for Email"; return $message; } break; case 'curr-password': $value = hash('sha256', $value); if ($value !== $currentPassword[0]['password']) { $message = "Current password does not match."; return $message; } unset($arr['curr-password']); break; case 'password': if (!preg_match($patterns['password'], $value)) { $message = "Enter at least 1 uppercase letter, number and special symbol. Password must be between 8 and 30 symbols."; return $message; } if ($value !== $arr['confirm-pass']) { $message = "Confirm password does not match."; return $message; } unset($arr['confirm-pass']); $arr['password'] = hash('sha256', $arr['password']); break; } } if ($userModel->update($arr)) { header('Location: ' . DX_ROOT_URL . 'profile.php?mid=' . $_SESSION['user_id']); exit; } else { return 'The were no changes to make.'; } }
public function __construct($class_name = '\\Controllers\\Master_Controller', $model = 'master', $views_dir = '/views/') { // Get caller classes $this->class_name = $class_name; $this->model = $model; $this->views_dir = $views_dir; // $this_class = get_class(); // $called_class = get_called_class(); // if( $this_class !== $called_class ) { // var_dump( $called_class ); // } include_once DX_ROOT_DIR . "models/{$model}.php"; $model_class = "\\Models\\" . ucfirst($model) . "_Model"; $this->model = new $model_class(array('table' => 'none')); $logged_user = \Lib\Auth::get_instance()->get_logged_user(); $this->logged_user = $logged_user; }
public function add() { $auth = \Lib\Auth::get_instance(); $topic_model = \Models\Topic_Model::get_instance(); $category_model = \Models\Category_Model::get_instance(); $user = $auth->get_logged_user(); if (!empty($user) && isset($_POST['title'], $_POST['category'], $_POST['content'])) { $title = $_POST['title']; $category = $_POST['category']; $content = $_POST['content']; $date = new \DateTime(); $dbCategory = $category_model->find(array('where' => 'name = "' . $category . '"')); if (empty($dbCategory)) { $message = 'Category does not exist.'; return $message; } if (strlen($title) > 100) { $message = 'Name can\'t be longer than 100 symbols'; return $message; } if ($title == '') { $message = 'Empty Name.'; return $message; } if (strlen($content) > 2000) { $message = 'Content can\' be longer than 2000 symbols'; return $message; } if ($content == '') { $message = 'Empty Content.'; return $message; } if ($topic_model->add(array('id' => '', 'name' => $title, 'content' => $content, 'category_id' => $dbCategory[0]['id'], 'views' => 0, 'user_id' => $user['user_id'], 'username' => $user['username'], 'date_created' => $date->format('Y-m-d H:i:s')))) { header('Location: ' . DX_ROOT_URL . 'category.php?cid=' . $dbCategory[0]['id']); exit; } else { $message = 'Adding Question failed. Please try again.'; return $message; } } elseif (!isset($_POST['category'])) { $message = 'Select category.'; return $message; } }
public function fromFollowers() { $user = Auth::get(); $posts = []; $count_posts = 0; if ($user) { $followers = $user->following(); $ids = []; foreach ($followers as $follower) { $ids[] = $follower->id; } if (count($ids) > 0) { $ids = implode(',', $ids); $post = new Post(); $posts = $post->in($ids); $count_posts = count($posts); } } return $this->view('followers-posts', compact('posts', 'count_posts')); }
public function update($request) { $validate = $this->validate($request, $this->rules); if ($validate->errors() == 0 && Auth::get()) { $conversation = new Conversation(); $conversation = $conversation->find((int) $request->id); if ($conversation) { if ($conversation->hasAccess()) { $conversation->updated_at = date('Y-m-d H:i:s'); $conversation->update(); $message = new Message(); $message->conversation_id = $conversation->id; $message->sender_id = Auth::get()->id; $message->text = nl2br(htmlspecialchars($request->text)); $message->save(); $notification = new Notification(); $notification->text = 'Používateľ ' . Auth::get()->nick . ' vám poslal novú správu!'; $notification->user_id = $conversation->getUserId(); $notification->link = 'sprava/' . $conversation->id; $notification->save(); return json_encode(['success' => 'Správa bola úspešne odoslaná!']); } else { return json_encode(['errors' => ['Nemáte prístup!']]); } } } else { return json_encode(['errors' => $validate->getErrors()]); } }
<?php include '../../../../lib/app/init.php'; /** * Initialisation */ use Lib\Tool; use Lib\Auth; use Lib\Application; use Lib\Search; use Lib\Annuaire\Contact; Tool::ifConnect(BASEFRONT); Auth::ifAdministrateurAccesApplication($bdd); /** * Variables de recherche */ if (isset($_POST['addRecherche'])) { Search::postRecherche('annuaire_contact'); } extract(Search::getRecherche('annuaire_contact', array('recherche', 'structure'))); /** * Variables de pagination */ $page = 1; $debut = 0; if (isset($_GET['page'])) { $page = $_GET['page']; $debut = $page - 1; $debut *= 50; } ?>
<?php include '../../../lib/app/init.php'; /** * Initialisation */ use Lib\Tool; use Lib\Auth; use Lib\Application; Tool::ifConnect(BASEFRONT); Auth::ifUtilisateurAccesApplication($bdd); ?> <!doctype html> <html lang="fr"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width; initial-scale=1;"> <title><?php echo Application::getApplication($bdd)->applicationNom; ?> </title> <!-- La liste des styles propre à l'intranet --> <?php include '../../include/style.php'; ?> <link href="<?php echo BASEFRONT; ?> app/documentation/js/color/tomorrow-night-eighties.css" rel="stylesheet" type="text/css"> <link href="<?php
<?php header('Content-Type: text/html; charset=utf-8'); // Db include 'config/db.php'; include_once 'root.php'; include_once 'lib/database.php'; include_once 'lib/auth.php'; include_once 'controllers/master_controller.php'; include_once 'controllers/topics.php'; include_once 'models/master.php'; include_once 'models/category.php'; include_once 'models/topic.php'; $db = \Lib\Database::get_instance()->get_db(); $auth = \Lib\Auth::get_instance(); $topic_controller = new \Controllers\Topic_Controller(); $category_model = new \Models\Category_Model(); $topics_model = new \Models\Topic_Model(); $message = ''; $categories = $category_model->find(array('columns' => 'name')); if (isset($_POST['submit'])) { $message = $topic_controller->add($categories); } $title = 'Forum'; $template_file = 'views/addTopic.php'; include 'views/layouts/default.php';
<?php $loggedUser = \Lib\Auth::get_instance()->get_logged_user(); ?> <?php if (!empty($loggedUser)) { ?> <section id="topic-add"> <form action="" method="post" id="question-form"> <input type="text" name="title" id="name" placeholder="Question name"/> <select name="category"> <option selected disabled>--Category--</option> <?php foreach ($categories as $category) { ?> <option value="<?php echo htmlentities($category['name']); ?> "><?php echo htmlentities($category['name']); ?> </option> <?php } ?> </select> <textarea name="content" class="content" placeholder="Content..."></textarea> <input type="submit" name="submit" class="button add" value="Add"/> </form> <p class="error-message"><?php
public function hasAccess() { return Auth::getUserId() == $this->sender_id || Auth::getUserId() == $this->recipient_id; }
<?php if (\Lib\Auth::get_instance()->is_logged_in()) { ?> <p class="error-message">Already logged in.</p> <?php } else { ?> <form method="post" id="login-form"> <div> <input type="text" name="username" placeholder="Username"/> </div> <div> <input type="password" name="password" placeholder="Password"/> </div> <input type="submit" class="button" name="login" value="Login" /> </form> <p class="error-message center"> <?php echo htmlentities($message); ?> </p> <?php }
if ($route === false) { require $_SERVER['DOCUMENT_ROOT'] . "/" . $dir . "/views/404.php"; die('match route'); } $ctrl = "controllers\\" . $route['controller'] . "Controller"; if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/" . $dir . "/" . $ctrl . ".php")) { require $_SERVER['DOCUMENT_ROOT'] . "/" . $dir . "/views/404.php"; die('not such controller!'); } $a = new $ctrl(); $params = $route['params']; if (method_exists($a, $route['action']) === false) { require $_SERVER['DOCUMENT_ROOT'] . "/" . $dir . "/views/404.php"; die('not such action in the controller!'); } $view = call_user_func_array(array($a, $route['action']), $params); if (is_object($view)) { $view_path = file_exists($_SERVER['DOCUMENT_ROOT'] . "/" . $dir . "/views/" . $view->view_file . ".php"); if (isset($view->data)) { foreach ($view->data as $key => $value) { ${$key} = $value; } } $auth = Auth::user(); if ($view_path === false) { require $_SERVER['DOCUMENT_ROOT'] . "/" . $dir . "/views/404.php"; die('no such view'); } else { require $_SERVER['DOCUMENT_ROOT'] . "/" . $dir . "/views/" . $view->view_file . ".php"; } }
public function follow($data) { $user = Auth::get(); if ($user) { if ($data->type == 1) { if (!$user->isFollowing($data->id)) { $user->follow($data->id); return json_encode(['success' => 'Zapnutie sledovania bolo úspešné.']); } else { return json_encode(['error' => 'Už sledujete tohto používateľa!']); } } else { if ($user->isFollowing($data->id)) { $user->unfollow($data->id); return json_encode(['success' => 'Zrušenie sledovania bolo úspešné.']); } else { return json_encode(['error' => 'Najprv musíte sledovať tohto používateľa!']); } } } return json_encode(['error' => 'Musíte byť prihlásený!']); }