public function save() { if (array_key_exists($this->_columns['password'], $this->_changed)) { $this->_object[$this->_columns['password']] = A1::instance($this->_config)->hash_password($this->_object[$this->_columns['password']]); } return parent::save(); }
function f() { A1::f(); A2::f(); \A1::f(); \A2::f(); B::f(); C::f(); }
function f() { self::nonStaticButSelfClass(); static::nonStaticButSelfClass(); parent::nonStaticButSelfClass(); P::nonStaticAClass(); P::staticAClass(); A1::nonStaticButSelfClass(); \a1::nonStaticButSelfClass(); b::nonStaticButSelfClass(); }
public function __set($key, $value) { if ($key === $this->columns['password']) { if ($this->loaded and $value === '') { // Do not set empty passwords return; } // Use Auth to hash the password $value = A1::instance($this->config_name)->hash_password($value); } parent::__set($key, $value); }
public function before() { if ($this->request->method() == HTTP_Request::OPTIONS) { $this->request->action('options'); } $action = $this->request->action(); if ($action and !in_array($action, array('index', 'authorize'))) { // Only apply templating to index and authorization actions $this->auto_render = FALSE; } parent::before(); $this->auth = A1::instance(); $this->user = $this->auth->get_user(); $this->session = $this->auth->session(); if ($this->auto_render) { $this->header->set('logged_in', $this->auth->logged_in()); } }
public function action_register() { /* * Checks if the user is logged in or there is no users in the DB. Otherwise redirects * to a mainpage */ if (!A1::instance()->logged_in() or Jelly::select('user')->count()) { $this->request->redirect('auth/login'); } $this->template->title = __('auth.register'); $errors = FALSE; $user = Jelly::factory('user'); if ($_POST) { $user->set(Arr::extract($_POST, array('email', 'username', 'password', 'password_confirm'))); $user->add('roles', 1); try { $user->save(); $this->request->redirect(); } catch (Validate_Exception $e) { $errors = $e->array->errors('auth'); } } $this->template->content = View::factory('auth/register')->set('user', $user)->set('errors', $errors); }
/** * Hash callback using the A1 library * * @param string password to hash * @return string */ public static function hash_password($password) { return A1::instance()->hash($password); }
/** * Test change in password */ public function testChangePassword() { $pass = A1::instance('a1')->hash_password('test_pass'); DB::insert('users', array('username', 'password'))->values(array('test_user', $pass))->execute(); $user = Sprig::factory('user', array('username' => 'test_user'))->load(); $this->assertEquals($pass, $user->password); $user->password = '******'; $user->update(); $user->load(); // Reload hashed password $salt = A1::instance('a1')->find_salt($user->password); $changed = A1::instance('a1')->hash_password('new_pass', $salt); $SUT = DB::select()->from('users')->where('id', '=', $user->id)->execute()->current(); $this->assertEquals($changed, $SUT['password']); }
public function before() { parent::before(); $this->auth = A1::instance(); $this->user = $this->auth->get_user(); }
public function doTest(A1 $obj) { echo __METHOD__ . "\n"; $obj->test(); }
public function foo() { parent::ma2(); b2::ma2(); }
<?php /* * The Authentication library to use * Make sure that the library supports a get_user method that returns FALSE when no user is logged in * and a user object that implements Acl_Role_Interface when a user is logged in. */ $config['a1'] = A1::instance('a1'); /* * The ACL Roles (String IDs are fine, use of ACL_Role_Interface objects also possible) * Use: ROLE => PARENT(S) (make sure parent is defined as role itself before you use it as a parent) */ $config['roles'] = array('user' => 'guest', 'admin' => 'user'); /* * The name of the guest role * Used when no user is logged in. */ $config['guest_role'] = 'guest'; /* * The ACL Resources (String IDs are fine, use of ACL_Resource_Interface objects also possible) * Use: ROLE => PARENT (make sure parent is defined as resource itself before you use it as a parent) */ $config['resources'] = array('blog' => NULL); /* * The ACL Rules (Again, string IDs are fine, use of ACL_Role/Resource_Interface objects also possible) * Split in allow rules and deny rules, one sub-array per rule: array( ROLES, RESOURCES, PRIVILEGES, ASSERTION) */ $config['rules'] = array('allow' => array(array('guest', 'blog', 'read'), array('user', 'blog', 'add'), array('user', 'blog', 'edit', new Acl_Assert_Argument(array('primary_key_value' => 'user_id'))), array('admin', 'blog', 'delete')), 'deny' => array());
// now new vars check::globals(array(bar_x)); class PhpFoo extends Foo { function ping() { return "PhpFoo::ping()"; } } $a = new PhpFoo(); check::equal($a->ping(), "PhpFoo::ping()", "ping failed"); check::equal($a->pong(), "Foo::pong();PhpFoo::ping()", "pong failed"); $b = new Foo(); check::equal($b->ping(), "Foo::ping()", "ping failed"); check::equal($b->pong(), "Foo::pong();Foo::ping()", "pong failed"); $a = new A1(1); check::equal($a->rg(2), 2, "rg failed"); class PhpClass extends MyClass { function vmethod($b) { $b->x = $b->x + 31; return $b; } } $b = new Bar(3); $d = new MyClass(); $c = new PhpClass(); $cc = MyClass::get_self($c); $dd = MyClass::get_self($d); $bc = $cc->cmethod($b);
/** * Test logged in from cookie */ public function testLoggedInFromCookie() { DB::insert('users', array('id', 'username', 'token'))->values(array(2, 'logged_in_cookie_user', 1234))->execute(); $_COOKIE['a1_a1_autologin'] = cookie::salt('a1_a1_autologin', '1234.2') . '~1234.2'; $this->assertType('string', cookie::get('a1_a1_autologin')); $result = A1::instance('a1')->logged_in(); $this->assertTrue($result); $session = Session::instance(Kohana::config('a1.session_type')); $user = $session->get('a1_a1'); $this->assertType('object', $user); $this->assertEquals('logged_in_cookie_user', $user->username); $this->assertEquals(2, $user->id); }
public function hash($password) { return A1::instance($this->_name)->hash($password); }
public function __construct() { $this->a1 = A1::instance(); }
/** * Hash callback using the A1 library * * @param string password to hash * @return string */ public function hash_password(Validate $array, $field) { $pass = $array[$field]; $array[$field] = A1::instance($this->_config)->hash_password($pass); }
public function filters() { return array('password' => array(array(array(A1::instance('admin/a1'), 'hash')))); }