Example #1
0
 /**
  * @param User $user
  * @return bool
  */
 public function sendConfirmationEmail(User $user)
 {
     // Build the message
     $this->message->setSubject('Welcome to Simple Quiz, please confirm your email address');
     $replacements = array();
     $confirmHash = sha1($user->getEmail() . mt_rand() . $user->getId());
     $replacements[$user->getEmail()] = array('{username}' => $user->getName(), '{hash}' => $confirmHash, '{sitename}' => Config::$siteurl);
     $this->decorator = new \Swift_Plugins_DecoratorPlugin($replacements);
     $this->instance->registerPlugin($this->decorator);
     $this->readFromFile('registerconfirm');
     $this->message->setTo(array($user->getEmail() => $user->getName()));
     // Send the message
     if ($this->instance->send($this->message) > 0) {
         $record = \ORM::for_table('users')->find_one($user->getId());
         $record->set('confirmhash', $confirmHash);
         $record->set_expr('hashstamp', 'now()');
         $record->save();
         return true;
     }
     return false;
 }
Example #2
0
 /**
  * @param User $user
  * @return User $user
  * @throws RegisterException
  */
 public function registerUser(User $user)
 {
     $name = $user->getName();
     $email = $user->getEmail();
     $password = $user->getPassword();
     $userexists = \ORM::for_table('users')->where_any_is(array(array('name' => $name), array('email' => $email)))->find_one();
     if ($userexists) {
         throw new RegisterException();
     } else {
         //register a new user
         $newuser = \ORM::for_table('users')->create();
         $newuser->set('name', $name);
         $newuser->set('email', $email);
         $newuser->set('pass', $password);
         $newuser->save();
         $user->setId($newuser->id());
         return $user;
     }
 }