Example #1
0
 public function tologin(LoginBean $loginBean)
 {
     $ret = array('succ' => TRUE, 'errorMsg' => array());
     $identifyingCodeImpl = new IdentifyingCodeBoImpl();
     $identifyingCodeValid = $identifyingCodeImpl->identifyingCodeValidate($loginBean->getIdentifyingCode());
     //校验验证码的合法性
     if (!$identifyingCodeValid['succ']) {
         return $identifyingCodeValid;
     }
     $loginValid = $loginBean->isValidate();
     //先验证参数的合法性
     if (!$loginValid['succ']) {
         return $loginValid;
     }
     //验证码与参数均校验成功后进入下一步校验
     $userBean = new UserBean();
     $userBean->setUserID($loginBean->getUserAccount());
     $userDao = $this->ci->userDao->selectOne($userBean);
     /**
      * 2 检查密码是否正确
      * 3 检查用户是否存在
      */
     if (empty($userDao)) {
         $ret['succ'] = FALSE;
         $ret['errorMsg'] = ERROR::LOGIN_ACCOUNT_ILLEGAL;
     }
     if ($userDao->getUserPassword() === $loginBean->getUserPassword()) {
         $ret['succ'] = FALSE;
         $ret['errorMsg'] = ERROR::LOGIN_PASSWORD_FAILED;
     }
     $this->saveLoginStatus($loginBean, $ret['succ']);
     return $ret;
 }
Example #2
0
 /**
  * Возвращает код получателя
  */
 public function getUserIdTo()
 {
     foreach ($this->to as $addr) {
         $userId = UserBean::inst()->getUserIdByMail($addr[0]);
         if (is_integer($userId)) {
             return $userId;
             //---
         }
     }
     return null;
 }
Example #3
0
 public static function getUser($id)
 {
     $rule = new RulesBean();
     $rule->setKey('AJDL2184FAS2186AGD');
     $rule->setType('ADMIN');
     $user = new UserBean();
     $user->setId($id);
     $user->setName('Miller');
     $user->setEmail('*****@*****.**');
     $user->setFone('+55 19 9.8177-2939');
     $user->addRule($rule);
     return $user;
 }
Example #4
0
 public static function validateEmail($mail, $mustPresent = false)
 {
     if (!$mail) {
         return 'required';
     }
     if (ps_strlen($mail) > EMAIL_MAXLEN) {
         return 'maxlength';
     }
     if (!PsCheck::isEmail($mail)) {
         return 'email';
     }
     $hasMail = UserBean::inst()->hasMail($mail);
     if ($hasMail && !$mustPresent || !$hasMail && $mustPresent) {
         return 'remote';
     }
     return false;
 }
Example #5
0
 /**
  * selectOne 
  * 单一查询
  * @param UserBean $userBean 
  * @access public
  * @return void
  */
 public function selectOne(UserBean $userBean)
 {
     $bean = new UserBean();
     $mapping = $userBean->getMapSetting();
     $ret = $this->select(implode(',', array_keys($mapping)))->where('user_id', $userBean->getUserID())->as_value()->find();
     foreach ($ret as $key => $value) {
         $bean->setUserID($value['user_id']);
         $bean->setUserName($value['user_name']);
         $bean->setUserPassword($value['user_password']);
         $bean->setUserEMail($value['user_email']);
     }
     return $bean;
 }
Example #6
0
 /**
  * Метод преобразует данный объект в ассоциативный массив
  */
 public function asAssocArray(array $allowed = null)
 {
     $class = __CLASS__;
     $result = array();
     foreach (PsUtil::getClassProperties($class, false, false) as $fieldName) {
         check_condition(UserBean::hasColumn($fieldName), "Поле {$class}::{$fieldName} не может быть свойством пользователя");
         if ($allowed === null || in_array($fieldName, $allowed)) {
             $result[$fieldName] = $this->{$fieldName};
         }
     }
     return $result;
 }
