public function onSuccess()
 {
     $v = $this->values;
     $user = $this->orm->users->getByEmail($v->email);
     if ($user && $user->registered) {
         $this->addError('duplicate');
         return;
     }
     if (!$user) {
         $user = new User();
         $user->email = $v->email;
         $this->orm->users->attach($user);
     }
     $user->gender = $v->gender;
     $user->setNames($v->name);
     $user->registered = TRUE;
     $plainHash = Passwords::hash($v->password);
     $user->password = $this->aes->encrypt($plainHash);
     $this->orm->flush();
     /** @var Auth $presenter */
     $presenter = $this->presenter;
     $presenter->user->login(new Identity($user->id));
     $this->iLog('auth.registration.password', ['entropy' => $this->entropy->compute($v->password, $user)]);
     $presenter->onLogin($user, TRUE);
 }
예제 #2
0
 public function onSuccess()
 {
     $v = $this->getValues();
     /** @var Auth $presenter */
     $presenter = $this->presenter;
     try {
         $userEntity = $this->orm->users->getByEmail($v->email);
         if ($userEntity && !$userEntity->registered) {
             $presenter->redirect('Auth:registration', ['email' => $v->email]);
         }
         $guest = NULL;
         if ($presenter->user->isPersistedGuest()) {
             // If guest user is persisted, link to it
             // locally so we dont override it with login.
             $guest = $presenter->getUserEntity();
         }
         $presenter->user->login($v->email, $v->password);
         if ($guest && $guest instanceof User) {
             $this->userMerger->mergeUserInto($guest, $presenter->getUserEntity());
             $this->orm->flush();
         }
         $presenter->onLogin($userEntity, NULL, 'password');
     } catch (AuthenticationException $e) {
         $presenter->flashError($e->getMessage());
     }
 }
예제 #3
0
 public function invoke(Presenters\Token $presenter, RepositoryContainer $orm)
 {
     $us = new Rme\Unsubscribe($this->user->email, $this->emailType);
     $orm->unsubscribes->attach($us);
     $orm->flush();
     $presenter->flashSuccess('unsubscribe');
     $presenter->redirect('Profile:');
 }
 public function invoke(Presenters\Token $presenter, RepositoryContainer $orm)
 {
     $presenter->login($this->user);
     $this->studentInvite->setAccepted();
     $orm->flush();
     $presenter->flashSuccess('student.approveMentor');
     $presenter->redirect('Profile:');
 }
 /**
  * @deprecated
  * @param string $password
  * @param $user
  * @throws AuthenticationException
  */
 private function authOldPassword($password, $user)
 {
     list($_, $hash, $salt) = explode(';', $user->password);
     if ($this->calculateHash($password, $salt) !== $hash) {
         throw new AuthenticationException('auth.flash.wrongPassword', self::INVALID_CREDENTIAL);
     }
     $plainHash = Passwords::hash($password);
     $user->password = $this->aes->encrypt($plainHash);
     $this->orm->flush();
 }
예제 #6
0
 public function invoke(RepositoryContainer $orm, Paths $paths, BlackboardPreview $generator)
 {
     $blackboards = $orm->contents->findAllBlackboards();
     foreach ($blackboards as $bb) {
         $file = $paths->getPreviews() . "/{$bb->id}.png";
         if (!file_exists($file)) {
             $generator->generate($bb, $file);
             $bb->preview = "/data/preview/{$bb->id}.png";
             $this->out->writeln("<info>Preview saved to {$file}</info>");
         }
     }
     $orm->flush();
 }
 public function onSuccess()
 {
     $v = $this->values;
     /** @var Auth $presenter */
     $presenter = $this->presenter;
     $user = $presenter->userEntity;
     $plainHash = Passwords::hash($v->password);
     $user->password = $this->aes->encrypt($plainHash);
     $this->orm->flush();
     $this->iLog('form.changePassword', ['entropy' => $this->entropy->compute($v->password, $user)]);
     $presenter->flashSuccess('auth.changePassword.success');
     $presenter->redirect('Profile:');
 }
