/** * Validates user input in Register form and saves customer into database. */ public function execute() { $this->userVO->setEmail($this->request->getPost('email')); $this->userVO->setUserName($this->request->getPost('username')); $this->userVO->setUserPassword($this->userService->hashPassword($this->request->getPost('password'))); if ($this->validate()) { try { $this->userDAO->save($this->userVO); UserVO::setMessage('Thank you for registering on our website!'); Session::set('username', $this->userVO->getUserName()); $this->response->redirect('/'); } catch (\Exception $e) { echo $e->getMessage(); } } else { throw new \Exception('Password and Confirm Password fields should be the same.'); } }
/** * @param string $attribute * @param string $value * @return UserVO * @throws \Exception */ public function findBy(string $attribute, string $value) { $params = [$attribute => $value]; $row = $this->queryBuilder->useDatabase(Config::getDatabaseName())->select()->from(self::TABLE)->where($attribute, '=')->execute($params)->getRow(); $userVO = new UserVO(); $userVO->setEmail($row['email']); $userVO->setUserName($row['user_name']); $userVO->setUserPassword($row['user_password']); return $userVO; }