• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Utils\Random类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Nette\Utils\Random的典型用法代码示例。如果您正苦于以下问题:PHP Random类的具体用法?PHP Random怎么用?PHP Random使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Random类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: generateToken

 /**
  * @return string
  */
 private function generateToken($random = NULL)
 {
     if ($random === NULL) {
         $random = Nette\Utils\Random::generate(10);
     }
     return $random . base64_encode(sha1($this->getToken() . $random, TRUE));
 }
开发者ID:knedle,项目名称:twitter-nette-skeleton,代码行数:10,代码来源:CsrfProtection.php


示例2: create

 public function create(Product $product, FileUpload $fileUpload)
 {
     switch ($fileUpload->getContentType()) {
         case 'image/jpeg':
             $suffix = 'jpg';
             break;
         case 'image/png':
             $suffix = 'png';
             break;
         case 'image/gif':
             $suffix = 'gif';
             break;
         default:
             throw new EntityInvalidArgumentException(sprintf('File is of an unknown type %s.', $fileUpload->getContentType()));
     }
     $baseName = sprintf('%s-%%s.%s', Strings::webalize($product->getName()), $suffix);
     do {
         $fileName = sprintf($baseName, Random::generate(5, '0-9a-zA-Z'));
         $path = sprintf('%s/%s', $this->imagesDir, $fileName);
     } while (file_exists($path));
     $fileUpload->move($path);
     $image = new ProductImage($product, $fileName);
     $this->createEntity($image);
     $product->addImage($image);
     return $image;
 }
开发者ID:shophp,项目名称:shophp,代码行数:26,代码来源:ProductImageService.php


示例3: formSucceeded

 /**
  * Callback for ForgottenPasswordForm onSuccess event.
  * @param Form      $form
  * @param ArrayHash $values
  */
 public function formSucceeded(Form $form, $values)
 {
     $user = $this->userManager->findByEmail($values->email);
     if (!$user) {
         $form->addError('No user with given email found');
         return;
     }
     $password = Nette\Utils\Random::generate(10);
     $this->userManager->setNewPassword($user->id, $password);
     try {
         // !!! Never send passwords through email !!!
         // This is only for demonstration purposes of Notejam.
         // Ideally, you can create a unique link where user can change his password
         // himself for limited amount of time, and then send the link.
         $mail = new Nette\Mail\Message();
         $mail->setFrom('[email protected]', 'Notejamapp');
         $mail->addTo($user->email);
         $mail->setSubject('New notejam password');
         $mail->setBody(sprintf('Your new password: %s', $password));
         $this->mailer->send($mail);
     } catch (Nette\Mail\SendException $e) {
         Debugger::log($e, Debugger::EXCEPTION);
         $form->addError('Could not send email with new password');
     }
 }
开发者ID:martinmayer,项目名称:notejam,代码行数:30,代码来源:ForgottenPasswordFormFactory.php


示例4: sendFormSucceeded

 function sendFormSucceeded(\Nette\Forms\BootstrapUIForm $form)
 {
     $email = $form->getValues()->email;
     if ($form->values->layer == 'admin') {
         $lostPass = $this->database->table("helpdesk_emails")->where("template", "lostpass-admin")->fetch();
     } else {
         $lostPass = $this->database->table("helpdesk_emails")->where("template", "lostpass-member")->fetch();
     }
     if (!\Nette\Utils\Validators::isEmail($email)) {
         $this->presenter->flashMessage("Adresa je neplatná");
         $this->presenter->redirect(":Front:Sign:lostpass");
     }
     $passwordGenerate = \Nette\Utils\Random::generate(12, "987654321zyxwvutsrqponmlkjihgfedcba");
     if ($this->database->table('users')->where(array('email' => $email))->count() == 0) {
         $this->flashMessage("E-mail nenalezen");
         $this->presenter->redirect(":Front:Sign:lostpass");
     }
     $member = new \App\Model\MemberModel($this->database);
     $member->setActivation($email, $passwordGenerate);
     $latte = new \Latte\Engine();
     $latte->setLoader(new \Latte\Loaders\StringLoader());
     $params = array('code' => $passwordGenerate, 'email' => $email, 'settings' => $this->presenter->template->settings);
     $mail = new \Nette\Mail\Message();
     $mail->setFrom($this->presenter->template->settings['contacts:email:hq'])->addTo($email)->setSubject("Informace o novém hesle")->setHTMLBody($latte->renderToString($lostPass->body, $params));
     $mailer = new \Nette\Mail\SendmailMailer();
     $mailer->send($mail);
     $this->presenter->flashMessage('Informace o zapomenutém hesle odeslány', 'success');
     $this->presenter->redirect(this);
 }