예제 #8
0
 protected function updateDurations(RepositoryContainer $orm, Youtube $youtube)
 {
     $count = 0;
     $videos = $orm->contents->findVideosWithoutDuration();
     $progress = new ProgressBar($this->out, $videos->count());
     $progress->start();
     /** @var Video $video */
     foreach ($videos as $video) {
         $video->duration = $youtube->getDuration($video->youtubeId);
         $progress->advance();
         $count++;
     }
     $progress->finish();
     $this->out->write("\n");
     $orm->flush();
     $this->out->writeln("<info>Duration updated for {$count} videos.</info>");
 }
예제 #9
0
 public function onSuccess()
 {
     $v = $this->values;
     $user = $this->user->getUserEntity();
     $user->setNames($v->name);
     $unsubscribe = $this->orm->unsubscribes->getByEmail($user->email);
     if ($v->subscribe) {
         if ($unsubscribe) {
             $this->orm->unsubscribes->remove($unsubscribe);
         }
     } else {
         if (!$unsubscribe) {
             $unsubscribe = new Unsubscribe($user->email, 'manual-settings');
             $this->orm->unsubscribes->attach($unsubscribe);
         }
     }
     $this->orm->flush();
     $this->presenter->flashSuccess('profileForm.success');
     $this->presenter->redirect('this');
 }
 /**
  * @param callable $begin {int $count}
  * @param callable $tick {}
  * @return int
  */
 public function populate(callable $begin = NULL, callable $tick = NULL)
 {
     $counter = 0;
     /** @var Repository[] $repos */
     $repos = [];
     foreach ($this->orm->getRepositoryClasses() as $class) {
         $repo = $this->orm->getRepository($class);
         $cn = $repo->getEntityClassName();
         $classes = is_array($cn) ? $cn : [$cn];
         foreach ($classes as $entity) {
             $ref = new ClassType($entity);
             if (!$ref->implementsInterface(IIndexable::class)) {
                 continue 2;
             }
         }
         $repos[] = $repo;
     }
     $total = 0;
     foreach ($repos as $repo) {
         $total += $repo->findAll()->count();
     }
     $begin($total);
     foreach ($repos as $repo) {
         $rows = [];
         /** @var Entity|IIndexable $entity */
         foreach ($repo->findAll() as $entity) {
             $data = $entity->getIndexData();
             if ($data === FALSE) {
                 continue;
             }
             $rows[$entity->id] = $data;
             $tick();
             $counter++;
         }
         if ($rows && isset($entity)) {
             $this->es->addToIndexBulk($entity->getShortEntityName(), $rows);
         }
     }
     return $counter;
 }
