login, logout, prihlasovanie, odhlasovanie
- Václav Kraus
- Člen | 77
Presenter https://github.com/…resenter.php
Template https://github.com/…mplates/Sign
Model https://github.com/…rManager.php
Editoval Václav Kraus (1. 2. 2016 15:40)
- Václav Kraus
- Člen | 77
Ten UserManager pracuje s databází. Jména sloupců jsou konstanty té třídy
class UserManager extends Nette\Object implements Nette\Security\IAuthenticator
{
const
TABLE_NAME = 'users',
COLUMN_ID = 'id',
COLUMN_NAME = 'username',
COLUMN_PASSWORD_HASH = 'password',
COLUMN_ROLE = 'role';
tak ti stačí, když si v databázi vyrobíš tabulku users s těmito sloupci a bude to fungovat
- David Matějka
- Moderator | 6445
kasiopia napsal(a):
Chcem vložiť cez UserManager svoje username a password, aby som sa mohol prihlásiť vedeli by si mi poradiť. Ďakujem Vám všetkým za radu
https://github.com/…rManager.php#L67 ?
v sandboxu je kdyztak command na to: https://github.com/…ate-user.php
- kasiopia
- Člen | 69
Čo by som mal dať do presenteru, model mám add() a tiež formulár na registráciu
protected function createComponentRegisterForm()
{
$form = new Nette\Application\UI\Form;
$form->addText('username', 'Username:')
->setRequired('Please enter your username.');
$form->addPassword('password', 'Password:')
->setRequired('Please enter your password.');
$form->addSubmit('send', 'Register');
// call method signInFormSucceeded() on success
$form->onSuccess[] = array($this, 'registerFormSucceeded');
return $form;
}
public function registerFormSucceeded($form, $values)
{
}
Ďakujem za odpoveď
- David Matějka
- Moderator | 6445
Vyzadej si UserManager jako zavislost – https://doc.nette.org/…dependencies
- CZechBoY
- Člen | 3608
Předej si model (UserManager) do Presenteru a v té metodě registerFormSucceeded si zavolej metodu add z toho modelu.
předání modelu do presenteru (nezapomeň nahoru přidat
use App\Model\UserManager;
)
private $userManager;
public function __construct (UserManager $userManager)
{
$this->userManager = $userManager;
}
Zavolání metody UserManager::add
public function registerFormSucceeded ($form, $values)
{
$this->userManager->add($values['username'], $values['password']);
$this->flashMessage('Uživatel úspěšně registrován.', 'success');
}
- Metrix
- Člen | 8
Dobry den, tvrdnem nad tym cely den a vzdy mi vyskakuju chyby, mohli by ste
sa na to pozriet odbornym okom?
https://metrixman@bitbucket.org/…-project.git
- David Matějka
- Moderator | 6445
@Metrix ahoj, bez toho, abys nam prozradil, jake chyby ti vyskakuji, tak ti moc neporadime… a priste prosim zaloz nove tema
- Metrix
- Člen | 8
Nette\DI\ServiceCreationException
Service 'services': The item 'factory' in array expects to be callable or Nette\DI\Statement or null, array(4) given.
...\web-project\vendor\nette\di\src\DI\Compiler.php:236 source Nette\DI\Compiler::loadDefinitions(arguments)
226: . ($hint ? ", did you mean '$hint'?" : '.')
227: );
228: }
229: }
230:
231:
232: /** @internal */
233: public function processServices()
234: {
235: if (isset($this->config['services'])) {
236: self::loadDefinitions($this->builder, $this->config['services']);
237: }
238: }
239:
240:
...\web-project\vendor\nette\di\src\DI\Compiler.php:176 source Nette\DI\Compiler->processServices()
166: */
167: public function compile()
168: {
169: if (func_num_args()) {
170: trigger_error(__METHOD__ . ' arguments are deprecated, use Compiler::addConfig() and Compiler::setClassName().', E_USER_DEPRECATED);
171: $this->config = func_get_arg(0) ?: $this->config;
172: $this->className = @func_get_arg(1) ?: $this->className;
173: }
174: $this->processParameters();
175: $this->processExtensions();
176: $this->processServices();
177: $classes = $this->generateCode();
178: return implode("\n\n\n", $classes);
179: }
180:
...\nette\bootstrap\src\Bootstrap\Configurator.php:306 source Nette\DI\Compiler->compile()
296: foreach ($this->defaultExtensions as $name => $extension) {
297: list($class, $args) = is_string($extension) ? [$extension, []] : $extension;
298: if (class_exists($class)) {
299: $args = DI\Helpers::expand($args, $this->parameters, true);
300: $compiler->addExtension($name, (new \ReflectionClass($class))->newInstanceArgs($args));
301: }
302: }
303:
304: $this->onCompile($this, $compiler);
305:
306: $classes = $compiler->compile();
307: return implode("\n", $fileInfo) . "\n\n" . $classes;
308: }
309:
310:
C:\xampp\htdocs\web-project\app\bootstrap.php:20 source Nette\Configurator->createContainer()
10: $configurator->setTimeZone('Europe/Prague');
11: $configurator->setTempDirectory(__DIR__ . '/../temp');
12:
13: $configurator->createRobotLoader()
14: ->addDirectory(__DIR__)
15: ->register();
16:
17: $configurator->addConfig(__DIR__ . '/config/config.neon');
18: $configurator->addConfig(__DIR__ . '/config/config.local.neon');
19:
20: $container = $configurator->createContainer();
21:
22: return $container;
23:
a ospravedlnujem sa, ale som tu novy
- David Matějka
- Moderator | 6445
v tom kodu na bitbucketu nikde nevidim pouzuti factory
klice
v configu. nemas to v config.local.neon, ktery neni v gitu?
mozna bude lepsi zacit od zacatku:
- povedlo se ti spustit cisty web-project?
- co si kam pridal, ze to prestalo fungovat?
- David Matějka
- Moderator | 6445
jeste prosim koukni, jak formatovat kod
nemas tam mit ten druhy klic services:
, ma to byt jen
services:
- App\Model\UserManager
- App\Forms\FormFactory
- App\Forms\SignInFormFactory
- App\Forms\SignUpFormFactory
router: App\Router\RouterFactory::createRouter