示例#1
0
 public static function create_user($login = false)
 {
     $person = new midcom_db_person();
     $person->_use_rcs = false;
     $person->_use_activitystream = false;
     $password = substr('p_' . time(), 0, 11);
     $username = __CLASS__ . ' user ' . microtime();
     midcom::get('auth')->request_sudo('midcom.core');
     if (!$person->create()) {
         throw new Exception('Person could not be created. Reason: ' . midcom_connection::get_error_string());
     }
     $account = midcom_core_account::get($person);
     $account->set_password($password);
     $account->set_username($username);
     $account->save();
     midcom::get('auth')->drop_sudo();
     if ($login) {
         if (!midcom::get('auth')->login($username, $password)) {
             throw new Exception('Login for user ' . $username . ' failed');
         }
         midcom::get('auth')->_sync_user_with_backend();
     }
     self::$_class_objects[$person->guid] = $person;
     return $person;
 }
示例#2
0
 public function testCRUD()
 {
     midcom::get('auth')->request_sudo('midcom.core');
     $person = new midcom_db_person();
     $stat = $person->create();
     $this->assertTrue($stat);
     $this->register_object($person);
     $person = new midcom_db_person($person->guid);
     $this->assertEquals('person #' . $person->id, $person->name);
     $this->assertEquals('person #' . $person->id, $person->rname);
     $person->firstname = ' Firstname ';
     $person->lastname = ' Lastname ';
     $stat = $person->update();
     $this->assertTrue($stat);
     $this->assertEquals('Firstname Lastname', $person->name);
     $this->assertEquals('Lastname, Firstname', $person->rname);
     $group = $this->create_object('midcom_db_group');
     $attributes = array('gid' => $group->id, 'uid' => $person->id);
     $member = $this->create_object('midcom_db_member', $attributes);
     $stat = $person->delete();
     $this->assertTrue($stat);
     $qb = midcom_db_member::new_query_builder();
     $qb->add_constraint('id', '=', $member->id);
     $this->assertEquals(0, $qb->count());
     midcom::get('auth')->drop_sudo();
 }
示例#3
0
文件: create.php 项目: nemein/openpsa
 /**
  * DM2 creation callback.
  */
 function &dm2_create_callback(&$controller)
 {
     // Create a new person
     $this->_person = new midcom_db_person();
     if (!$this->_person->create()) {
         debug_print_r('We operated on this object:', $this->_person);
         throw new midcom_error('Failed to create a new person. Last Midgard error was: ' . midcom_connection::get_error_string());
     }
     return $this->_person;
 }
示例#4
0
     $username = str_replace('ä', 'a', $username);
     $username = str_replace('ö', 'o', $username);
     $username = str_replace('Ä', 'a', $username);
     $username = str_replace('Ö', 'o', $username);
     $username = str_replace('Å', 'a', $username);
     $username = str_replace('å', 'a', $username);
     $person->username = $username;
     // Generate a random password and activation Hash
     $password = '******';
     $length = 8;
     // Create a random password
     for ($i = 0; $i < $length; $i++) {
         $password .= chr(rand(97, 122));
     }
     $person->password = $password;
     $person->create();
     $group = new midcom_db_group();
     $group->get_by_path('/kkp_admins/editoijat');
     $member = new midcom_db_member();
     $member->uid = $person->id;
     $member->gid = $group->id;
     $member->create();
     $mail = new org_openpsa_mail();
     $mail->from = '*****@*****.**';
     $mail->subject = '[KKp-web] Tunnukset sivustolle';
     $mail->body = "Hei\n\nTunnus: " . $username;
     $mail->body .= "\nSalasana: " . str_replace('**', '', $password);
     $mail->to = $person->email;
     $mail->send();
     $status = 'Tunnukset lähetetty.';
 }