function setPersonalInfo($firstName, $lastName, $birthDate) { $errors = []; if (empty($firstName)) { $errors[] = "FirstName is required"; } else { if (strlen($firstName) < 2 || strlen($firstName) > 30) { $errors[] = "FirstName must be between 2 and 30"; } } if (empty($lastName)) { $errors[] = "LastName is required"; } else { if (strlen($lastName) < 2 || strlen($lastName) > 30) { $errors[] = "LastName must be between 2 and 30"; } } if (empty($birthDate)) { $errors[] = "BirthDate is required"; } if (!empty($errors)) { $ex = new SiteException('Personal info change failed'); $ex->setErrors($errors); throw $ex; } else { $user = UsersPDO::get($this->userName); if ($user['PersonId'] == null) { $personId = PersonsPDO::add($firstName, $lastName, $birthDate); UsersPDO::setPersonId($this->userName, $personId); } else { $personId = $user['PersonId']; PersonsPDO::update($personId, $firstName, $lastName, $birthDate); } } }
public static function userExists($userName, $password = null) { $user = UsersPDO::get($userName, $password); if (empty($user)) { return false; } return true; }
public function listAction() { if (Request::isAjax() && Request::isPost()) { $user = UsersPDO::get(AuthModel::getUserName()); $receiverId = $_POST['receiverId']; $model = new ChatModel($user['Id']); $result = $model->getChat($receiverId); $this->renderJSON($result); } }
public function registerAction() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = []; $userName = $_POST['userName']; $email = $_POST['email']; $password = $_POST['password']; $cpassword = $_POST['cpassword']; if (empty($userName)) { $errors[] = 'User Name required'; } else { if (strlen($userName) < 4) { $errors[] = 'User Name must be more than 4 letters'; } } if (empty($email)) { $errors[] = 'Email required'; } else { if (strlen($userName) < 5) { $errors[] = 'Email must be more than 5 letters'; } } if (empty($password)) { $errors[] = 'Password required'; } else { if (strlen($password) < 6) { $errors[] = 'Password must be more than 6 letters'; } else { if (empty($cpassword)) { $errors[] = 'Password confirmation required'; } else { if ($password != $cpassword) { $errors[] = 'Password confirmation is wrong'; } } } } if (AuthModel::userExists($userName)) { $errors[] = 'This username already exists'; } if (empty($errors)) { UsersPDO::addUser($userName, $email, $password); $this->view('register_success'); return; } else { $this->errors = $errors; } } $this->title = "Register new user"; $this->view("register"); }
public function listAction() { if (!AuthModel::isLogin()) { header('Location: /auth/login/'); return; } $number = 10; $page = isset($_GET['page']) ? $_GET['page'] : 1; $limitOffset = ($page - 1) * $number; $this->page = $page; $this->pageCount = ceil(UsersPDO::count() / $number); $this->users = UsersPDO::getAllLimit($limitOffset, $number); if (Request::isAjax()) { $this->partialView('user_list_partial'); } else { $this->title = 'Users list'; $this->view('user_list'); } }
public function getChat($receiverId) { $sender = UsersPDO::getById($this->userId); $receiver = UsersPDO::getById($receiverId); $messagesFrom = MessagesPDO::get($this->userId, $receiverId); $messagesTo = MessagesPDO::get($receiverId, $this->userId); $chatMessages = array_merge($messagesFrom, $messagesTo); usort($chatMessages, function ($a, $b) { $a = new DateTime($a['Time']); $a = $a->getTimestamp(); $b = new DateTime($b['Time']); $b = $b->getTimestamp(); if ($a < $b) { return -1; } else { if ($a < $b) { return 1; } } return 0; }); return ['sender' => $sender['UserName'], 'receiver' => $receiver['UserName'], 'messages' => $chatMessages]; }