Example #7
0
 /**
  * Creates the string for the user's events and todos between the given start
  * and end times
  *
  * @param UserBean $user_bean the current UserBean
  * @param DateTime $start_date_time the start date to search from
  * @param DateTime $end_date_time the end date to search to
  * @param string $dtstamp the current timestamp
  * @return string the entries for events and todos
  */
 protected function createSugarIcal(&$user_bean, &$start_date_time, &$end_date_time, $dtstamp)
 {
     $ical_array = array();
     global $DO_USER_TIME_OFFSET, $sugar_config, $current_user, $timedate;
     $hide_calls = false;
     if (!empty($_REQUEST['hide_calls']) && $_REQUEST['hide_calls'] == "true") {
         $hide_calls = true;
     }
     $taskAsVTODO = true;
     if (!empty($_REQUEST['show_tasks_as_events']) && ($_REQUEST['show_tasks_as_events'] == "1" || $_REQUEST['show_tasks_as_events'] == "true")) {
         $taskAsVTODO = false;
     }
     $acts_arr = CalendarActivity::get_activities($user_bean->id, !$taskAsVTODO, $start_date_time, $end_date_time, 'month', !$hide_calls);
     // loop thru each activity, get start/end time in UTC, and return iCal strings
     foreach ($acts_arr as $act) {
         $event = $act->sugar_bean;
         if (!$hide_calls || $hide_calls && $event->object_name != "Call") {
             $ical_array[] = array("BEGIN", "VEVENT");
             $ical_array[] = array("SUMMARY", $event->name);
             $ical_array[] = array("DTSTART;TZID=" . $user_bean->getPreference('timezone'), str_replace("Z", "", $timedate->tzUser($act->start_time, $current_user)->format(self::UTC_FORMAT)));
             $ical_array[] = array("DTEND;TZID=" . $user_bean->getPreference('timezone'), str_replace("Z", "", $timedate->tzUser($act->end_time, $current_user)->format(self::UTC_FORMAT)));
             $ical_array[] = array("DTSTAMP", $dtstamp);
             $ical_array[] = array("DESCRIPTION", $event->description);
             $ical_array[] = array("URL;VALUE=URI", $sugar_config['site_url'] . "/index.php?module=" . $event->module_dir . "&action=DetailView&record=" . $event->id);
             $ical_array[] = array("UID", $event->id);
             if ($event->object_name == "Meeting") {
                 $ical_array[] = array("LOCATION", $event->location);
                 $eventUsers = $event->get_meeting_users();
                 $query = "SELECT contact_id as id from meetings_contacts where meeting_id='{$event->id}' AND deleted=0";
                 $eventContacts = $event->build_related_list($query, new Contact());
                 $eventAttendees = array_merge($eventUsers, $eventContacts);
                 if (is_array($eventAttendees)) {
                     foreach ($eventAttendees as $attendee) {
                         if ($attendee->id != $user_bean->id) {
                             // Define the participant status
                             $participant_status = '';
                             if (!empty($attendee->accept_status)) {
                                 switch ($attendee->accept_status) {
                                     case 'accept':
                                         $participant_status = ';PARTSTAT=ACCEPTED';
                                         break;
                                     case 'decline':
                                         $participant_status = ';PARTSTAT=DECLINED';
                                         break;
                                     case 'tentative':
                                         $participant_status = ';PARTSTAT=TENTATIVE';
                                         break;
                                 }
                             }
                             $ical_array[] = array('ATTENDEE' . $participant_status . ';CN="' . $attendee->get_summary_text() . '"', 'mailto:' . (!empty($attendee->email1) ? $attendee->email1 : '*****@*****.**'));
                         }
                     }
                 }
             }
             if ($event->object_name == "Call") {
                 $eventUsers = $event->get_call_users();
                 $eventContacts = $event->get_contacts();
                 $eventAttendees = array_merge($eventUsers, $eventContacts);
                 if (is_array($eventAttendees)) {
                     foreach ($eventAttendees as $attendee) {
                         if ($attendee->id != $user_bean->id) {
                             // Define the participant status
                             $participant_status = '';
                             if (!empty($attendee->accept_status)) {
                                 switch ($attendee->accept_status) {
                                     case 'accept':
                                         $participant_status = ';PARTSTAT=ACCEPTED';
                                         break;
                                     case 'decline':
                                         $participant_status = ';PARTSTAT=DECLINED';
                                         break;
                                     case 'tentative':
                                         $participant_status = ';PARTSTAT=TENTATIVE';
                                         break;
                                 }
                             }
                             $ical_array[] = array('ATTENDEE' . $participant_status . ';CN="' . $attendee->get_summary_text() . '"', 'mailto:' . (!empty($attendee->email1) ? $attendee->email1 : '*****@*****.**'));
                         }
                     }
                 }
             }
             if (isset($event->reminder_time) && $event->reminder_time > 0 && $event->status != "Held") {
                 $ical_array[] = array("BEGIN", "VALARM");
                 $ical_array[] = array("TRIGGER", "-PT");
                 $ical_array[] = array("ACTION", "DISPLAY");
                 $ical_array[] = array("DESCRIPTION", $event->name);
                 $ical_array[] = array("END", "VALARM");
             }
             $ical_array[] = array("END", "VEVENT");
         }
     }
     $str = vCal::create_ical_string_from_array($ical_array, true);
     require_once 'include/TimeDate.php';
     $timedate = new TimeDate();
     $today = gmdate("Y-m-d");
     $today = $timedate->handle_offset($today, $timedate->dbDayFormat, false);
     require_once 'modules/ProjectTask/ProjectTask.php';
     $where = "project_task.assigned_user_id='{$user_bean->id}' " . "AND (project_task.status IS NULL OR (project_task.status!='Deferred')) " . "AND (project_task.date_start IS NULL OR " . CalendarActivity::get_occurs_within_where_clause('project_task', '', $start_date_time, $end_date_time, 'date_start', 'month') . ")";
     $seedProjectTask = new ProjectTask();
     $projectTaskList = $seedProjectTask->get_full_list("", $where);
     if (is_array($projectTaskList)) {
         foreach ($projectTaskList as $projectTask) {
             $str .= $this->createSugarIcalTodo($user_bean, $projectTask, "ProjectTask", $dtstamp);
         }
     }
     if ($taskAsVTODO) {
         require_once 'modules/Tasks/Task.php';
         $where = "tasks.assigned_user_id='{$user_bean->id}' " . "AND (tasks.status IS NULL OR (tasks.status!='Deferred')) " . "AND (tasks.date_start IS NULL OR " . CalendarActivity::get_occurs_within_where_clause('tasks', '', $start_date_time, $end_date_time, 'date_start', 'month') . ")";
         $seedTask = new Task();
         $taskList = $seedTask->get_full_list("", $where);
         if (is_array($taskList)) {
             foreach ($taskList as $task) {
                 $str .= $this->createSugarIcalTodo($user_bean, $task, "Tasks", $dtstamp);
             }
         }
     }
     return $str;
 }
