コード例 #1
0
ファイル: login.php プロジェクト: nok32/SoftUni
 public function logout()
 {
     $auth = \Lib\Auth::get_instance();
     $auth->logout();
     header('Location: ' . DX_ROOT_URL);
     exit;
 }
コード例 #2
0
 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;
     }
 }
コード例 #3
0
ファイル: users.php プロジェクト: nok32/SoftUni
 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.';
     }
 }
コード例 #4
0
ファイル: master_controller.php プロジェクト: nok32/SoftUni
 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;
 }
コード例 #5
0
ファイル: topics.php プロジェクト: nok32/SoftUni
 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;
     }
 }
コード例 #6
0
ファイル: addTopic.php プロジェクト: nok32/SoftUni
<?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';
コード例 #7
0
ファイル: login.php プロジェクト: nok32/SoftUni
<?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 
}
コード例 #8
0
ファイル: addTopic.php プロジェクト: nok32/SoftUni
<?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