本文整理汇总了PHP中Security::check方法的典型用法代码示例。如果您正苦于以下问题:PHP Security::check方法的具体用法?PHP Security::check怎么用?PHP Security::check使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Security
的用法示例。
在下文中一共展示了Security::check方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_index
public function action_index()
{
$view = View::factory('home/register');
if ($this->request->method() === Request::POST) {
if (!Security::check($this->request->post('token'))) {
throw new Exception("Bad Token");
}
$post = Validation::factory($_POST)->rule('name', 'not_empty')->rule('surname', 'not_empty')->rule('email', 'not_empty')->rule('email', 'email')->rule('email', 'Model_Client::if_email_exists')->rule('pass', 'not_empty')->rule('pass_confirm', 'not_empty')->rule('pass', 'matches', array(':validation', 'pass_confirm', 'pass'))->rule('checkbox', 'not_empty');
if ($post->check()) {
$salt = 'MySalt!';
$name = $this->request->post('name');
$surname = $this->request->post('surname');
$email = $this->request->post('email');
$pass = crypt($salt, $this->request->post('pass'));
$checkbox = $this->request->post('checkbox');
$clients = new Model_Client();
$data = array('name' => $name, 'surname' => $surname, 'email' => $email, 'pass' => $pass, 'is_superuser' => '0');
$create_user = $clients->create_user($data);
if (!$create_user) {
throw new Exception("Please check all fields!");
}
$this->request->redirect('/');
}
}
$this->template->content = $view->render();
}
示例2: action_create
public function action_create()
{
$this->template->page_title = 'Create Page';
$user = new Model_User();
$session = Session::instance()->get('user');
$view = View::factory('cp/pages/create');
$view->author = $user->get_user_by_session_id($session);
if ($this->request->method() === Request::POST) {
if (!Security::check($this->request->post('csrf_token'))) {
throw new HTTP_Exception_401("Bad token!");
}
$post_title = $this->request->post('title');
$post_content = $this->request->post('content');
$post_author = $this->request->post('author');
$post_date = time();
if (empty($post_title) && empty($post_content) && empty($post_author) && empty($post_date)) {
throw new Exception('Please don`t make empty fields!');
}
$page = new Model_Page();
$data = array('title' => $post_title, 'content' => $post_content, 'author' => $post_author, 'date' => $date);
$insert_page = $page->insert_page($data);
if (!$insert_page) {
throw new Exception('Check if you are connected to database!');
}
$this->request->redirect('cp/pages');
}
$this->template->content = $view->render();
}
示例3: action_do
public function action_do()
{
$user_id = $this->request->param('id');
$hash = $this->request->param('id2');
$password_recovery = new Model_Password_Recovery();
$check_hash = $password_recovery->check($user_id, $hash);
if ($check_hash !== true) {
throw new Exception("This hash is not a password recovery request!");
}
$view = View::factory('forgot_password/recovery');
if ($this->request->method() === Request::POST) {
if (!Security::check($this->request->post('csrf_secure'))) {
throw new Exception("Bad token!");
}
$password = $this->request->post('password');
$confirm = $this->request->post('confirm');
if ($password !== $confirm) {
throw new Exception("Passwords did not match!");
}
$user = new Model_User();
$password = crypt($password, 'generatedsalt');
$change_password = $user->recover_password($password, $user_id);
if (!$change_password) {
throw new Exception("Error with changing a password!");
}
$chmod_attemp = $password_recovery->chmod_attemp($hash);
if (!$chmod_attemp) {
throw new Exception("False");
}
$this->redirect('');
}
$this->template->content = $view->render();
}
示例4: action_create
public function action_create()
{
if (Auth::is_admin_signed_in() === true) {
$view = View::factory('acp/categories/create');
$categories = new Model_Category();
if ($this->request->method() === Request::POST) {
$name = $this->request->post('name');
$slug = $this->request->post('slug');
$token = $this->request->param('id');
if (!Security::check($token)) {
$this->request->redirect('acp/categories/create');
}
if (empty($slug)) {
$slug = URL::title($name, '_');
}
if (empty($name) && empty($slug)) {
$this->request->redirect('acp/categories/create');
}
$categories = new Model_Category();
$create_category = $categories->create_category($name, $slug);
if (!$create_category) {
$this->request->redirect('acp/categories/create');
}
$this->request->redirect('acp/categories');
}
$this->template->content = $view->render();
} else {
$this->request->redirect('acp');
}
}
示例5: action_login
public function action_login()
{
if (HTTP_Request::POST == $this->request->method() && Security::check(Arr::get($this->request->post(), 'csrf', '')) && Captcha::valid($_POST['captcha'])) {
$remember = array_key_exists('remember', $this->request->post()) ? (bool) $this->request->post('remember') : FALSE;
$user = Auth::instance()->login($this->request->post('username'), $this->request->post('password'), $remember);
if ($user) {
HTTP::redirect($this->config->get('admin_url'));
} else {
Session::instance()->set('error', 'Логин или пароль не верный');
$errors = array('Логин или пароль не верный.');
}
}
$this->template = 'login';
parent::before();
$captcha = Captcha::instance();
$csrf = Security::token(true);
$this->template->title = 'Вход в админ панель';
$this->template->bind('errors', $errors)->bind('csrf', $csrf)->bind('captcha', $captcha);
$errors = null;
if (Auth::instance()->get_user()) {
$auth = Auth::instance();
$has_admin_role = $auth->logged_in('admin');
if ($has_admin_role) {
$session = Session::instance();
$session->set('redirectAfterLogin', $_SERVER['REQUEST_URI']);
HTTP::redirect('/' . $this->admin_url . '/');
}
}
}
示例6: action_index
public function action_index()
{
$count = ORM::factory('User')->count_all();
if ($count === 0) {
$this->template->content = View::factory('install/index');
if ($this->request->method() === Request::POST) {
if (!Security::check($this->request->param('id'))) {
throw new Exception("Bad token!");
}
$post = Validation::factory($_POST)->rule('username', 'not_empty')->rule('email', 'not_empty')->rule('email', 'email')->rule('password', 'not_empty')->rule('password', 'min_length', array(':value', '8'))->rule('password2x', 'not_empty')->rule('password', 'matches', array(':validation', 'password', 'password2x'));
if ($post->check()) {
$user = new Model_User();
$post = $this->request->post();
$user->values($post)->save();
$adminRole = ORM::factory('Role')->where('name', '=', 'admin')->find();
$loginRole = ORM::factory('Role')->where('name', '=', 'login')->find();
$user->add('roles', $loginRole);
$user->add('roles', $adminRole);
$this->redirect('install/successful');
} else {
$this->redirect('install/oops');
}
}
} else {
$this->redirect('');
}
}
示例7: get
/**
* Get cookie value(s)
*
* @param string $name Name of the cookie to get
* @param mixed $default [optional] Default value if cookie is not set. Default is false
* @return mixed Cookie stored datas
*/
public static function get($name, $default = false)
{
// handling array notation
if (preg_match('#^(.*?)\\[(.*?)\\]$#', $name, $m)) {
if (!isset($_COOKIE[$m[1]][$m[2]])) {
return $default;
}
$value = $_COOKIE[$m[1]][$m[2]];
} else {
if (!isset($_COOKIE[$name])) {
return $default;
}
$value = $_COOKIE[$name];
}
// retrieve cookie content
$cookieValue = explode('|', $value);
// hash is not correct
if (count($cookieValue) !== 3 || !Security::check($cookieValue[0] . $cookieValue[1], $cookieValue[2])) {
Cookie::delete($name);
return $default;
}
$value = $cookieValue[0];
// if content is a serialized array
if ($v = @unserialize($value)) {
$value = $v;
}
return $value;
}
示例8: action_sign_up
public function action_sign_up()
{
$email = $this->request->post('email');
$pass = crypt('MySalt!', $this->request->post('pass'));
$cookie = $this->request->post('cookie');
if (!Security::check($this->request->param('id'))) {
throw new Exception("Bad Token!");
}
if (empty($email) and empty($pass)) {
$this->request->redirect('acp');
}
$client = new Model_Client();
$email_from_db = $client->email_from_db($email);
$pass_from_db = $client->pass_from_db($email);
if ($email !== $email_from_db || $pass !== $pass_from_db) {
throw new Exception("This User do not exists! \n {$pass} {$pass_from_db}");
}
$is_superuser = $client->is_superuser($email);
if ($is_superuser === 0) {
throw new Exception("Sorry, but you are not a superuser!");
}
if ($cookie) {
Cookie::set('admin', $email);
}
Session::instance()->set('admin', $email);
$this->request->redirect('acp');
}
示例9: action_write
public function action_write()
{
$this->template->page_title = 'Write Article';
$user = new Model_User();
$session = Session::instance()->get('user');
$view = View::factory('cp/entries/write');
$view->author = $users->get_user_by_session_id($session);
if ($this->request->method() === Request::POST) {
if (!Security::check($this->request->post('csrf_token'))) {
throw new HTTP_Exception_401("Bad token!");
}
$post_title = $this->request->post('title');
$post_slug = $this->request->post('slug');
$post_content = $this->request->post('content');
$post_author = $this->request->post('author');
$post_date = time();
if (empty($post_title) and empty($post_content) and empty($post_author) and empty($post_date)) {
throw new Exception('Please don`t make empty fields!');
}
if (empty($post_slug)) {
$post_slug = URL::title($post_title, '_');
}
$entry = new Model_Entry();
$data = array('title' => $post_title, 'slug' => $post_slug, 'content' => $post_content, 'author' => $post_author, 'date' => $post_date);
$insert_entry = $entry->insert_entry($data);
if (!$insert_entry) {
throw new Exception('Check if you are connected to database!');
}
$this->request->redirect('cp/entries/write/');
}
$this->template->content = $view->render();
}
示例10: before
public function before()
{
if ($this->request->is_ajax() && $this->request->method() == 'POST') {
if (!Security::check($this->request->headers('X-CSRF-TOKEN'))) {
return $this->response->status(403)->body('X-CSRF protection');
}
}
}
示例11: provider_csrf_token
/**
* Provides test data for Security::token()
*
* @return array Test data sets
*/
public function provider_csrf_token()
{
$array = array();
for ($i = 0; $i <= 4; $i++) {
Security::$token_name = 'token_' . $i;
$array[] = array(Security::token(TRUE), Security::check(Security::token(FALSE)), $i);
}
return $array;
}
示例12: formComponentSave
/**
* Form Component Save
*/
public static function formComponentSave()
{
if (Request::post('sandbox_component_save')) {
if (Security::check(Request::post('csrf'))) {
Option::update('sandbox_template', Request::post('sandbox_form_template'));
Request::redirect('index.php?id=themes');
}
}
}
示例13: attempt
public function attempt($login, $password, $remember = false)
{
if ($hash = $this->retrieveUser($login)) {
if (Security::check($login . $password, $hash)) {
return $this->login($login, $remember);
}
}
return false;
}
示例14: action_delete_category
public function action_delete_category()
{
$category_id = $this->request->param('id');
if (!Security::check($this->request->param('id2'))) {
throw new Exception("Bad token!");
}
$category = ORM::factory('Category');
$delete_category = $category->delete_category($category_id);
$this->redirect('dashboard/categories/list');
}
示例15: __construct
function __construct($param = null)
{
try {
Security::check($this);
} catch (Exception $e) {
header('Location: /403');
}
$this->param = $param;
$this->init();
}