Example #8
0
 /** @return AdminUserBean */
 public static function inst()
 {
     return parent::inst();
 }
Example #9
0
 /**
  * Загрузка пользователя по email.
  * 
  * @param str $email - электронный адрес пользователя
  * @return PsUser
  */
 public static function instByMail($email)
 {
     $userId = UserBean::inst()->getUserIdByMail($email);
     check_condition(is_inumeric($userId), "Электронный адрес [{$email}] не зарегистрирован");
     return self::inst($userId);
 }
 public function __construct()
 {
     $this->loggedIn = SessionArrayHelper::hasInt(SESSION_USER_PARAM);
     $this->userId = $this->loggedIn ? SessionArrayHelper::getInt(SESSION_USER_PARAM) : null;
     $this->loggedInAsAdmin = $this->loggedIn ? UserBean::inst()->isAdmin($this->userId) : false;
 }
Example #11
0
 public function __construct($parentClass, $userId)
 {
     check_condition($parentClass === 'AdminManager' && ++self::$cnt === 1, 'Trying to create one more instance of ' . __CLASS__);
     check_condition(UserBean::inst()->isAdmin($userId), "User [{$userId}] is not admin");
     $this->adminId = $userId;
 }
Example #12
0
 /**
  * Получение свойства по его названию.
  * Если данные пользователя не установлены или требуемое свойство не загружено - загрузем данные из базы.
  */
 final function __get($property)
 {
     return UserBean::inst()->getUserProperty($this->userId, $property);
 }