예제 #11
0
 /**
  * @param string $view email template
  * @param User $user
  * @param NULL|array $args template variables
  *
  * @throws Exception from Latte\Engine
  * @throws SmtpException from Mailer
  */
 public function send($view, User $user, array $args = [])
 {
     if ($this->orm->unsubscribes->getByEmail($user->email)) {
         // Last line of defense. Make sure unsubscribed users
         // really dont receive any email. This should however
         // be handled before the task is queued.
         $this->logger->addAlert("Email to '{$user->email}' not send, user unsubscribed. Find out why it was queued");
         return;
     }
     $msg = new Message();
     $msg->setFrom('Khanova škola <*****@*****.**>');
     $msg->addReplyTo('Markéta Matějíčková <*****@*****.**>');
     $msg->addTo($user->email, $user->name);
     $token = Unsubscribe::createFromUser($user);
     $token->emailType = $view;
     $this->orm->tokens->attach($token);
     $this->orm->flush();
     $args['recipient'] = $user;
     $args['email'] = $msg;
     $args['unsubscribe'] = (object) ['token' => $token, 'code' => $token->getUnsafe()];
     $args['baseUrl'] = rtrim($this->baseUrl, '/');
     $latte = new Engine();
     /** @var Presenters\Token $presenter */
     $presenter = $this->factory->createPresenter('Token');
     $presenter->autoCanonicalize = FALSE;
     $ref = new \ReflectionProperty(Presenter::class, 'globalParams');
     $ref->setAccessible(TRUE);
     $ref->setValue($presenter, []);
     $latte->addFilter('token', function (Token $token, $unsafe) use($presenter, $view) {
         return $presenter->link('//Token:', ['token' => $token->toString($unsafe), 'utm_campaign' => "email-{$view}"]);
     });
     $latte->addFilter('vocative', function ($phrase) {
         return $this->inflection->inflect($phrase, 5);
     });
     $template = $latte->renderToString($this->getTemplate($view), $args);
     $msg->setHtmlBody($template);
     $this->mailer->send($msg);
     $this->logger->addInfo('Email send', ['view' => $view, 'email' => $user->email]);
 }
 public function onSuccess()
 {
     $v = $this->getValues();
     /** @var Auth $presenter */
     $presenter = $this->presenter;
     $userEntity = $this->orm->users->getByEmail($v->email);
     if (!$userEntity || !$userEntity->registered) {
         $this->iLog('form.resetPassword.fail', ['email' => $v->email]);
         $this->presenter->flashError('/auth.reset.notFound');
         $this->addError('/auth.reset.notFound.title');
         return;
     }
     $token = Tokens\ResetPassword::createFromUser($userEntity);
     $this->orm->tokens->persist($token);
     $this->orm->flush();
     // prevent race condition with queue
     $producer = $this->queue->getProducer('mail');
     $producer->publish(serialize(['template' => 'resetPassword', 'recipient' => new EntityPointer($userEntity), 'token' => new EntityPointer($token), 'unsafe' => $token->getUnsafe()]));
     $this->iLog('form.resetPassword.ok', ['email' => $v->email]);
     $presenter->flashSuccess('auth.reset.success');
     $presenter->redirect('this');
 }
예제 #13
0
 public function onSuccess()
 {
     $v = $this->getValues();
     /** @var Content $presenter */
     $presenter = $this->presenter;
     $comment = new Rme\Comment();
     $comment->text = $v->text;
     $comment->content = $this->content;
     $this->orm->comments->attach($comment);
     $comment->author = $presenter->getUserEntity();
     if ($v->replyTo) {
         $replyTo = $this->orm->comments->getById($v->replyTo);
         if (!$replyTo || !$this->content->comments->has($replyTo)) {
             $this->addError('invalid reply');
         }
         $comment->inReplyTo = $replyTo;
     }
     $this->orm->comments->attach($comment);
     $this->orm->flush();
     $this->iLog('form.comment');
     $presenter->flashSuccess('added');
     $presenter->redirect('this');
 }
예제 #14
0
 /**
  * @param User $teacher
  * @param string $email
  * @throws \Exception
  */
 protected function inviteUser(User $teacher, $email)
 {
     $student = $this->getOrCreateUser($email);
     if ($student->registered) {
         $token = LinkExistingStudent::createFromUser($student);
         $template = 'mentor.linkStudent.existing';
     } else {
         $token = LinkNewStudent::createFromUser($student);
         $template = 'mentor.linkStudent.new';
     }
     $invite = new StudentInvite($teacher, $student);
     $token->studentInvite = $invite;
     $this->orm->tokens->persist($token);
     $this->orm->flush();
     // prevent race condition with queue
     $teacher->studentInvitesSent->add($invite);
     $producer = $this->queue->getProducer('mail');
     $producer->publish(serialize(['template' => $template, 'recipient' => new EntityPointer($student), 'teacher' => new EntityPointer($teacher), 'token' => new EntityPointer($token), 'unsafe' => $token->getUnsafe()]));
 }
 /**
  * @param RepositoryContainer $orm
  * @return NULL|Entity
  */
 public function resolve(RepositoryContainer $orm)
 {
     return $orm->getRepository($this->repoClass)->getById($this->id);
 }
 public function invoke(Presenters\Token $presenter, RepositoryContainer $orm)
 {
     $this->studentInvite->setAccepted();
     $orm->flush();
     $presenter->redirect('Auth:registration', ['email' => $this->user->email]);
 }