开发者ID:caloriscz,项目名称:caloriscms,代码行数:29,代码来源:LostPassControl.php


示例5: authenticate

 /**
  * @param array $credentials
  * @return Identity
  * @throws AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     $email = $credentials[0]['email'];
     $user = $this->users->getUser($email);
     if ($user === NULL && $this->autoRegister === FALSE || $user instanceof UserEntity && $user->getActive() == 0) {
         throw new AuthenticationException("User '{$email}' not found.", self::IDENTITY_NOT_FOUND);
     } else {
         if ($user === NULL && $this->autoRegister === TRUE) {
             $result = $this->users->register(array("login" => $email, "password" => Random::generate(), "name" => $credentials[0]['firstName'] . " " . $credentials[0]['lastName'], "firstname" => $credentials[0]['firstName'], "lastname" => $credentials[0]['lastName'], "lastLogged" => new DateTime(), "ip" => $_SERVER['REMOTE_ADDR']));
             if ($result instanceof ContactEntity) {
                 return new Identity($result->getUserID(), $result->getUser()->getRole()->getName(), $result->getUser()->toArray());
             } else {
                 throw new AuthenticationException("User '{$email}' cannot be registered.", self::IDENTITY_NOT_FOUND);
             }
         } else {
             if ($user instanceof UserEntity) {
                 $user->setLastLogged(new DateTime());
                 $user->setIp($_SERVER['REMOTE_ADDR']);
                 $this->users->updateUser($user);
                 $data = $user->toArray();
                 unset($data['password']);
                 return new Identity($user->getUserID(), $user->getRole()->getName(), $data);
             } else {
                 throw new AuthenticationException("User '{$email}' cannot be connected.", self::IDENTITY_NOT_FOUND);
             }
         }
     }
 }
开发者ID:vipercz,项目名称:sandbox,代码行数:33,代码来源:FacebookAuthenticator.php


示例6: generateHash

 protected function generateHash()
 {
     do {
         $hash = Nette\Utils\Random::generate(32);
     } while ($this->getTable()->where([$this->tables['identityHash']['hash'] => $hash])->fetch());
     return $hash;
 }
开发者ID:trejjam,项目名称:authorization,代码行数:7,代码来源:IdentityHash.php


示例7: generate

 public function generate($length = self::DEFAULT_LENGTH, $charlist = self::DEFAULT_CHARLIST)
 {
     Validators::assert($length, 'integer', 'length');
     if ($length < 1) {
         throw new InvalidArgumentException("Length must be greater or equal 1, value '{$length}' given.");
     }
     return Random::generate($length, $charlist);
 }
开发者ID:rebendajirijr,项目名称:passwords,代码行数:8,代码来源:NettePasswordManager.php


示例8: save

 /**
  * Save past text into database
  * Return generated hash
  * @param array $data
  * @return string
  */
 public function save($data)
 {
     $data->hash = Random::generate(6, '0-9a-zA-Z');
     $data->inserted = $this->dateTime->getTimestamp();
     $data->id_user = '';
     $this->dtb->table('pastes')->insert($data);
     return $data->hash;
 }
开发者ID:hadikcz,项目名称:PasteIt,代码行数:14,代码来源:PasteManager.php


