Пример #1
0
 /**
  * Performs an authentication.
  * @return Nette\Security\Identity
  * @throws Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     $user = $this->userRepository->getUserByLogin($username);
     if (!$user) {
         throw new Nette\Security\AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);
     } elseif (!Passwords::verify($password, $user->getPassword())) {
         throw new Nette\Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
     }
     $oParams = ['login' => $user->getLogin()];
     return new Nette\Security\Identity($user->getId(), $user->getRole(), $oParams);
 }
Пример #2
0
 public function registerFormSucceeded(Form $form, $values)
 {
     try {
         $user = $this->users->createEntity();
         $user->setUsername($values->name);
         $user->setPassword($values->password);
         $this->users->persist($user);
         $this->redirect('Sign:in');
     } catch (\App\Model\Repository\DuplicateNameException $e) {
         $form['username']->addError('Toto uživatelské jméno je již použité. Zvolte prosím jiné.');
     } catch (\Exception $e) {
         \Tracy\Debugger::log($e);
         $form->addError('Při registraci došlo k neočekávané chybě. Zkuste to prosím znovu.');
     }
 }
Пример #3
0
 public function processCommentForm(Form $form, $values)
 {
     $this->comment = $this->comments->createEntity();
     $user = $this->users->getByID($this->getUser()->getId());
     $this->comment->setMessage($values->message);
     $this->comment->setArticle($this->article);
     $this->comment->setUser($user);
     $this->comments->persist($this->comment);
     $this->redirect('this');
 }
Пример #4
0
 /**
  * @param int $userId
  */
 public function actionEdit($userId)
 {
     //neni-li admin, nemuze editovat ostatni
     if ($this->user->id != $userId && !$this->user->isInRole('admin')) {
         $this->flashMessage($this->translator->translate('system.requestNA'), self::MESSAGE_DANGER);
         $this->redirect('default');
     }
     $this->myUser = $this->userRepository->getUserById($userId);
     if (!$this->myUser) {
         $this->flashMessage($this->translator->translate('system.invalidId'), self::MESSAGE_DANGER);
         $this->redirect('default');
     }
     $this->template->title = $this->translator->translate('system.userProfile');
 }
Пример #5
0
 public function login(Request $request, Response $response, $args)
 {
     $this->logger->info("Login page action start");
     if ($request->getMethod() == 'POST') {
         $uri = $request->getUri();
         $data = $request->getParsedBody();
         $this->logger->info("Login with parameters POST");
         $v = new $this->validator($data);
         $v->lang('es');
         $v->rule('required', array('username', 'password'));
         if ($v->validate()) {
             $this->logger->info("Login with parameters VALIDATION PASS");
             try {
                 $this->logger->info("Login with parameters: " . $data['username'] . " - " . $data['password']);
                 $this->currentUser = UserRepository::logIn($data['username'], $data['password']);
                 if ($this->currentUser != null && $this->currentUser->isAuthenticated()) {
                     $this->flash->addMessage('info', 'Sample flash message');
                     $this->logger->info("Login successfull redirected to Home");
                     return $response->withStatus(302)->withHeader('Location', $uri->withPath(''));
                 }
             } catch (ParseException $e) {
                 ParseErrorHandler::handleParseError($e);
                 $this->flash->addMessage('error', $e->getMessage());
                 $this->logger->error("Login parse exception ·" . $e->getMessage() . " REDIRECT  Login");
                 return $response->withStatus(302)->withHeader('Location', $uri->withPath('login'));
             }
         }
         foreach ($v->errors() as $field => $errors) {
             foreach ($errors as $error) {
                 $this->flash->addMessage('error', $error);
             }
         }
         $this->logger->error("Login form validation fail·- REDIRECT  Login");
         return $response->withStatus(302)->withHeader('Location', $uri->withPath('login'));
     }
     // Get Messages
     $messages = $this->flash->getMessages();
     // Fetch Template
     $body = $this->view->fetch('login/login.twig', ['flash' => $messages]);
     $this->logger->info("Login page dispathed");
     // Write Response
     return $response->write($body);
 }
Пример #6
0
 /**
  * @param Nette\Utils\ArrayHash $values Hodnoty z formulare
  * @return boolean Editace uzivatele provedena uspesne?
  */
 protected function editUser($values)
 {
     $result = TRUE;
     $userValues = $values->user;
     $personValues = $values->person;
     try {
         /** @var User $editUser */
         $editUser = $this->repository->getUserById($values->id);
         if (!$editUser) {
             return FALSE;
         }
         // nastaveni atributu
         $editUser->setLogin($userValues->login);
         $editUser->setRole($userValues->role);
         if (!empty($userValues->password)) {
             $editUser->setPassword($userValues->password);
         }
         // osoba
         if ($editUser->person !== NULL) {
             $person = $editUser->person;
             $person->name = $personValues->name;
             $person->surname = $personValues->surname;
         } else {
             $person = new \App\Model\Entities\Person($personValues->name, $personValues->surname);
             $editUser->setPerson($person);
         }
         if ($personValues->avatar->isImage()) {
             $this->imageStorage->setPersonAvatar($person, $personValues->avatar->toImage());
         }
         // ulozeni zmeny
         $this->em->flush();
     } catch (\Exception $e) {
         \Tracy\Debugger::log($e, \Tracy\Debugger::INFO);
         $result = FALSE;
     }
     return $result;
 }
Пример #7
0
    $file = __DIR__ . $_SERVER['REQUEST_URI'];
    if (is_file($file)) {
        return false;
    }
}
require __DIR__ . '/../vendor/autoload.php';
session_start();
// Load env vars
$dotenv = new Dotenv\Dotenv(__DIR__ . '/../');
$dotenv->load();
// Get Settings
$settings = (require __DIR__ . '/../app/settings.php');
// Parse Init
\Parse\ParseClient::initialize($settings['settings']['parse']['app_id'], $settings['settings']['parse']['rest_key'], $settings['settings']['parse']['master_key'], false);
\Parse\ParseClient::setStorage(new \Parse\ParseSessionStorage());
\App\Model\Repository\UserRepository::registerSubclass();
\App\Model\Repository\AddressRepository::registerSubclass();
\App\Model\Repository\CompanyRepository::registerSubclass();
// Instantiate the app
$app = new \Slim\App($settings);
if ($settings['settings']['debug'] === true) {
    Tracy\Debugger::enable();
}
// Set up dependencies
require __DIR__ . '/../app/dependencies.php';
// Register middleware
require __DIR__ . '/../app/middleware.php';
// Register routes
require __DIR__ . '/../app/routes.php';
// Run!
$app->run();