コード例 #1
0
 public function initialize(IIdentity $identity)
 {
     if ($identity instanceof EntityIdentity && !$identity->isLoaded()) {
         $identity->load($this->em->getDao($identity->getEntityClass()));
     }
     return $identity;
 }
コード例 #2
0
ファイル: ExpressionVoter.php プロジェクト: zycon42/security
 private function extractRoles(IIdentity $identity)
 {
     if ($this->roleHierarchy) {
         return $this->roleHierarchy->getReachableRoles($identity->getRoles());
     }
     return $identity->getRoles();
 }
コード例 #3
0
 /**
  * @param \NetteAddons\Model\Addon
  * @param \Nette\Security\IIdentity
  * @return Form
  */
 public function create(Addon $addon, IIdentity $user)
 {
     $form = new Form();
     $form->addTextArea('message', 'Why / What?')->setRequired();
     $form->addSubmit('sub', 'Send');
     $model = $this->reports;
     $form->onSuccess[] = function (Form $form) use($model, $addon, $user) {
         $values = $form->getValues();
         $model->saveReport($user->getId(), $addon->id, $values->message);
     };
     return $form;
 }
コード例 #4
0
 /**
  * @param IIdentity
  * @return Form
  */
 public function create(IIdentity $user)
 {
     $form = new Form();
     $form->addHidden('report')->setRequired();
     $form->addTextArea('reason', 'What?')->setRequired();
     $form->addSubmit('sub', 'Zap');
     $model = $this->reports;
     $form->onSuccess[] = function (Form $form) use($model, $user) {
         $values = $form->getValues();
         $model->updateReport($values->report, $values->reason, $user->getId());
     };
     return $form;
 }
コード例 #5
0
 /**
  * @param \Nette\Security\IIdentity
  * @return \NetteAddons\Forms\Form
  */
 public function create(IIdentity $user)
 {
     $form = new Form();
     $form->addHidden('token', Strings::random());
     $form->addText('url', 'Repository URL', NULL, 256)->setAttribute('autofocus', TRUE)->setRequired();
     $form['url']->addRule(Form::PATTERN, 'Sorry, we currently support only packagist.', '(https?\\://)?packagist\\.org/packages/([a-z0-9]+(?:-[a-z0-9]+)*)/([a-z0-9]+(?:-[a-z0-9]+)*)');
     $form->addSubmit('sub', 'Load');
     $manager = $this->manager;
     $validators = $this->validators;
     $form->onSuccess[] = function (Form $form) use($manager, $validators, $user) {
         $values = $form->getValues();
         try {
             $addonEntity = $this->packagistImporter->getAddon($values['url']);
             if (!$validators->isComposerFullNameUnique($addonEntity->getComposerFullName())) {
                 $form->addError("Addon with composer name '{$addonEntity->getComposerFullName()}' already exists.");
                 return;
             }
             $addon = new Addon();
             // Back compatability
             $addon->composerFullName = $addonEntity->getComposerFullName();
             $addon->userId = $user->getId();
             $addon->shortDescription = $addonEntity->getPerex();
             $addon->type = Addon::TYPE_COMPOSER;
             $addon->defaultLicense = array();
             $addon->resources[AddonResources::RESOURCE_GITHUB] = $addonEntity->getGithub();
             $addon->resources[AddonResources::RESOURCE_PACKAGIST] = $addonEntity->getPackagist();
             $manager->storeAddon($values->token, $addon);
         } catch (\NetteAddons\Model\Importers\AddonVersionImporters\AddonNotFoundException $e) {
             $form['url']->addError("Package with URL '{$values->url}' does not exist.");
         } catch (\Exception $e) {
             $form['url']->addError('Importing failed. Try again later.');
             Debugger::log($e, Debugger::WARNING);
         }
     };
     return $form;
 }
コード例 #6
0
ファイル: UserManager.php プロジェクト: kivi8/ars-poetica
 /**
  * Generate and set new check code. Send mail for user
  * @param \Nette\Security\IIdentity $user
  * @param string $mail
  * @return string
  */
 public function changeMailSet(\Nette\Security\IIdentity $user, $mail)
 {
     $id = $user->getId();
     $name = Helper::combineUserName($user, false);
     $user->oldMail = $user->mail;
     $user->mail = $mail;
     $checkCode = $this->genCheckCode('checkCode', 6);
     $this->updateUserDat($id, ['checkCode' => $checkCode . '.newM', 'mail' => $mail]);
     (new SendMailManager())->sendNewMailCode($mail, $name, $checkCode);
     return $checkCode;
 }
コード例 #7
0
 protected function extractRoles(IIdentity $identity)
 {
     return $this->roleHierarchy->getReachableRoles($identity->getRoles());
 }
コード例 #8
0
 /**
  * Serializes the IIdentity into an array, which will then be stored in
  * the JWT access token.
  * @param IIdentity $identity
  * @return array
  */
 public function serialize(IIdentity $identity)
 {
     $jwtData['sub'] = $identity->getId();
     $jwtData['roles'] = $identity->getRoles();
     return $jwtData;
 }
コード例 #9
0
 /**
  * @param Addon
  * @param \Nette\Security\IIdentity
  */
 public function markAsDeleted(Addon $addon, \Nette\Security\IIdentity $user)
 {
     $row = $this->find($addon->id);
     if (!$row) {
         return;
     }
     $row->update(array('deletedAt' => new \DateTime(), 'deletedBy' => $user->getId()));
     $this->onAddonChange($addon);
 }
コード例 #10
0
ファイル: RoleVoter.php プロジェクト: zycon42/security
 protected function extractRoles(IIdentity $identity)
 {
     return $identity->getRoles();
 }
コード例 #11
0
 /**
  * Fills addon with values (usually from form). Those value must be already validated.
  *
  * @param \NetteAddons\Model\Addon
  * @param array
  * @param \Nette\Security\IIdentity|NULL
  * @return \NetteAddons\Model\Addon
  * @throws \NetteAddons\InvalidArgumentException
  */
 public function fillAddonWithValues(Addon $addon, array $values, IIdentity $owner = NULL)
 {
     $overWritable = array('name' => TRUE, 'shortDescription' => TRUE, 'description' => TRUE, 'descriptionFormat' => TRUE, 'demo' => TRUE, 'defaultLicense' => FALSE, 'repository' => FALSE, 'repositoryHosting' => FALSE, 'tags' => FALSE);
     $ifEmpty = array('composerFullName' => TRUE);
     if (isset($values['defaultLicense']) && is_array($values['defaultLicense'])) {
         $values['defaultLicense'] = implode(', ', $values['defaultLicense']);
     }
     if (isset($values['tags']) && is_array($values['tags'])) {
         $values['tags'] = array_map('intval', $values['tags']);
     }
     if ($owner) {
         $addon->userId = $owner->getId();
         // TODO: this is duplicity to self::import()
     }
     foreach ($overWritable as $field => $required) {
         if (!array_key_exists($field, $values)) {
             if ($required) {
                 throw new \NetteAddons\InvalidArgumentException("Values does not contain field '{$field}'.");
             }
         } else {
             $addon->{$field} = $values[$field];
         }
     }
     foreach ($ifEmpty as $field => $required) {
         if (empty($addon->{$field})) {
             if (empty($values[$field])) {
                 if ($required) {
                     throw new \NetteAddons\InvalidArgumentException("Values does not contain field '{$field}'.");
                 }
             } else {
                 $addon->{$field} = $values[$field];
             }
         }
     }
     return $addon;
 }