Example #1
0
 public function actionEdit($id)
 {
     $id = (int) $id;
     $name = '';
     $password = '';
     $errors = [];
     $user = UserModel::getUser('user');
     if (!$user) {
         FL::redirectTo('/');
     }
     $categories = CategoryModel::getAllUsingColumns();
     if (isset($_POST['submit'])) {
         $name = FL::clearStr($_POST['name']);
         $password = FL::clearStr($_POST['password']);
         if (!FL::isValue($name)) {
             $errors[] = 'Имя не может быть пустым';
         }
         if (!FL::isPassword($password)) {
             $errors[] = 'Пароль должен быть больше 5 символов';
         }
         if (empty($errors)) {
             $user = UserModel::getById($id);
             $user->name = $name;
             $user->password = $password;
             Session::deleteSession('user');
             Cookie::deleteCookie('user');
             $result = $user->save(false, true);
             if ($result) {
                 FL::redirectTo('/cabinet');
             }
         }
     }
     $view = new View();
     $view->categories = $categories;
     $view->id = $id;
     $view->errors = $errors;
     $view->password = $password;
     $view->user = $user;
     $view->display('cabinet/edit.php');
     return true;
 }
Example #2
0
 public function actionLogout()
 {
     Session::deleteSession('user');
     Cookie::deleteCookie('user');
     FL::redirectTo('/');
 }