コード例 #1
0
 /**
  * Start a new conversation.
  *
  * @since 2.0.0
  * @access public
  *
  * @param string $Recipient Username of the recipient.
  */
 public function Add($Recipient = '')
 {
     $this->Form->SetModel($this->ConversationModel);
     if ($this->Form->AuthenticatedPostBack()) {
         $RecipientUserIDs = array();
         $To = explode(',', $this->Form->GetFormValue('To', ''));
         $UserModel = new UserModel();
         foreach ($To as $Name) {
             if (trim($Name) != '') {
                 $User = $UserModel->GetByUsername(trim($Name));
                 if (is_object($User)) {
                     $RecipientUserIDs[] = $User->UserID;
                 }
             }
         }
         $this->Form->SetFormValue('RecipientUserID', $RecipientUserIDs);
         $ConversationID = $this->Form->Save($this->ConversationMessageModel);
         if ($ConversationID !== FALSE) {
             $Target = $this->Form->GetFormValue('Target', 'messages/' . $ConversationID);
             $this->RedirectUrl = Url($Target);
         }
     } else {
         if ($Recipient != '') {
             $this->Form->SetValue('To', $Recipient);
         }
     }
     if ($Target = Gdn::Request()->Get('Target')) {
         $this->Form->AddHidden('Target', $Target);
     }
     $this->Title(T('New Conversation'));
     $this->SetData('Breadcrumbs', array(array('Name' => T('Inbox'), 'Url' => '/messages/inbox'), array('Name' => $this->Data('Title'), 'Url' => 'messages/add')));
     $this->Render();
 }
コード例 #2
0
 /**
  * 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 UserModel();
         foreach ($To as $Name) {
             if (trim($Name) != '') {
                 $User = $UserModel->GetByUsername(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();
 }
コード例 #3
0
 /**
  * Handle discussion option menu Change Author action.
  */
 public function DiscussionController_Author_Create($Sender, $Args)
 {
     $DiscussionID = $Sender->Request->Get('discussionid');
     $Discussion = $Sender->DiscussionModel->GetID($DiscussionID);
     if (!$Discussion) {
         throw NotFoundException('Discussion');
     }
     // Check edit permission
     $Sender->Permission('Vanilla.Discussions.Edit', TRUE, 'Category', $Discussion->PermissionCategoryID);
     if ($Sender->Form->AuthenticatedPostBack()) {
         // Change the author
         $Name = $Sender->Form->GetFormValue('Author', '');
         $UserModel = new UserModel();
         if (trim($Name) != '') {
             $User = $UserModel->GetByUsername(trim($Name));
             if (is_object($User)) {
                 if ($Discussion->InsertUserID == $User->UserID) {
                     $Sender->Form->AddError('That user is already the discussion author.');
                 } else {
                     // Change discussion InsertUserID
                     $Sender->DiscussionModel->SetField($DiscussionID, 'InsertUserID', $User->UserID);
                     // Update users' discussion counts
                     $Sender->DiscussionModel->UpdateUserDiscussionCount($Discussion->InsertUserID);
                     $Sender->DiscussionModel->UpdateUserDiscussionCount($User->UserID, TRUE);
                     // Increment
                     // Go to the updated discussion
                     Redirect(DiscussionUrl($Discussion));
                 }
             } else {
                 $Sender->Form->AddError('No user with that name was found.');
             }
         }
     } else {
         // Form to change the author
         $Sender->SetData('Title', $Discussion->Name);
     }
     $Sender->Render('changeauthor', '', 'plugins/AuthorSelector');
 }
コード例 #4
0
 public function get_user_id_by_username($user_login)
 {
     // Read the user_id for this login
     $UserModel = new UserModel();
     $result = $UserModel->GetByUsername($user_login, DATASET_TYPE_ARRAY);
     return GetValue('Deleted', $result) === '1' ? FALSE : GetValue('UserID', $result);
 }
