예제 #1
0
 public function signIn()
 {
     $mEmail = $this->data['email'];
     $mPassword = $this->data['password'];
     $mCompanyDomain = $this->data['domain'];
     $user = new User($this->db);
     $user->allocateByEmail($mEmail);
     $mCompany = new Company($this->db);
     $mCompany->allocateByDomain($mCompanyDomain);
     if ($user->isEmpty() || $mCompany->isEmpty() || $mCompany->getId() != $user->getCompanyId() || !$user->isPasswordEqual($mPassword)) {
         return;
     }
     $user->updateRecentActivityTime();
     $key_manager = new KeyManager();
     $access_key = $this->generateKey();
     $key = $key_manager->createKey($user->getId(), $access_key);
     $csrf_token = sha1($key . 'success');
     $user->addAccessKey($access_key);
     $this->setCookie(CheckAuthorization::IDENTIFIER, $key, time() + 365 * 24 * 3600, '/', $_SERVER['HTTP_HOST']);
     $this->setCookie(CheckAuthorization::CSRF_TOKEN_NAME, $csrf_token, time() + 365 * 24 * 3600, '/', $_SERVER['HTTP_HOST']);
     $this->setSession(CheckAuthorization::IDENTIFIER, $key);
     $this->result = true;
 }
예제 #2
0
 /**
  * @param int $access_flag
  * @param Company $mCompany
  */
 private function apply($access_flag, $mCompany)
 {
     if ($mCompany->isEmpty()) {
         throw new NotFoundCompanyException();
     }
     $mAccessManager = new CompanyAccessManager();
     $this->result = array('company' => array());
     $tempCompanyFields = array();
     if ($mAccessManager->can($access_flag, 'id')) {
         $tempCompanyFields['id'] = intval($mCompany->getId());
     }
     if ($mAccessManager->can($access_flag, 'name')) {
         $tempCompanyFields['name'] = $mCompany->getName();
     }
     if ($mAccessManager->can($access_flag, 'country')) {
         $tempCompanyFields['country'] = $mCompany->getCountry();
     }
     if ($mAccessManager->can($access_flag, 'city')) {
         $tempCompanyFields['city'] = $mCompany->getCity();
     }
     if ($mAccessManager->can($access_flag, 'website')) {
         $tempCompanyFields['website'] = $mCompany->getWebsite();
     }
     if ($mAccessManager->can($access_flag, 'company_type')) {
         $tempCompanyFields['company_type'] = intval($mCompany->getCompanyType());
     }
     if ($mAccessManager->can($access_flag, 'company_logo')) {
         $tempCompanyFields['company_logo'] = $mCompany->getCompanyLogo();
     }
     if ($mAccessManager->can($access_flag, 'user_id')) {
         $tempCompanyFields['user_id'] = intval($mCompany->getUserId());
     }
     if ($mAccessManager->can($access_flag, 'domain')) {
         $tempCompanyFields['domain'] = $mCompany->getDomain();
     }
     if ($mAccessManager->can($access_flag, 'contact_email')) {
         $tempCompanyFields['contact_email'] = $mCompany->getContactEmail();
     }
     if ($mAccessManager->can($access_flag, 'contact_phone')) {
         $tempCompanyFields['contact_phone'] = $mCompany->getContactPhone();
     }
     if ($mAccessManager->can($access_flag, 'register_time')) {
         $tempCompanyFields['register_time'] = intval($mCompany->getRegisterTime());
     }
     if ($mAccessManager->can($access_flag, 'max_count_services')) {
         $tempCompanyFields['max_count_services'] = intval($mCompany->getMaxCountServices());
     }
     if ($mAccessManager->can($access_flag, 'current_count_services')) {
         $tempCompanyFields['current_count_services'] = intval($mCompany->getCurrentCountServices());
     }
     if ($mAccessManager->can($access_flag, 'employees_number')) {
         $tempCompanyFields['employees_number'] = intval($mCompany->getEmployeesNumber());
     }
     if ($mAccessManager->can($access_flag, 'end_subscription_time')) {
         $tempCompanyFields['end_subscription_time'] = intval($mCompany->getEndSubscriptionTime());
     }
     if ($mAccessManager->can($access_flag, 'end_subscription_time')) {
         $tempCompanyFields['remain_time'] = intval($mCompany->getRemainTime());
     }
     if ($mAccessManager->can($access_flag, 'end_subscription_time')) {
         $tempCompanyFields['is_not_expired'] = $mCompany->isNotExpired();
     }
     if ($mAccessManager->can($access_flag, 'stop_company_time')) {
         $tempCompanyFields['stop_company_time'] = intval($mCompany->getStopCompanyTime());
     }
     if ($mAccessManager->can($access_flag, 'sms_enabled')) {
         $tempCompanyFields['sms_enabled'] = $mCompany->isSmsEnabled();
     }
     if ($mAccessManager->can($access_flag, 'email_enabled')) {
         $tempCompanyFields['email_enabled'] = $mCompany->isEmailEnabled();
     }
     $tempCompanyFields['is_active'] = $mCompany->isActive();
     $this->result['company'] = $tempCompanyFields;
 }