Example #13
0
 /**
  * Creates the string for the user's events and todos between the given start
  * and end times
  *
  * @param UserBean $user_bean the current UserBean
  * @param DateTime $start_date_time the start date to search from
  * @param DateTime $end_date_time the end date to search to
  * @param string $dtstamp the current timestamp
  * @return string the entries for events and todos
  */
 protected function createSugarIcal(&$user_bean, &$start_date_time, &$end_date_time, $dtstamp)
 {
     $str = '';
     global $DO_USER_TIME_OFFSET, $sugar_config, $current_user, $timedate;
     $acts_arr = CalendarActivity::get_activities($user_bean->id, false, $start_date_time, $end_date_time, 'month');
     $hide_calls = false;
     if (!empty($_REQUEST['hide_calls']) && $_REQUEST['hide_calls'] == "true") {
         $hide_calls = true;
     }
     // loop thru each activity, get start/end time in UTC, and return iCal strings
     foreach ($acts_arr as $act) {
         $event = $act->sugar_bean;
         if (!$hide_calls || $hide_calls && $event->object_name != "Call") {
             $str .= "BEGIN:VEVENT\n";
             $str .= "SUMMARY:" . $event->name . "\n";
             $str .= "DTSTART;TZID=" . $user_bean->getPreference('timezone') . ":" . str_replace("Z", "", $timedate->tzUser($act->start_time, $current_user)->format(self::UTC_FORMAT)) . "\n";
             $str .= "DTEND;TZID=" . $user_bean->getPreference('timezone') . ":" . str_replace("Z", "", $timedate->tzUser($act->end_time, $current_user)->format(self::UTC_FORMAT)) . "\n";
             $str .= "DTSTAMP:" . $dtstamp . "\n";
             $str .= "DESCRIPTION:" . $this->escapeNls($event->description) . "\n";
             $str .= "URL;VALUE=URI:" . $sugar_config['site_url'] . "/index.php?module=" . $event->module_dir . "&action=DetailView&record=" . $event->id . "\n";
             $str .= "UID:" . $event->id . "\n";
             if ($event->object_name == "Meeting") {
                 $str .= "LOCATION:" . $event->location . "\n";
                 $eventUsers = $event->get_meeting_users();
                 $query = "SELECT contact_id as id from meetings_contacts where meeting_id='{$event->id}' AND deleted=0";
                 $eventContacts = $event->build_related_list($query, new Contact());
                 $eventAttendees = array_merge($eventUsers, $eventContacts);
                 if (is_array($eventAttendees)) {
                     foreach ($eventAttendees as $attendee) {
                         if ($attendee->id != $user_bean->id) {
                             $str .= 'ATTENDEE;CN="' . $attendee->get_summary_text() . '":mailto:' . $attendee->email1 . "\n";
                         }
                     }
                 }
             }
             if ($event->object_name == "Call") {
                 $eventUsers = $event->get_call_users();
                 $eventContacts = $event->get_contacts();
                 $eventAttendees = array_merge($eventUsers, $eventContacts);
                 if (is_array($eventAttendees)) {
                     foreach ($eventAttendees as $attendee) {
                         if ($attendee->id != $user_bean->id) {
                             $str .= 'ATTENDEE;CN="' . $attendee->get_summary_text() . '":mailto:' . $attendee->email1 . "\n";
                         }
                     }
                 }
             }
             if ($event->reminder_time > 0 && $event->status != "Held") {
                 $str .= "BEGIN:VALARM\n";
                 $str .= "TRIGGER:-PT" . $event->reminder_time / 60 . "M\n";
                 $str .= "ACTION:DISPLAY\n";
                 $str .= "DESCRIPTION:" . $event->name . "\n";
                 $str .= "END:VALARM\n";
             }
             $str .= "END:VEVENT\n";
         }
     }
     require_once 'include/TimeDate.php';
     $timedate = new TimeDate();
     $today = gmdate("Y-m-d");
     $today = $timedate->handle_offset($today, $timedate->dbDayFormat, false);
     require_once 'modules/ProjectTask/ProjectTask.php';
     $where = "project_task.assigned_user_id='{$user_bean->id}' " . "AND (project_task.status IS NULL OR (project_task.status!='Deferred')) " . "AND (project_task.date_start IS NULL OR project_task.date_start <= '{$today}')";
     $seedProjectTask = new ProjectTask();
     $projectTaskList = $seedProjectTask->get_full_list("", $where);
     if (is_array($projectTaskList)) {
         foreach ($projectTaskList as $projectTask) {
             $str .= $this->createSugarIcalTodo($user_bean, $projectTask, "ProjectTask", $dtstamp);
         }
     }
     require_once 'modules/Tasks/Task.php';
     $where = "tasks.assigned_user_id='{$user_bean->id}' " . "AND (tasks.status IS NULL OR (tasks.status!='Deferred')) " . "AND (tasks.date_start IS NULL OR tasks.date_start <= '{$today}')";
     $seedTask = new Task();
     $taskList = $seedTask->get_full_list("", $where);
     if (is_array($taskList)) {
         foreach ($taskList as $task) {
             $str .= $this->createSugarIcalTodo($user_bean, $task, "Tasks", $dtstamp);
         }
     }
     return $str;
 }
Example #14
0
 /**
  * Метод удаляет аватар (с удалением загруженной картинки)
  */
 public function deleteUserAvatar($userId, $avatarId)
 {
     $avatarId = PsCheck::int($avatarId);
     UserBean::inst()->unsetUserAvatar($userId, $avatarId);
     return AvatarUploader::inst()->deleteUploadedFile($avatarId, $userId);
 }
Example #15
0
 /**
  * Создание нового пользователя на основе данных формы регистрации
  * @return type
  */
 public static function createUser(RegFormData $regData)
 {
     //Создадим пользователя в базе
     UserBean::inst()->createUser($regData);
     //Авторизуем нового пользователя
     self::loginImpl($regData->getUserMail(), $regData->getPassword(), UserLoadType::CLIENT(), true);
 }