コード例 #1
0
ファイル: messages.php プロジェクト: nbudin/Garden
 /**
  * Add a new conversations.
  */
 public function Add($Recipient = '')
 {
     $this->Form->SetModel($this->ConversationModel);
     if ($this->Form->AuthenticatedPostBack()) {
         $RecipientUserIDs = array();
         $To = explode(',', $this->Form->GetFormValue('To', ''));
         $UserModel = new Gdn_UserModel();
         foreach ($To as $Name) {
             if (trim($Name) != '') {
                 $User = $UserModel->Get(trim($Name));
                 if (is_object($User)) {
                     $RecipientUserIDs[] = $User->UserID;
                 }
             }
         }
         $this->Form->SetFormValue('RecipientUserID', $RecipientUserIDs);
         $ConversationID = $this->Form->Save($this->ConversationMessageModel);
         if ($ConversationID !== FALSE) {
             $this->RedirectUrl = Url('messages/' . $ConversationID);
         }
     } else {
         if ($Recipient != '') {
             $this->Form->SetFormValue('To', $Recipient);
         }
     }
     $this->Render();
 }
コード例 #2
0
ファイル: class.vanillamodel.php プロジェクト: kidmax/Garden
 /**
  * Checks to see if the user is spamming. Returns TRUE if the user is spamming.
  */
 public function CheckForSpam($Type)
 {
     $Spam = FALSE;
     if (!in_array($Type, array('Comment', 'Discussion'))) {
         trigger_error(ErrorMessage(sprintf('Spam check type unknown: %s', $Type), 'VanillaModel', 'CheckForSpam'), E_USER_ERROR);
     }
     $Session = Gdn::Session();
     $CountSpamCheck = $Session->GetAttribute('Count' . $Type . 'SpamCheck', 0);
     $DateSpamCheck = $Session->GetAttribute('Date' . $Type . 'SpamCheck', 0);
     $SecondsSinceSpamCheck = time() - Format::ToTimestamp($DateSpamCheck);
     $SpamCount = Gdn::Config('Vanilla.' . $Type . '.SpamCount');
     if (!is_numeric($SpamCount) || $SpamCount < 2) {
         $SpamCount = 2;
     }
     // 2 spam minimum
     $SpamTime = Gdn::Config('Vanilla.' . $Type . '.SpamTime');
     if (!is_numeric($SpamTime) || $SpamTime < 0) {
         $SpamTime = 30;
     }
     // 30 second minimum spam span
     $SpamLock = Gdn::Config('Vanilla.' . $Type . '.SpamLock');
     if (!is_numeric($SpamLock) || $SpamLock < 30) {
         $SpamLock = 30;
     }
     // 30 second minimum lockout
     // Definition:
     // Users cannot post more than $SpamCount comments within $SpamTime
     // seconds or their account will be locked for $SpamLock seconds.
     // Apply a spam lock if necessary
     $Attributes = array();
     if ($SecondsSinceSpamCheck < $SpamLock && $CountSpamCheck >= $SpamCount && $DateSpamCheck !== FALSE) {
         // TODO: REMOVE DEBUGGING INFO AFTER THIS IS WORKING PROPERLY
         /*
         echo '<div>SecondsSinceSpamCheck: '.$SecondsSinceSpamCheck.'</div>';
         echo '<div>SpamLock: '.$SpamLock.'</div>';
         echo '<div>CountSpamCheck: '.$CountSpamCheck.'</div>';
         echo '<div>SpamCount: '.$SpamCount.'</div>';
         echo '<div>DateSpamCheck: '.$DateSpamCheck.'</div>';
         echo '<div>SpamTime: '.$SpamTime.'</div>';
         */
         $Spam = TRUE;
         $this->Validation->AddValidationResult('Body', sprintf(Gdn::Translate('You have posted %1$s times within %2$s seconds. A spam block is now in effect on your account. You must wait at least %3$s seconds before attempting to post again.'), $SpamCount, $SpamTime, $SpamLock));
         // Update the 'waiting period' every time they try to post again
         $Attributes['Date' . $Type . 'SpamCheck'] = Format::ToDateTime();
     } else {
         if ($SecondsSinceSpamCheck > $SpamTime) {
             $Attributes['Count' . $Type . 'SpamCheck'] = 1;
             $Attributes['Date' . $Type . 'SpamCheck'] = Format::ToDateTime();
         } else {
             $Attributes['Count' . $Type . 'SpamCheck'] = $CountSpamCheck + 1;
         }
     }
     // Update the user profile after every comment
     $UserModel = new Gdn_UserModel();
     $UserModel->SaveAttribute($Session->UserID, $Attributes);
     return $Spam;
 }
コード例 #3
0
ファイル: user.php プロジェクト: nbudin/Garden
 public function Edit($UserID)
 {
     $this->Permission('Garden.Users.Edit');
     $this->AddJsFile('user.js');
     $this->AddSideMenu('garden/user');
     $RoleModel = new Gdn_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 = T('Your changes have been saved successfully.');
         }
         $this->UserRoleData = $this->Form->GetFormValue('RoleID');
     }
     $this->Render();
 }
コード例 #4
0
 function ValidateOldPassword($Value, $Field, $FormPostedValues)
 {
     $OldPassword = ArrayValue('OldPassword', $FormPostedValues, '');
     $Session = Gdn::Session();
     $UserModel = new Gdn_UserModel();
     $UserID = $Session->UserID;
     return (bool) $UserModel->ValidateCredentials('', $UserID, $OldPassword);
 }