示例9: nodeOpened

	/**
	 * New node is found.
	 * @return bool
	 */
	public function nodeOpened(Latte\MacroNode $node)
	{
		$this->used = TRUE;
		$node->isEmpty = FALSE;
		$node->openingCode = Latte\PhpWriter::using($node)
			->write('<?php if (Nette\Bridges\CacheLatte\CacheMacro::createCache($netteCacheStorage, %var, $_g->caches, %node.array?)) { ?>',
				Nette\Utils\Random::generate()
			);
	}
开发者ID:nakoukal,项目名称:fakturace,代码行数:13,代码来源:CacheMacro.php


示例10: macroVersion

 /**
  * generates random number for front assets versing
  */
 public function macroVersion(MacroNode $node, PhpWriter $writer)
 {
     $length = 10;
     $word = $node->tokenizer->fetchWord();
     if (is_numeric($word)) {
         $length = (int) $word;
     }
     return $writer->write(' ?>?' . Random::generate($length) . '<?php ');
 }
开发者ID:janlanger,项目名称:nette-skeleton,代码行数:12,代码来源:UIMacros.php


示例11: nodeOpened

 /**
  * New node is found.
  * @return bool
  */
 public function nodeOpened(Latte\MacroNode $node)
 {
     if ($node->modifiers) {
         throw new Latte\CompileException('Modifiers are not allowed in ' . $node->getNotation());
     }
     $this->used = TRUE;
     $node->empty = FALSE;
     $node->openingCode = Latte\PhpWriter::using($node)->write('<?php if (Nette\\Bridges\\CacheLatte\\CacheMacro::createCache($this->global->cacheStorage, %var, $this->global->cacheStack, %node.array?)) { ?>', Nette\Utils\Random::generate());
 }
开发者ID:nette,项目名称:caching,代码行数:13,代码来源:CacheMacro.php


示例12: nodeOpened

 /**
  * New node is found.
  * @return bool
  */
 public function nodeOpened(Latte\MacroNode $node)
 {
     if ($node->modifiers) {
         trigger_error("Modifiers are not allowed in {{$node->name}}", E_USER_WARNING);
     }
     $this->used = TRUE;
     $node->isEmpty = FALSE;
     $node->openingCode = Latte\PhpWriter::using($node)->write('<?php if (Nette\\Bridges\\CacheLatte\\CacheMacro::createCache($netteCacheStorage, %var, $_g->caches, %node.array?)) { ?>', Nette\Utils\Random::generate());
 }
开发者ID:4iz278,项目名称:cviceni,代码行数:13,代码来源:CacheMacro.php


示例13: createWorker

 /**
  * @return \Venne\Queue\Worker
  */
 public function createWorker()
 {
     $id = Random::generate(20);
     $this->configManager->lock();
     $data = $this->configManager->loadConfigFile();
     $data['worker'][$id] = array('id' => $id, 'state' => self::STATE_PAUSED, 'lastCheck' => null, 'lastJob' => null);
     $this->configManager->saveConfigFile($data);
     $this->configManager->unlock();
     return $this->getWokrer($id);
 }
开发者ID:venne,项目名称:venne,代码行数:13,代码来源:WorkerManager.php


