/**
  * Create a new user
  * @param array $exclude Attributes not to set
  * @param \PDO $db Database connection to use, default to master resource
  * @return boolean
  */
 public function Create($exclude = array(), &$db = FALSE)
 {
     // Set random password
     $this->iset('password', \Sonic\Resource\Crypt::_randomPassword());
     // Begin transaction
     $this->db->beginTransaction();
     // Call parent method
     if (!parent::Create($exclude, $db)) {
         $this->db->rollBack();
         return FALSE;
     }
     // Send email
     $email = new \Sonic\Resource\Email();
     $email->setPHPMail();
     $email->addHTML("\n\t\t\t<p style='font-family:Arial;font-size:12px;'>Your admin login details for <a href=\"" . URL_ROOT . "admin\">" . URL_ROOT . "admin</a> are:<br />\n\t\t\tUsername: "******"<br />\n\t\t\tPassword: "******"</p>\n\t\t");
     $email->addRecipient($this->iget('email'), $this->iget('first_name') . ' ' . $this->iget('last_name'));
     if (!$email->Send(EMAIL_FROM, 'Admin Account Login')) {
         $this->db->rollBack();
         new \Sonic\Message('error', 'Unable to send registration email. The user was not created');
         return FALSE;
     }
     // Commit
     $this->db->commit();
     // Return TRUE
     return TRUE;
 }
示例#2
0
 /**
  * Crypt
  */
 public function crypt()
 {
     // Set variables
     $original = '';
     $type = '';
     $crypt = '';
     // If the form is submitted
     if (isset($_POST['crypt'])) {
         // Get variables
         $original = $_POST['original'];
         $type = $_POST['type'];
         // Crypt
         switch ($type) {
             case 'md5':
                 $crypt = md5($original);
                 break;
             case 'sha1':
                 $crypt = sha1($original);
                 break;
             case 'sha256':
                 $crypt = \Sonic\Resource\Crypt::_sha256($original);
                 break;
             case 'bcrypt':
                 $crypt = \Sonic\Resource\User::_Hash($original);
                 break;
         }
     }
     // Set template variables
     $this->view->assign('original', $original);
     $this->view->assign('type', $type);
     $this->view->assign('crypt', $crypt);
     $this->view->assign('options', ['bcrypt' => 'bcrypt', 'md5' => 'md5', 'sha1' => 'sha1', 'sha256' => 'sha256']);
 }