コード例 #1
0
ファイル: UserTest.php プロジェクト: ameliefranco/casebox
 public function testUpdate()
 {
     $id = DM\User::toId($this->testName);
     $params = array('id' => $id, 'first_name' => '123', 'last_name' => '231', 'sex' => 'f', 'email' => 'f', 'password' => 'a', 'photo' => '/tmp/q.jpg', 'language_id' => 2, 'data' => '{}', 'cfg' => '{"db_user": "******"}', 'recover_hash' => '---', 'enabled' => 0, 'cid' => 1);
     DM\User::update($params);
     $data = DM\User::read($id);
     $params['password'] = md5('aero' . $params['password']);
     $this->assertArraySubset($params, $data);
     //updateByName
     unset($params['id']);
     $params['name'] = $this->testName;
     $params['password'] = '******';
     $params['enabled'] = 1;
     DM\User::updateByName($params);
     $data = DM\User::read($id);
     $params['password'] = md5('aero' . $params['password']);
     $this->assertArraySubset($params, $data);
     //verify password
     $this->assertTrue(DM\User::verifyPassword($id, 'b'), 'Wrong password');
     //check id by mail
     $id = DM\User::getIdByEmail('f');
     $this->assertTrue(is_numeric($id), 'Cant get Id by mail');
     //check id by recover hash
     $id = DM\User::getIdByRecoveryHash('---');
     $this->assertTrue(is_numeric($id), 'Cant get Id by recover hash');
     //check owner
     $this->assertTrue(DM\User::getOwnerId($id) == 1, 'different owner set');
 }
コード例 #2
0
     if (empty($templateIds)) {
         \CB\debug('receive comments cron: no comment template defined');
         continue;
     }
     $templateId = array_shift($templateIds);
     $commentsObj = Objects::getCustomClassByType('comment');
     foreach ($core['mails'] as $mail) {
         if (!Objects::idExists($mail['pid'])) {
             \CB\debug('receive comments cron: target id not found for mail "' . $mail['subject'] . '"');
             continue;
         }
         $emailFrom = extractEmailFromText($mail['from']);
         // user email
         $emailTo = extractEmailFromText($mail['to']);
         // <*****@*****.**>
         $userId = DM\User::getIdByEmail($emailFrom);
         $_SESSION['user'] = array('id' => $userId);
         $data = array('id' => null, 'pid' => $mail['pid'], 'oid' => $userId, 'cid' => $userId, 'template_id' => $templateId, 'data' => array('_title' => removeContentExtraBlock($mail['content'], $emailFrom, $emailTo)), 'sys_data' => array('mailId' => $mail['id']));
         try {
             $commentId = $commentsObj->create($data);
             //add attachments
             if (!empty($mail['attachments'])) {
                 saveObjectAttachments($commentId, $mail['attachments']);
             }
         } catch (Exception $e) {
             \CB\debug('Cannot create comment from ' . $mail['from'], $data);
         }
         $deleteMailIds[] = $mail['id'];
     }
 }
 if (!empty($mailConf['mailbox'])) {
コード例 #3
0
 /**
  * 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']);
     if (empty($p['name'])) {
         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\User::getIdByEmail($p['email']);
     if (!empty($user_id)) {
         throw new \Exception(L\get('UserEmailExists'));
     }
     $user_id = 0;
     /*check user existance, if user already exists but is deleted
       then its record will be used for new user */
     $res = DB\dbQuery('SELECT id
         FROM users_groups
         WHERE name = $1
             AND did IS NULL', $p['name']) or die(DB\dbQueryError());
     if ($r = $res->fetch_assoc()) {
         throw new \Exception(L\get('User_exists'));
     }
     $res->close();
     /*end of check user existance */
     DB\dbQuery('INSERT INTO users_groups (
             `name`
             ,first_name
             ,last_name
             ,`cid`
             ,language_id
             ,cdate
             ,uid
             ,email)
         VALUES($1
             ,$2
             ,$3
             ,$4
             ,$5
             ,CURRENT_TIMESTAMP
             ,$4
             ,$6)
         ON DUPLICATE KEY
         UPDATE id = last_insert_id(id)
             ,`name` = $1
             ,`first_name` = $2
             ,`last_name` = $3
             ,`cid` = $4
             ,last_login = NULL
             ,login_successful = NULL
             ,login_from_ip = NULL
             ,last_logout = NULL
             ,last_action_time = NULL
             ,enabled = 1
             ,cdate = CURRENT_TIMESTAMP
             ,did = NULL
             ,ddate = NULL
             ,`password` = NULL
             ,`password_change` = NULL
             ,`recover_hash` = NULL
             ,language_id = $5
             ,`cfg` = NULL
             ,`data` = NULL
             ,email = $6
             ,uid = $4
             ,cdate = CURRENT_TIMESTAMP', array($p['name'], $p['first_name'], $p['last_name'], $_SESSION['user']['id'], Config::get('language_index'), $p['email'])) or die(DB\dbQueryError());
     if ($user_id = DB\dbLastInsertId()) {
         $rez = array('success' => true, 'data' => array('id' => $user_id));
         $p['id'] = $user_id;
     }
     /* 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) or die(DB\dbQueryError());
     DB\dbQuery('DELETE FROM tree_acl WHERE user_group_id = $1', $rez['data']['id']) or die(DB\dbQueryError());
     /* end of in case it was a deleted user we delete all old acceses */
     // 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'], $_SESSION['user']['id'])) or die(DB\dbQueryError());
         $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['send_invite'])) {
         $this->sendResetPasswordMail($user_id, 'invite');
     }
     Security::calculateUpdatedSecuritySets();
     Solr\Client::runBackgroundCron();
     return $rez;
 }
コード例 #4
0
 /* try to get target folder from subject*/
 $path = false;
 //case_nr
 /* try to find user from database that corresponds to this mail.
    Ex: Kell <*****@*****.**> */
 $email = false;
 if (preg_match_all('/^[^<]*<?([^>]+)>?/i', $mail->from, $results)) {
     $email = $results[1][0];
 }
 if ($email == false) {
     $delete_ids[] = $mailbox->getUniqueId($k);
     echo "\rcannot find senders email for: {$subject} ... skipping";
     mail($mail->from, 'Error processing your email: ' . $subject, '. We didn\'t find ' . 'your email in received message. ' . $mail_requirements, 'From: ' . $core['mail_user'] . "\n\r");
     continue;
 }
 $user_id = DM\User::getIdByEmail($email);
 if (!empty($user_id)) {
     if (empty($test_user_id)) {
         $delete_ids[] = $mailbox->getUniqueId($k);
         mail($mail->from, 'Error processing your email: ' . $subject, '. We didn\'t find your' . ' email address in our users database, please update your email ' . 'address in your user profile of casebox and resend your mail. ' . 'Wrong messages are deleted automatically.' . $mail_requirements, 'From: ' . $core['mail_user'] . "\n\r");
         echo "\rcannot find corresponding user in our database '.\n                'for email {$email} from message: {$subject} ... skipping";
         continue;
     } else {
         $user_id = $test_user_id;
     }
 }
 /* end of try to find user from database that corresponds to this mail */
 if (preg_match('/(\\([\\s]*(.+)[\\s]*\\))\\s*$/i', $subject, $matches)) {
     $subject = str_replace($matches[0], '', $subject);
     $path = $matches[2];
 } else {