private function addEventListeners($permanentLoginExpiration) { $this->onValidate[] = function () { $values = $this->getValues(); try { $this->user->login($values->email, $values->password); $this->currentCartService->consolidateCurrentCartWithCurrentUser(); } catch (AuthenticationException $e) { $this->addError('Invalid credentials.'); } }; $this->onSuccess[] = function () use($permanentLoginExpiration) { $values = $this->getValues(); if ($values->permanent) { $this->user->setExpiration($permanentLoginExpiration, false); } else { $this->user->setExpiration(0, true); } }; }
private function registerUser(RegistrationForm $form) { $values = $form->getValues(); $user = new User($values->email, $values->password); $user->setName($values->address->name); $user->setStreet($values->address->street); $user->setCity($values->address->city); $user->setZip($values->address->zip); try { if (!$form->hasErrors()) { $this->userService->create($user); $this->flashMessage('Account has been created.'); $this->user->login($user->getEmail(), $values->password); $this->currentCartService->consolidateCurrentCartWithCurrentUser(); $this->restoreRequest($this->backlink); $this->redirect(':Front:Home:Homepage:'); } } catch (EntityDuplicateException $e) { $form->addError(sprintf('User with e-mail %s already exists.', $user->getEmail())); } }