Esempio n. 1
0
 public function confirmAction()
 {
     $this->title = "You have confirmed your email";
     $mapper = new Application_Model_EmailHashMapper();
     $hashHash = addslashes($this->getRequest()->getParam('hash'));
     $hash = new Application_Model_EmailHash();
     $mapper->find($hashHash, $hash);
     if ($hash->getCookie() != null) {
         $this->view->hash = $hash;
         $cookieObj = $hash->fetchCookieObject();
         $cookieObj->setEmail($hash->getEmail());
         $cookieMapper = new Application_Model_CookieMapper();
         $cookieMapper->save($cookieObj);
     } else {
         $this->view->hash = false;
     }
 }
Esempio n. 2
0
 public function processCommand($vals)
 {
     /*******************************************************
      * Do things like allow the user to set a /nick.
      * and other special commands.
      *
      * $vals['content'] is the command itself.
      * $vals['cookieObject'] is the cookie.
      */
     $commandStr = substr($vals['content'], 1);
     $params = explode(" ", $commandStr);
     $command = array_shift($params);
     $cookie = $vals['cookieObject'];
     switch ($command) {
         /**************************************************
          * change Nickname command.
          */
         case "nick":
             if (sizeof($params) <= 0) {
                 return "Your nick is currently " . $cookie->getNick();
             }
             $x = implode(" ", $params);
             $x = preg_replace("/[^A-Za-z0-9\\ \\_\\-]/", "", $x);
             if (strlen($x) < 2) {
                 return "Nicks must be 2 chars or more";
             }
             $cookie->setNick($x);
             $mapper = new Application_Model_CookieMapper();
             $mapper->save($cookie);
             return "Changed nick to {$x}";
             /**************************************************
              * Save your session to resume it later! Oooh!
              */
         /**************************************************
          * Save your session to resume it later! Oooh!
          */
         case "password":
         case "pass":
         case "save":
             if ($cookie->getEmail() == null || $cookie->getEmail() == "") {
                 return "You must first set an email address before you can save";
             }
             if (sizeof($params) <= 0) {
                 return "You must provide a password to save with";
             }
             $password = $params[0];
             if (isset($params[1])) {
                 if ($password != $params[1]) {
                     return "Password and confirm don't match";
                 }
             }
             $oldPassword = $cookie->getPassword();
             $mapper = new Application_Model_CookieMapper();
             $cookie = $mapper->duplicate($cookie);
             //Save session as backup!
             $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
             $opts = $bootstrap->getOptions();
             $salt = $opts['webace']['saveSessionPasswordSalt'];
             $encPassword = md5($salt . $password);
             $cookie->setPassword($encPassword);
             $mapper->save($cookie);
             if ($oldPassword) {
                 return "Changed session password, use new password in future";
             }
             return "Session saved, resume with /load [email@address.com] [password]";
             /***************************************************
              * Resuming your session
              */
         /***************************************************
          * Resuming your session
          */
         case "resume":
         case "load":
         case "login":
             if (sizeof($params) < 2) {
                 return "To load a session you need to provide an email address and password";
             }
             $email = $params[0];
             $password = $params[1];
             $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
             $opts = $bootstrap->getOptions();
             $salt = $opts['webace']['saveSessionPasswordSalt'];
             $encPassword = md5($salt . $password);
             $mapper = new Application_Model_CookieMapper();
             $cookie = $mapper->findFromPassword($email, $encPassword);
             if ($cookie == null) {
                 return "Can't find session with that email/password";
             } else {
                 $newcookie = $mapper->duplicate($cookie);
                 $mapper->save($newcookie);
                 setcookie('cookieKey', $newcookie->getId(), time() + 7 * 24 * 60 * 60, "/");
                 $_POST['cookieKey'] = $newcookie->getId();
                 return "Restored session, welcome back " . $cookie->getNick();
             }
             /**************************************************
              * Log out
              */
         /**************************************************
          * Log out
          */
         case "logout":
             $cookie = Application_Model_Cookie::makeNewCookie();
             return "Logged out. You now have a new anonymous ID.";
             /**************************************************
              * Attach email address command.
              */
         /**************************************************
          * Attach email address command.
          */
         case "email":
             if (sizeof($params) <= 0) {
                 $cookie->setEmail("");
                 $mapper = new Application_Model_CookieMapper();
                 $mapper->save($cookie);
                 return "Reset your email attachment, no longer attached to email.";
             }
             $x = $params[0];
             $validator = new Zend_Validate_EmailAddress();
             if ($validator->isValid($x)) {
                 // email appears to be valid
                 $nick = $cookie->getNick();
                 //Create the confirmation hash
                 $hash = new Application_Model_EmailHash();
                 $hash->setCookie($cookie->getId());
                 $hash->setEmail($x);
                 $mapper = new Application_Model_EmailHashMapper();
                 $mapper->save($hash);
                 //What's the email look like?
                 $emailBody = "Hi there!\n\nYou (or someone pretending to be you) asked webace to confirm your email. Click here to confirm this is really you:\nhttp://webace.dalliance.net/Email/confirm?hash=" . $hash->getHash() . "\n\nIf it was't you, sorry. Ignore this.";
                 //Send off the confirmation
                 $mail = new Zend_Mail();
                 $mail->setBodyText($emailBody)->setFrom('*****@*****.**', 'WebAce')->addTo($x, $nick)->setSubject("Confirm your email address for webace {$nick}");
                 $mail->send();
                 return "Sent confirmation email to " . htmlentities($x) . " -> It'll probably be in your <b>spam folder</b> soon.";
             } else {
                 return htmlentities($x) . " isn't a valid email address.";
             }
             /**************************************************
              * Set display mode command.
              */
         /**************************************************
          * Set display mode command.
          */
         case "mode":
             if (sizeof($params) == 0) {
                 return "Current displaymode is " . $cookie->getDisplayMode() . "(" . $cookie->getDisplayModeName() . ")";
             }
             //Some names for the modes:
             if (strcasecmp($params[0], "page") == 0) {
                 $params[0] = 0;
             }
             if (strcasecmp($params[0], "single-page") == 0) {
                 $params[0] = 0;
             }
             if (strcasecmp($params[0], "domain") == 0) {
                 $params[0] = 1;
             }
             if (strcasecmp($params[0], "whole-domain") == 0) {
                 $params[0] = 1;
             }
             if (strcasecmp($params[0], "net") == 0) {
                 $params[0] = 2;
             }
             if (strcasecmp($params[0], "internet") == 0) {
                 $params[0] = 2;
             }
             if (strcasecmp($params[0], "whole-internet") == 0) {
                 $params[0] = 2;
             }
             if (strcasecmp($params[0], "whole-net") == 0) {
                 $params[0] = 2;
             }
             $x = (int) $params[0];
             $cookie->setDisplayMode($x);
             $mapper = new Application_Model_CookieMapper();
             $mapper->save($cookie);
             return "Changed displaymode changed to {$x} (" . $cookie->getDisplayModeName() . ")";
     }
     /*endSwitch*/
     return "Unknown Command {$command}";
 }