public function edit($options = array()) { if (!\Utils::isUserLogged()) { header('Location: /index.php?page=Pages&action=notlogged'); die; } if (!empty($_POST)) { $stmt = Ubermodel::$pdo->prepare("\n UPDATE posts\n SET title=:title, body=:body, modified=:modified\n WHERE id=:id\n "); $stmt->execute(array(':id' => $_POST['id'], ':title' => $_POST['title'], ':body' => $_POST['body'], ':modified' => date('Y-m-d H:i:s'))); header('Location: /index.php?page=Posts'); die; } $data = Ubermodel::getOne($this->tableName, 'id', $options['id']); echo $this->renderView('Posts/edit', compact('data')); }
private function registerValidation($data = array()) { if (empty($data)) { return array(); } $errors = array(); if (!empty($data['name']) && !preg_match('/^[a-z][a-z ]*$/i', $data['name'])) { $errors['name'] = true; } if (!empty($data['email']) && !filter_var($data['email'], FILTER_VALIDATE_EMAIL)) { $errors['email'] = true; } $x = Ubermodel::getOne($this->tableName, 'email', $data['email']); if (!empty($x)) { $errors['clone'] = true; } // Regex taken from http://stackoverflow.com/questions/13384008/php-regex-password-validation-not-working if (!empty($data['password']) && !preg_match("/^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{6,20}\$/", $data['password'])) { $errors['password'] = true; if ($data['password'] != $data['repassword']) { $errors['repassword'] = true; } } if (!empty($data['gender']) && !($data['gender'] === 'male' || $data['gender'] === 'female')) { $errors['gender'] = true; } if (!empty($data['birth_day']) && !($data['birth_day'] >= 1 && $data['birth_day'] <= 31)) { $errors['birth_day'] = true; } if (!empty($data['birth_month']) && !($data['birth_month'] >= 1 && $data['birth_month'] <= 12)) { $errors['birth_month'] = true; } if (!empty($data['birth_year']) && !($data['birth_year'] >= 1900 && $data['birth_year'] <= 2014)) { $errors['birth_year'] = true; } // $captcha = \core\wrapper\CaptchaWrapper::createCaptcha(__ENVIRONMENT__); // $response = $captcha->check($_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']); // if (!$response->isValid()) // { // $errors['captcha'] = true; // } return $errors; }
public function doesUserExist($args) { $user = Ubermodel::getOne('users', 'email', $args['email']); return $user; }