コード例 #5
0
 public function Authenticate()
 {
     if (!$this->Request->IsPostBack()) {
         throw ForbiddenException($this->Request->RequestMethod());
     }
     $Args = array_change_key_case($this->Form->FormValues());
     $UserModel = new UserModel();
     // Look up the user.
     $User = NULL;
     if ($Email = GetValue('email', $Args)) {
         $User = $UserModel->GetByEmail($Email);
     } elseif ($Name = GetValue('name', $Args)) {
         $User = $UserModel->GetByUsername($Name);
     } else {
         throw new Gdn_UserException("One of the following parameters required: Email, Name.", 400);
     }
     if (!$User) {
         throw NotFoundException('User');
     }
     // Check the password.
     $PasswordHash = new Gdn_PasswordHash();
     $Password = $this->Form->GetFormValue('Password');
     try {
         $PasswordChecked = $PasswordHash->CheckPassword($Password, GetValue('Password', $User), GetValue('HashMethod', $User));
         // Rate limiting
         Gdn::UserModel()->RateLimit($User, $PasswordChecked);
         if ($PasswordChecked) {
             $this->SetData('User', ArrayTranslate((array) $User, array('UserID', 'Name', 'Email', 'PhotoUrl')));
             if (GetValue('session', $Args)) {
                 Gdn::Session()->Start($this->Data('User.UserID'));
                 $this->SetData('Cookie', array(C('Garden.Cookie.Name') => $_COOKIE[C('Garden.Cookie.Name')]));
             }
         } else {
             throw new Exception(T('Invalid password.'), 401);
             // Can't be a user exception.
         }
     } catch (Gdn_UserException $Ex) {
         $this->Form->AddError($Ex);
     }
     $this->Render();
 }
コード例 #6
0
 /**
  * Start a new conversation.
  *
  * @since 2.0.0
  * @access public
  *
  * @param string $Recipient Username of the recipient.
  */
 public function Add($Recipient = '')
 {
     $this->Permission('Conversations.Conversations.Add');
     $this->Form->SetModel($this->ConversationModel);
     // Set recipient limit
     if (!CheckPermission('Garden.Moderation.Manage') && C('Conversations.MaxRecipients')) {
         $this->AddDefinition('MaxRecipients', C('Conversations.MaxRecipients'));
         $this->SetData('MaxRecipients', C('Conversations.MaxRecipients'));
     }
     if ($this->Form->AuthenticatedPostBack()) {
         $RecipientUserIDs = array();
         $To = explode(',', $this->Form->GetFormValue('To', ''));
         $UserModel = new UserModel();
         foreach ($To as $Name) {
             if (trim($Name) != '') {
                 $User = $UserModel->GetByUsername(trim($Name));
                 if (is_object($User)) {
                     $RecipientUserIDs[] = $User->UserID;
                 }
             }
         }
         // Enforce MaxRecipients
         if (!$this->ConversationModel->AddUserAllowed(0, count($RecipientUserIDs))) {
             // Reuse the Info message now as an error.
             $this->Form->AddError(sprintf(Plural($this->Data('MaxRecipients'), "You are limited to %s recipient.", "You are limited to %s recipients."), C('Conversations.MaxRecipients')));
         }
         $this->EventArguments['Recipients'] = $RecipientUserIDs;
         $this->FireEvent('BeforeAddConversation');
         $this->Form->SetFormValue('RecipientUserID', $RecipientUserIDs);
         $ConversationID = $this->Form->Save($this->ConversationMessageModel);
         if ($ConversationID !== FALSE) {
             $Target = $this->Form->GetFormValue('Target', 'messages/' . $ConversationID);
             $this->RedirectUrl = Url($Target);
         }
     } else {
         if ($Recipient != '') {
             $this->Form->SetValue('To', $Recipient);
         }
     }
     if ($Target = Gdn::Request()->Get('Target')) {
         $this->Form->AddHidden('Target', $Target);
     }
     Gdn_Theme::Section('PostConversation');
     $this->Title(T('New Conversation'));
     $this->SetData('Breadcrumbs', array(array('Name' => T('Inbox'), 'Url' => '/messages/inbox'), array('Name' => $this->Data('Title'), 'Url' => 'messages/add')));
     $this->Render();
 }