private function doRegister() { try { $userRepository = new UserRepository($this->storage); $user = UserFactory::create(new UniqueId(), $this->request->get('name'), $this->request->get('email'), $this->request->get('password'), new UserGroups($this->storage)); $userRepository->insert($user); } catch (DataNotValid $e) { return $this->returnErrorMessages(['field' => $e->getFieldName(), 'message' => $e->getMessage()]); } return $this->app->redirect('/groups/index'); }
public function getById($id) : GroupEntity { $result = $this->storage->query(function ($pdo, $operations) use($id) { $dbClass = $operations . '\\FetchData'; $columns = ['owner_id', 'name']; return $dbClass::getByField($pdo, $columns, 'group', 'id', $id); }); $userRepository = new User($this->storage); $owner = $userRepository->getById($result['owner_id']); $id = new UniqueId($id); return new GroupEntity($id, $owner, new GroupName($result['name']), new Fiches($this->storage)); }
private function doLogin() { $user = null; try { $userRepository = new UserRepository($this->storage); $user = $userRepository->getByEmail($this->request->get('email')); } catch (RecordNotExists $e) { return $this->returnErrorMessages(['field' => 'email', 'message' => 'Email address is not exists']); } if (password_verify($this->request->get('password'), $user->getPassword())) { return $this->returnErrorMessages(['field' => 'password', 'message' => 'Password is wrong']); } $this->setCurrentUser($user); return $this->app->redirect('/groups/index'); }