/**
  * Create a user.
  *
  * @since 2.0.0
  * @access public
  */
 public function add()
 {
     $this->permission('Garden.Users.Add');
     // Page setup
     $this->addJsFile('user.js');
     $this->title(t('Add User'));
     $this->addSideMenu('dashboard/user');
     $RoleModel = new RoleModel();
     $AllRoles = $RoleModel->getArray();
     $RoleData = $RoleModel->GetAssignable();
     // By default, people with access here can freely assign all roles
     $this->RoleData = $RoleData;
     $UserModel = new UserModel();
     $this->User = false;
     // Set the model on the form.
     $this->Form->setModel($UserModel);
     try {
         // These are all the 'effective' roles for this add action. This list can
         // be trimmed down from the real list to allow subsets of roles to be edited.
         $this->EventArguments['RoleData'] =& $this->RoleData;
         $this->fireEvent("BeforeUserAdd");
         if ($this->Form->authenticatedPostBack()) {
             // These are the new roles the creating user wishes to apply to the target
             // user, adjusted for his ability to affect those roles
             $RequestedRoles = $this->Form->getFormValue('RoleID');
             if (!is_array($RequestedRoles)) {
                 $RequestedRoles = array();
             }
             $RequestedRoles = array_flip($RequestedRoles);
             $UserNewRoles = array_intersect_key($this->RoleData, $RequestedRoles);
             // Put the data back into the forum object as if the user had submitted
             // this themselves
             $this->Form->setFormValue('RoleID', array_keys($UserNewRoles));
             $NewUserID = $this->Form->save(array('SaveRoles' => true, 'NoConfirmEmail' => true));
             if ($NewUserID !== false) {
                 $Password = $this->Form->getValue('Password', '');
                 $UserModel->sendWelcomeEmail($NewUserID, $Password, 'Add');
                 $this->informMessage(t('The user has been created successfully'));
                 $this->RedirectUrl = url('dashboard/user');
             }
             $this->UserRoleData = $UserNewRoles;
         } else {
             // Set the default roles.
             $this->UserRoleData = RoleModel::getDefaultRoles(RoleModel::TYPE_MEMBER);
         }
     } catch (Exception $Ex) {
         $this->Form->addError($Ex);
     }
     $this->render();
 }