示例14: computeUnsafeHash

 /**
  * @return string Password grade hash (do not store!)
  */
 protected function computeUnsafeHash()
 {
     if ($this->getValue('hash', FALSE)) {
         throw new InvalidStateException('Hash already set');
     }
     if (!$this->user) {
         throw new InvalidArgumentException();
     }
     return md5($this->createdAt->format('u') . $this->user->email) . Random::generate(15);
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:13,代码来源:Token.php


示例15: actionIn

 /**
  * @param $key
  * @throws BadRequestException
  */
 public function actionIn($key)
 {
     $response = $this->api->call('scud', "SCUD_CheckAccess/{$key}");
     if ($response['status'] === "OK") {
         $identity = new Identity(Random::generate(32));
         $this->getUser()->login($identity);
         $this->redirect("Dashboard:default");
     }
     throw new BadRequestException();
 }
开发者ID:pogodi,项目名称:Brain,代码行数:14,代码来源:ScudPresenter.php


示例16: getCsrfToken

 /**
  * Returns unique token for method and params
  * @param  string $control
  * @param  string $method
  * @param  array $params
  * @return string
  */
 public function getCsrfToken($control, $method, $params)
 {
     $session = $this->getSession('Nextras.Application.UI.SecuredLinksPresenterTrait');
     if (!isset($session->token)) {
         $session->token = Nette\Utils\Random::generate();
     }
     $params = Nette\Utils\Arrays::flatten($params);
     $params = implode('|', array_keys($params)) . '|' . implode('|', array_values($params));
     return substr(md5($control . $method . $params . $session->token . $this->getSession()->getId()), 0, 8);
 }
开发者ID:adambisek,项目名称:secured-links,代码行数:17,代码来源:SecuredLinksPresenterTrait.php


示例17: getConfirmationToken

 /**
  * @return string
  */
 private function getConfirmationToken()
 {
     $sessionSection = $this->getPresenter()->getSession('Librette.ConfirmationDialog');
     if (!isset($sessionSection->token)) {
         $sessionSection->token = Random::generate(10);
     }
     $parameters = $this instanceof Presenter ? $this->request->getParameters() : $this->getParameters();
     $signalIdentifier = [get_class($this), $this->getPresenter()->signal, $parameters];
     return substr(md5(serialize($signalIdentifier) . $sessionSection->token), 0, 10);
 }
开发者ID:librette,项目名称:confirmation-dialog,代码行数:13,代码来源:TConfirmation.php


示例18: signUpFormSucceeded

 function signUpFormSucceeded(\Nette\Forms\BootstrapUIForm $form)
 {
     $activationCode = \Nette\Utils\Random::generate(12, "987654321zyxwvutsrqponmlkjihgfedcba");
     $password = \Nette\Security\Passwords::hash($form->values->pwd);
     $arr = array("email" => $form->values->email, "username" => $form->values->username, "password" => $password, "activation" => $activationCode, "newsletter" => (bool) $form->values->newsletter, "state" => 0, "users_roles_id" => 4, "date_created" => date("Y-m-d H:i:s"));
     if ($this->presenter->template->settings['members:groups:enabled']) {
         $arr["categories_id"] = $form->values->group;
     }
     $userId = $this->database->table("users")->insert($arr);
     $this->database->table("users")->where(array("id" => $userId->id))->update(array("uid" => \Nette\Utils\Strings::padLeft($userId->id, 6, '0')));
     if ($this->template->settings['members:signup:contactEnabled']) {
         $arrContacts = array("categories_id" => 44, "users_id" => $userId, "name" => $form->values->name, "street" => $form->values->street, "city" => $form->values->city, "zip" => $form->values->zip, "countries_id" => 1);
         if ($this->presenter->template->settings['members:signup:companyEnabled']) {
             $arrContacts["company"] = $form->values->company;
             $arrContacts["vatin"] = $form->values->vatin;
             $arrContacts["vatid"] = $form->values->vatid;
         }
         $contactId = $this->database->table("contacts")->insert($arrContacts);
         $this->database->table("contacts")->get($contactId)->update(array("order" => $contactId));
     }
     if ($form->values->vatin) {
         $ares = new \h4kuna\Ares\Ares();
         $aresArr = $ares->loadData('')->toArray();
     }
     $latte = new \Latte\Engine();
     $latte->setLoader(new \Latte\Loaders\StringLoader());
     $params = array('username' => $form->values->username, 'activationCode' => $activationCode, 'settings' => $this->presenter->template->settings, 'form' => $form, 'aresArr' => $aresArr);
     $helpdesk = $this->database->table("helpdesk")->get(3);
     $helpdesk_signup_member = $helpdesk->related("helpdesk_emails", "helpdesk_id")->get(5);
     $helpdesk_signup_confirmbyadmin = $helpdesk->related("helpdesk_emails", "helpdesk_id")->get(6);
     $helpdesk_signup_adminconfirm = $helpdesk->related("helpdesk_emails", "helpdesk_id")->get(7);
     try {
         if ($this->presenter->template->settings['members:signup:confirmByAdmin']) {
             $email_signup_confirmbyamin = $latte->renderToString($helpdesk_signup_confirmbyadmin->body, $params);
             $email_signup_adminconfirm = $latte->renderToString($helpdesk_signup_adminconfirm->body, $params);
             $mail = new \Nette\Mail\Message();
             $mail->setFrom($this->presenter->template->settings['contacts:email:hq'])->addTo($form->values->email)->setHTMLBody($email_signup_confirmbyamin);
             $this->presenter->mailer->send($mail);
             $mailA = new \Nette\Mail\Message();
             $mailA->setFrom($this->presenter->template->settings['contacts:email:hq'])->addTo($this->presenter->template->settings['contacts:email:hq'])->setHTMLBody($email_signup_adminconfirm);
             $this->presenter->mailer->send($mailA);
             $this->flashMessage('Registrace byla dokončena. Po ověření Vám bude zaslán e-mail, po kterém se můžete přihlásit', 'note');
         } else {
             $email_signup_member = $latte->renderToString($helpdesk_signup_member->body, $params);
             $mail = new \Nette\Mail\Message();
             $mail->setFrom($this->presenter->template->settings['contacts:email:hq'])->addTo($form->values->email)->setHTMLBody($email_signup_member);
             $this->presenter->mailer->send($mail);
             $this->presenter->flashMessage('Vaše registrace proběhla úspěšně. Po ověření se můžete přihlásit.', 'note');
         }
         $this->presenter->redirect(":Front:Sign:ed");
     } catch (\Nette\Mail\SmtpException $e) {
         $this->presenter->flashMessage('E-mail nebyl odeslán' . $e->getMessage(), 'error');
         $this->presenter->redirect(":Front:Sign:up");
     }
 }
开发者ID:caloriscz,项目名称:caloriscms,代码行数:55,代码来源:SignUpControl.php


示例19: preparePost

 public static function preparePost($vpId = null, $authorVpId = null, $postValues = [])
 {
     if ($vpId === null) {
         $vpId = IdUtil::newId();
     }
     $post = array_merge(['post_date' => "2015-02-02 14:19:59", 'post_date_gmt' => "2015-02-02 14:19:59", 'post_modified' => '0000-00-00 00:00:00', 'post_modified_gmt' => '0000-00-00 00:00:00', 'post_content' => "Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!", 'post_title' => "Hello world!", 'post_excerpt' => "", 'post_status' => "publish", 'comment_status' => "open", 'ping_status' => "open", 'post_password' => "", 'post_name' => "hello-world", 'to_ping' => "", 'pinged' => "", 'post_content_filtered' => "", 'guid' => "http://127.0.0.1/wordpress/?p=" . Random::generate(), 'menu_order' => 0, 'post_type' => "post", 'post_mime_type' => "", 'vp_id' => $vpId, 'vp_post_parent' => 0, 'vp_post_author' => 0], $postValues);
     if ($authorVpId !== null) {
         $post['vp_post_author'] = $authorVpId;
     }
     return $post;
 }
开发者ID:versionpress,项目名称:versionpress,代码行数:11,代码来源:EntityUtils.php


示例20: formSucceeded

 public function formSucceeded($form, $values)
 {
     $user = $this->userRepository->findOneBy(['email' => $values->email]);
     if (!$user) {
         $form->addError("User with email " . $values->email . " does not exist.");
         return;
     }
     $hash = Nette\Utils\Random::generate(16);
     $this->passwordResetRepository->replace(["user_id" => $user->id, "hash" => $hash, "created" => new Nette\Utils\DateTime()]);
     $this->emailService->send($values->email, ['email' => $values->email, 'resetUrl' => $this->presenter->link("//Sign:in", ['newpasshash' => $hash])], 'passwordResetRequest.latte');
     $this->onFormSuccess($this);
 }
开发者ID:gritbox,项目名称:gritbox,代码行数:12,代码来源:SendPasswordForm.php



注:本文中的Nette\Utils\Random类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Utils\Strings类代码示例发布时间:2022-05-23
下一篇:
PHP Utils\ObjectMixin类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap