public function execute()
 {
     if ($this->photo->isValid()) {
         $name = sha1($this->user->getId() . $this->user->getLogin() . $this->user->getRegisteredAt() . time() . uniqid('ffdf'));
         $photoUploader = new PhotoFormatter($this->photo->getRealPath(), self::MINIMUM_SIZE, self::MAXIMUM_SIZE, $this->output);
         $old = $this->user->getAvatar();
         $photoUploader->setNewName($name);
         $photoUploader->loadAndScale(self::START_SIZE);
         $this->user->setAvatar($name);
         $this->repository->update($this->user);
         if (!empty($old)) {
             $photoUploader->removeOld($old, self::START_SIZE);
         }
     }
 }
 public static function create(User $user, $ip, $time)
 {
     $item = new PasswordRecoveryRequest();
     $item->user = $user;
     $item->requestIp = ip2long($ip);
     $item->requestTime = $time;
     $item->provisionKey = sha1('dsSDfdjd' . rand(-2000000000, 2000000000) . 'ZSdDkjqi23df' . $item->requestIp . $time . $user->getLogin());
     return $item;
 }
 public static function forPassword(User $user, $password, $salt, $ip, $time)
 {
     $item = new CredentialChangeRequest();
     $item->user = $user;
     $item->password = $password;
     $item->salt = $salt;
     $item->requestIp = ip2long($ip);
     $item->requestTime = $time;
     $item->provisionKey = sha1('SdfFSDfdjd' . rand(-2000000000, 2000000000) . 'ZSdDkjqi23df' . $item->requestIp . $time . $user->getLogin());
     return $item;
 }