Example #1
0
 public function Edit($UserID)
 {
     $this->Permission('Garden.Users.Edit');
     if ($this->Head) {
         $this->Head->AddScript('/applications/garden/js/user.js');
     }
     $this->AddSideMenu('garden/user');
     $RoleModel = new Model('Role');
     $this->RoleData = $RoleModel->Get();
     $UserModel = new Gdn_UserModel();
     $this->User = $UserModel->Get($UserID);
     // Set the model on the form.
     $this->Form->SetModel($UserModel);
     // Make sure the form knows which item we are editing.
     $this->Form->AddHidden('UserID', $UserID);
     if (!$this->Form->AuthenticatedPostBack()) {
         $this->Form->SetData($this->User);
         $this->UserRoleData = $UserModel->GetRoles($UserID);
     } else {
         // If a new password was specified, add it to the form's collection
         $ResetPassword = $this->Form->GetValue('ResetPassword', FALSE);
         $NewPassword = $this->Form->GetValue('NewPassword', '');
         if ($ResetPassword !== FALSE) {
             $this->Form->SetFormValue('Password', $NewPassword);
         }
         if ($this->Form->Save(array('SaveRoles' => TRUE)) !== FALSE) {
             if ($this->Form->GetValue('Password', '') != '') {
                 $UserModel->SendPasswordEmail($UserID, $NewPassword);
             }
             $this->StatusMessage = Gdn::Translate('Your changes have been saved successfully.');
         }
         $this->UserRoleData = $this->Form->GetFormValue('RoleID');
     }
     $this->Render();
 }