Beispiel #1
0
 public static function add_user(user_object $user)
 {
     $sql = "INSERT INTO \n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t`users`(\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t`user_login`,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t`user_password`,\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t`user_email`,\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t`user_signin_datetime`\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t) \n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tVALUES(\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t" . database_essence::prepare($user->get_login()) . ",\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t" . database_essence::prepare($user->get_password()) . ",\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t" . database_essence::prepare($user->get_email()) . ",\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tNOW()\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t)";
     if ($user_id = database_essence::insert($sql, 'users')) {
         return $user_id;
     }
     return null;
 }
Beispiel #2
0
 public static function signin()
 {
     if ($me = session_essence::get('me')) {
         request_essence::load_request();
     }
     $validation = self::validate_signin();
     if ($validation->valid()) {
         $user = new user_object();
         $user->set_login(data_essence::get('post', 'authorization-login', array('trim')));
         $user->set_email(data_essence::get('post', 'authorization-email', array('trim')));
         $user->set_password(md5(data_essence::get('post', 'authorization-password', array('trim'))));
         if ($user_id = user_model::add_user($user)) {
             $me = new user_object(array('user_id' => $user_id));
             session_essence::set('me', $me);
             request_essence::load_request('user', 'view', array($me->get_login()));
         }
     } else {
         view_essence::assign('breadcrumb', 'Регистрация');
         view_essence::assign('validation', $validation);
         view_essence::display('authorization/signin');
     }
 }
  function logout()
  {
    if(($result = parent :: logout()) === false)
      return false;

    if($this->_walk_node_objects('logout') === false)
      return false;

    return true;
  }
Beispiel #4
0
 /**
  * Test the magic methods for getting associated records.
  * @uses $DB
  * @uses $USER
  */
 public function test_get_associated_records()
 {
     global $DB, $USER;
     // Get some random user.
     $user = $DB->get_record('user', array(), '*', IGNORE_MULTIPLE);
     // Get some random role.
     $role = $DB->get_record('role', array(), '*', IGNORE_MULTIPLE);
     // Add a role assignment.
     $syscontext = context_system::instance();
     // Create a new role assignment.
     $ra = new stdClass();
     $ra->userid = $user->id;
     $ra->roleid = $role->id;
     $ra->contextid = $syscontext->id;
     $ra->timemodified = time();
     $ra->modifierid = $USER->id;
     $ra->id = $DB->insert_record('role_assignments', $ra);
     // Count the role assignments for the user.
     $user = new user_object($user, null, array(), true, array(), $DB);
     $this->assertEquals($user->count_role_assignments(), 1);
     // Verify that we can get the role assignment via the magic get method.
     $roleassignments = $user->role_assignments->to_array();
     $this->assertEquals(count($roleassignments), 1);
     $ra = current($roleassignments);
     $this->assertEquals($ra->userid, $user->id);
     $this->assertEquals($ra->roleid, $role->id);
     $this->assertEquals($ra->contextid, $syscontext->id);
     // Verify that we can get the role assignment via the magic call method.
     $roleassignments = $user->get_role_assignments()->to_array();
     $this->assertEquals(count($roleassignments), 1);
     $ra = current($roleassignments);
     $this->assertEquals($ra->userid, $user->id);
     $this->assertEquals($ra->roleid, $role->id);
     $this->assertEquals($ra->contextid, $syscontext->id);
     // Test the filtered get and count methods.
     $roleassignments = $user->get_role_assignments(new field_filter('userid', $user->id, field_filter::NEQ))->to_array();
     $this->assertEquals(count($roleassignments), 0);
     $this->assertEquals($roleassignments = $user->count_role_assignments(new field_filter('userid', $user->id, field_filter::NEQ)), 0);
     $this->assertEquals($ra->user->id, $user->id);
 }