コード例 #1
0
ファイル: UserTest.php プロジェクト: youprofit/casebox
 /**
  * @depends testCreate
  */
 public function testsetAsLoged()
 {
     $id = DM\Users::create(array('name' => $this->testName, 'password' => 'qq'));
     $this->assertTrue(is_numeric($id), 'Cant create User');
     \CB\User::setAsLoged($id, 'tests_key');
     $this->assertTrue(\CB\User::isLoged(), ' Error: user is not logged');
     $this->assertEquals($id, $_SESSION['user']['id'], 'Sessions user is not equal with setted users');
     $this->assertEquals('tests_key', $_SESSION['key'], 'Sessions key is not equal with setted keys');
 }
コード例 #2
0
ファイル: UsersGroups.php プロジェクト: sebbie42/casebox
 /**
  * Add a new user
  * params: name, group_id
  */
 public function addUser($p)
 {
     if (!User::isVerified()) {
         return array('success' => false, 'verify' => true);
     }
     if (!Security::canManage()) {
         throw new \Exception(L\get('Access_denied'));
     }
     $rez = array('success' => false, 'msg' => L\get('Missing_required_fields'));
     $p['name'] = strip_tags($p['name']);
     $p['name'] = trim($p['name']);
     $p1 = empty($p['password']) ? '' : $p['password'];
     $p2 = empty($p['confirm_password']) ? '' : $p['confirm_password'];
     if (empty($p['name']) || $p1 != $p2) {
         return $rez;
     }
     // validate input params
     if (!preg_match('/^[a-z\\.0-9_]+$/i', $p['name'])) {
         return array('success' => false, 'msg' => 'Invalid username. Use only letters, digits, "dot" and/or "underscore".');
     }
     $p['first_name'] = Purify::humanName($p['first_name']);
     $p['last_name'] = Purify::humanName($p['last_name']);
     if (!empty($p['email'])) {
         if (!filter_var($p['email'], FILTER_VALIDATE_EMAIL)) {
             return array('success' => false, 'msg' => L\get('InvalidEmail'));
         }
     }
     //check if user with such email doesn exist
     $user_id = DM\Users::getIdByEmail($p['email']);
     if (!empty($user_id)) {
         throw new \Exception(L\get('UserEmailExists'));
     }
     /*check user existance, if user already exists but is deleted
       then its record will be used for new user */
     $user_id = DM\Users::getIdByName($p['name']);
     if (!empty($user_id)) {
         throw new \Exception(L\get('User_exists'));
     }
     $params = array('name' => $p['name'], 'first_name' => $p['first_name'], 'last_name' => $p['last_name'], 'cid' => User::getId(), 'language_id' => Config::get('language_index'), 'email' => $p['email']);
     if (!empty($p['password']) && !empty($p['psw_setup']['ps']) && $p['psw_setup']['ps'] == 2) {
         $params['password'] = $p['password'];
     }
     $user_id = DM\Users::getIdByName($p['name'], false);
     if (!empty($user_id)) {
         //update
         $params['id'] = $user_id;
         DM\Users::update($params);
         /* in case it was a deleted user we delete all old acceses */
         DB\dbQuery('DELETE FROM users_groups_association WHERE user_id = $1', $user_id);
         DB\dbQuery('DELETE FROM tree_acl WHERE user_group_id = $1', $rez['data']['id']);
         /* end of in case it was a deleted user we delete all old acceses */
     } else {
         //create
         $user_id = DM\Users::create($params);
     }
     $rez = array('success' => true, 'data' => array('id' => $user_id));
     $p['id'] = $user_id;
     // associating user to group if group was specified
     if (isset($p['group_id']) && is_numeric($p['group_id'])) {
         DB\dbQuery('INSERT INTO users_groups_association (user_id, group_id, cid)
             VALUES($1, $2, $3)
             ON duplicate KEY
             UPDATE cid = $3', array($user_id, $p['group_id'], User::getId()));
         $rez['data']['group_id'] = $p['group_id'];
     } else {
         $rez['data']['group_id'] = 0;
     }
     //check if send invite is set and create notification
     if (!empty($p['psw_setup']['ps']) && $p['psw_setup']['ps'] == 1) {
         $this->sendResetPasswordMail($user_id, 'invite');
     }
     Security::calculateUpdatedSecuritySets();
     Solr\Client::runBackgroundCron();
     return $rez;
 }