public function subscribe(User $user, $confirm_pass) { if ($user->password() == $confirm_pass) { return $this->dao->save($user); } else { throw new Exception('Senhas informadas não conferem'); } }
static function createUser($nickname, $email, $password, $role) { $pwd = Filter::encodePassword($password); $user = new User($nickname, $email, $pwd); $user->setRole($role); $userdao = new UserDao(); $u = $userdao->save($user); //invia una mail per permettere all'utente di convalidare la sua casella. $code = self::generateValidationCode($u); mail($u->getEMail(), "Iscrizione a IoEsisto", self::generateValidationMailMessage($code)); //genera una collection di preferiti require_once 'manager/CollectionManager.php'; $data = array("title" => "Preferiti", "author" => $u->getID(), "categories" => "favourites", "visible" => false, "type" => "collection"); //TODO la collection viene creata nel db ma da fatal error, forse il problema è nell'override di setContent dove controlla che si stia inserendo un post ma il contenuto è false //CollectionManager::createCollection($data); //TODO creare MailManager //genera tre directory email: mailbox, cestino e spam //require_once("manager/MailManager.php"); //MailManager::createDirectory(MAILBOX, $u->getID()); //MailManager::createDirectory(TRASH, $u->getID()); //MailManager::createDirectory(SPAM, $u->getID()); return $u; }
} } public function save($userName, $userPwd) { try { $sql = "insert into user values(?,?,?)"; //set the time format $rTime = date("Y-m-d h:i:s"); //begin the transaction $this->pdo->beginTransaction(); $stmt = $this->pdo->prepare($sql); $stmt->bindParam(1, $userName, PDO::PARAM_STR); $stmt->bindParam(2, $userPwd, PDO::PARAM_STR); $stmt->bindParam(3, $rTime, PDO::PARAM_STR); $stmt->execute(); //there is no tips when occures the commit $this->pdo->commit(); //show results //$this->testConn(); //close the database $this->dbUtil->close(); } catch (PDOException $e) { echo date("Y-m-d h:i:s") . " :Fail:" . $e->getMessage(); } } } //main test $userDao = new UserDao(); //$userDao->testConn(); $userDao->save('matrix', '121550');
<?php $errors = array(); $User = null; $edit = array_key_exists('id', $_GET); if ($edit) { $User = Utils::getUserByGetId(); } else { // set defaults $User = new User(); //$User->setDate(new DateTime()); } if (array_key_exists('cancel', $_POST)) { } elseif (array_key_exists('save', $_POST)) { $data = array('email' => $_POST['Users']['email'], 'password' => $_POST['Users']['password']); // map UserMapper::map($User, $data); // validate $errors = UserValidator::validate($User); // validate if (empty($errors)) { // save $dao = new UserDao(); $User = $dao->save($User); Flash::addFlash('Success Booking :)'); // redirect Utils::redirect('home'); } }
<?php //status of list $status = Utils::getUrlParam('status'); //command $cmd = Utils::getUrlParam('cmd'); $flightBooking = Utils::getUserByGetId(); $flightBooking->setStatus($cmd); $dao = new UserDao(); $dao->save($flightBooking); $msg = ''; if ($cmd === User::VOIDED) { $smg = 'User deleted successfully.'; } else { $smg = 'User changed successfully.'; } Flash::addFlash($smg); Utils::redirect('list', array('status' => $status));
<?php $errors = array(); $user = null; $edit = array_key_exists('id', $_GET); if ($edit) { $user = Utils::getUserByGetId(); } else { $user = new User(); } if (array_key_exists('cancel', $_POST)) { } elseif (array_key_exists('save', $_POST)) { $data = array('first_name' => $_POST['user']['first_name'], 'user_password' => $_POST['user']['user_password']); // map UserMapper::map($user, $data); // validate $errors = UserValidator::validate($user); // validate if (empty($errors)) { // save $dao = new UserDao(); $user = $dao->save($user); Flash::addFlash('Success sign in :)'); // redirect Utils::redirect('home'); } }