getID() public method

Get a user by ID.
public getID ( integer $ID, string | false $DatasetType = false, array $Options = [] ) : array | object | false
$ID integer The ID of the user.
$DatasetType string | false Whether to return an array or object.
$Options array Additional options to affect fetching. Currently unused.
return array | object | false Returns the user or **false** if the user wasn't found.
 public function getValidUser($user_id, $ret_type = DATASET_TYPE_ARRAY)
 {
     $UserModel = new UserModel();
     $result = $UserModel->getID($user_id, $ret_type);
     return GetValue('Deleted', $result) === '1' ? FALSE : $result;
     // $result can still be false.
 }
 /**
  * Confirm email address is valid via sent code.
  *
  * @access public
  * @since 2.0.0
  *
  * @param int $UserID
  * @param string $EmailKey Authenticate with unique, 1-time code sent via email.
  */
 public function emailConfirm($UserID, $EmailKey = '')
 {
     $User = $this->UserModel->getID($UserID);
     if (!$User) {
         throw notFoundException('User');
     }
     $EmailConfirmed = $this->UserModel->confirmEmail($User, $EmailKey);
     $this->Form->setValidationResults($this->UserModel->validationResults());
     if ($EmailConfirmed) {
         $UserID = val('UserID', $User);
         Gdn::session()->start($UserID);
     }
     $this->setData('EmailConfirmed', $EmailConfirmed);
     $this->setData('Email', $User->Email);
     $this->render();
 }
示例#3
0
$Session = Gdn::session();
$TagCount = $this->data('RecordCount');
$Tags = $this->data('Tags');
?>
        <tbody>
        <?php 
foreach ($Tags as $Tag) {
    $CssClass = 'TagAdmin';
    $Title = '';
    $Special = FALSE;
    $type = val('Type', $Tag);
    if (empty($type)) {
        $type = t('Tag');
    }
    $userModel = new UserModel();
    $createdBy = $userModel->getID(val('InsertUserID', $Tag));
    $dateInserted = Gdn_Format::date(val('DateInserted', $Tag), '%e %b %Y');
    $count = val('CountDiscussions', $Tag, 0);
    $displayName = TagFullName($Tag);
    if (val('Type', $Tag)) {
        $Special = TRUE;
        $CssClass .= " Tag-Special Tag-{$Tag['Type']}";
        $Title = t('This is a special tag.');
    }
    ?>
            <tr id="<?php 
    echo "Tag_{$Tag['TagID']}";
    ?>
" class="<?php 
    echo $CssClass;
    ?>
 /**
  * Edit a user account.
  *
  * @since 2.0.0
  * @access public
  * @param int $UserID Unique ID.
  */
 public function edit($UserID)
 {
     $this->permission('Garden.Users.Edit');
     // Page setup
     $this->addJsFile('user.js');
     $this->title(t('Edit User'));
     $this->addSideMenu('dashboard/user');
     // Only admins can reassign roles
     $RoleModel = new RoleModel();
     $AllRoles = $RoleModel->getArray();
     $RoleData = $RoleModel->getAssignable();
     $UserModel = new UserModel();
     $User = $UserModel->getID($UserID, DATASET_TYPE_ARRAY);
     // Determine if username can be edited
     $CanEditUsername = (bool) c("Garden.Profile.EditUsernames") || Gdn::session()->checkPermission('Garden.Users.Edit');
     $this->setData('_CanEditUsername', $CanEditUsername);
     // Determine if emails can be edited
     $CanEditEmail = Gdn::session()->checkPermission('Garden.Users.Edit');
     $this->setData('_CanEditEmail', $CanEditEmail);
     // Decide if they have ability to confirm users
     $Confirmed = (bool) valr('Confirmed', $User);
     $CanConfirmEmail = UserModel::RequireConfirmEmail() && Gdn::session()->checkPermission('Garden.Users.Edit');
     $this->setData('_CanConfirmEmail', $CanConfirmEmail);
     $this->setData('_EmailConfirmed', $Confirmed);
     $User['ConfirmEmail'] = (int) $Confirmed;
     // Determine whether user being edited is privileged (can escalate permissions)
     $UserModel = new UserModel();
     $EditingPrivilegedUser = $UserModel->checkPermission($User, 'Garden.Settings.Manage');
     // Determine our password reset options
     // Anyone with user editing my force reset over email
     $this->ResetOptions = array(0 => t('Keep current password.'), 'Auto' => t('Force user to reset their password and send email notification.'));
     // Only admins may manually reset passwords for other admins
     if (checkPermission('Garden.Settings.Manage') || !$EditingPrivilegedUser) {
         $this->ResetOptions['Manual'] = t('Manually set user password. No email notification.');
     }
     // 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);
     try {
         $AllowEditing = true;
         $this->EventArguments['AllowEditing'] =& $AllowEditing;
         $this->EventArguments['TargetUser'] =& $User;
         // These are all the 'effective' roles for this edit action. This list can
         // be trimmed down from the real list to allow subsets of roles to be
         // edited.
         $this->EventArguments['RoleData'] =& $RoleData;
         $UserRoleData = $UserModel->getRoles($UserID)->resultArray();
         $RoleIDs = array_column($UserRoleData, 'RoleID');
         $RoleNames = array_column($UserRoleData, 'Name');
         $UserRoleData = arrayCombine($RoleIDs, $RoleNames);
         $this->EventArguments['UserRoleData'] =& $UserRoleData;
         $this->fireEvent("BeforeUserEdit");
         $this->setData('AllowEditing', $AllowEditing);
         $this->Form->setData($User);
         if ($this->Form->authenticatedPostBack()) {
             if (!$CanEditUsername) {
                 $this->Form->setFormValue("Name", $User['Name']);
             }
             // Allow mods to confirm/unconfirm emails
             $this->Form->removeFormValue('Confirmed');
             $Confirmation = $this->Form->getFormValue('ConfirmEmail', null);
             $Confirmation = !is_null($Confirmation) ? (bool) $Confirmation : null;
             if ($CanConfirmEmail && is_bool($Confirmation)) {
                 $this->Form->setFormValue('Confirmed', (int) $Confirmation);
             }
             $ResetPassword = $this->Form->getValue('ResetPassword', false);
             // If we're an admin or this isn't a privileged user, allow manual setting of password
             $AllowManualReset = checkPermission('Garden.Settings.Manage') || !$EditingPrivilegedUser;
             if ($ResetPassword == 'Manual' && $AllowManualReset) {
                 // If a new password was specified, add it to the form's collection
                 $NewPassword = $this->Form->getValue('NewPassword', '');
                 $this->Form->setFormValue('Password', $NewPassword);
             }
             // Role changes
             // These are the new roles the editing 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($RoleData, $RequestedRoles);
             // These roles will stay turned on regardless of the form submission contents
             // because the editing user does not have permission to modify them
             $ImmutableRoles = array_diff_key($AllRoles, $RoleData);
             $UserImmutableRoles = array_intersect_key($ImmutableRoles, $UserRoleData);
             // Apply immutable roles
             foreach ($UserImmutableRoles as $IMRoleID => $IMRoleName) {
                 $UserNewRoles[$IMRoleID] = $IMRoleName;
             }
             // Put the data back into the forum object as if the user had submitted
             // this themselves
             $this->Form->setFormValue('RoleID', array_keys($UserNewRoles));
             if ($this->Form->save(array('SaveRoles' => true)) !== false) {
                 if ($this->Form->getValue('ResetPassword', '') == 'Auto') {
                     $UserModel->PasswordRequest($User['Email']);
                     $UserModel->setField($UserID, 'HashMethod', 'Reset');
                 }
                 $this->informMessage(t('Your changes have been saved.'));
             }
             $UserRoleData = $UserNewRoles;
         }
     } catch (Exception $Ex) {
         $this->Form->addError($Ex);
     }
     $this->setData('User', $User);
     $this->setData('Roles', $RoleData);
     $this->setData('UserRoles', $UserRoleData);
     $this->render();
 }
 public function userBookmarkCount($UserID = false)
 {
     if ($UserID === false) {
         $UserID = Gdn::session()->UserID;
     }
     if (!$UserID) {
         $CountBookmarks = null;
     } else {
         if ($UserID == Gdn::session() && isset(Gdn::session()->User->CountBookmarks)) {
             $CountBookmarks = Gdn::session()->User->CountBookmarks;
         } else {
             $UserModel = new UserModel();
             $User = $UserModel->getID($UserID, DATASET_TYPE_ARRAY);
             $CountBookmarks = $User['CountBookmarks'];
         }
         if ($CountBookmarks === null) {
             $CountBookmarks = Gdn::sql()->select('DiscussionID', 'count', 'CountBookmarks')->from('UserDiscussion')->where('Bookmarked', '1')->where('UserID', $UserID)->get()->value('CountBookmarks', 0);
             Gdn::userModel()->setField($UserID, 'CountBookmarks', $CountBookmarks);
         }
     }
     $this->setData('CountBookmarks', $CountBookmarks);
     $this->setData('_Value', $CountBookmarks);
     $this->xRender('Value', 'utility', 'dashboard');
 }
示例#6
0
 /**
  * Handle flagging process in a discussion.
  */
 public function discussionController_flag_create($Sender)
 {
     // Signed in users only.
     if (!($UserID = Gdn::session()->UserID)) {
         return;
     }
     $UserName = Gdn::session()->User->Name;
     $Arguments = $Sender->RequestArgs;
     if (sizeof($Arguments) != 5) {
         return;
     }
     list($Context, $ElementID, $ElementAuthorID, $ElementAuthor, $EncodedURL) = $Arguments;
     $URL = htmlspecialchars(base64_decode(str_replace('-', '=', $EncodedURL)));
     $Sender->setData('Plugin.Flagging.Data', array('Context' => $Context, 'ElementID' => $ElementID, 'ElementAuthorID' => $ElementAuthorID, 'ElementAuthor' => $ElementAuthor, 'URL' => $URL, 'UserID' => $UserID, 'UserName' => $UserName));
     if ($Sender->Form->authenticatedPostBack()) {
         $SQL = Gdn::sql();
         $Comment = $Sender->Form->getValue('Plugin.Flagging.Reason');
         $Sender->setData('Plugin.Flagging.Reason', $Comment);
         $CreateDiscussion = c('Plugins.Flagging.UseDiscussions');
         if ($CreateDiscussion) {
             // Category
             $CategoryID = c('Plugins.Flagging.CategoryID');
             // New discussion name
             if ($Context == 'comment') {
                 $Result = $SQL->select('d.Name')->select('c.Body')->from('Comment c')->join('Discussion d', 'd.DiscussionID = c.DiscussionID', 'left')->where('c.CommentID', $ElementID)->get()->firstRow();
             } elseif ($Context == 'discussion') {
                 $DiscussionModel = new DiscussionModel();
                 $Result = $DiscussionModel->getID($ElementID);
             }
             $DiscussionName = val('Name', $Result);
             $PrefixedDiscussionName = t('FlagPrefix', 'FLAG: ') . $DiscussionName;
             // Prep data for the template
             $Sender->setData('Plugin.Flagging.Report', array('DiscussionName' => $DiscussionName, 'FlaggedContent' => val('Body', $Result)));
             // Assume no discussion exists
             $this->DiscussionID = null;
             // Get discussion ID if already flagged
             $FlagResult = Gdn::sql()->select('DiscussionID')->from('Flag fl')->where('ForeignType', $Context)->where('ForeignID', $ElementID)->get()->firstRow();
             if ($FlagResult) {
                 // New comment in existing discussion
                 $DiscussionID = $FlagResult->DiscussionID;
                 $ReportBody = $Sender->fetchView($this->getView('reportcomment.php'));
                 $SQL->insert('Comment', array('DiscussionID' => $DiscussionID, 'InsertUserID' => $UserID, 'Body' => $ReportBody, 'Format' => 'Html', 'DateInserted' => date('Y-m-d H:i:s')));
                 $CommentModel = new CommentModel();
                 $CommentModel->updateCommentCount($DiscussionID);
             } else {
                 // New discussion body
                 $ReportBody = $Sender->fetchView($this->getView('report.php'));
                 $DiscussionID = $SQL->insert('Discussion', array('InsertUserID' => $UserID, 'UpdateUserID' => $UserID, 'CategoryID' => $CategoryID, 'Name' => $PrefixedDiscussionName, 'Body' => $ReportBody, 'Format' => 'Html', 'CountComments' => 1, 'DateInserted' => date('Y-m-d H:i:s'), 'DateUpdated' => date('Y-m-d H:i:s'), 'DateLastComment' => date('Y-m-d H:i:s')));
                 // Update discussion count
                 $DiscussionModel = new DiscussionModel();
                 $DiscussionModel->updateDiscussionCount($CategoryID);
             }
         }
         try {
             // Insert the flag
             $SQL->insert('Flag', array('DiscussionID' => $DiscussionID, 'InsertUserID' => $UserID, 'InsertName' => $UserName, 'AuthorID' => $ElementAuthorID, 'AuthorName' => $ElementAuthor, 'ForeignURL' => $URL, 'ForeignID' => $ElementID, 'ForeignType' => $Context, 'Comment' => $Comment, 'DateInserted' => date('Y-m-d H:i:s')));
         } catch (Exception $e) {
         }
         // Notify users with permission who've chosen to be notified
         if (!$FlagResult) {
             // Only send if this is first time it's being flagged.
             $Sender->setData('Plugin.Flagging.DiscussionID', $DiscussionID);
             $Subject = isset($PrefixedDiscussionName) ? $PrefixedDiscussionName : t('FlagDiscussion', 'A discussion was flagged');
             $EmailBody = $Sender->fetchView($this->getView('reportemail.php'));
             $NotifyUsers = c('Plugins.Flagging.NotifyUsers', array());
             // Send emails
             $UserModel = new UserModel();
             foreach ($NotifyUsers as $UserID) {
                 $User = $UserModel->getID($UserID);
                 $Email = new Gdn_Email();
                 $Email->to($User->Email)->subject(sprintf(t('[%1$s] %2$s'), Gdn::config('Garden.Title'), $Subject))->message($EmailBody);
                 try {
                     $Email->send();
                 } catch (Exception $e) {
                     if (debug()) {
                         throw $e;
                     }
                 }
             }
         }
         $Sender->informMessage(t('FlagSent', "Your complaint has been registered."));
     }
     $Sender->render($this->getView('flag.php'));
 }
 /**
  * Render basic data about user.
  *
  * @since 2.0.?
  * @access public
  * @param int $UserID Unique ID.
  */
 public function get($UserID = false)
 {
     if (!$UserID) {
         $UserID = Gdn::session()->UserID;
     }
     if (($UserID != Gdn::session()->UserID || !Gdn::session()->UserID) && !checkPermission('Garden.Users.Edit')) {
         throw new Exception(t('You do not have permission to view other profiles.'), 401);
     }
     $UserModel = new UserModel();
     // Get the user.
     $User = $UserModel->getID($UserID, DATASET_TYPE_ARRAY);
     if (!$User) {
         throw notFoundException('User');
     }
     $PhotoUrl = $User['Photo'];
     if ($PhotoUrl && strpos($PhotoUrl, '//') == false) {
         $PhotoUrl = url('/uploads/' . changeBasename($PhotoUrl, 'n%s'), true);
     }
     $User['Photo'] = $PhotoUrl;
     // Remove unwanted fields.
     $this->Data = arrayTranslate($User, array('UserID', 'Name', 'Email', 'Photo'));
     $this->render();
 }
示例#8
0
 /**
  * Internally store the uid for the active user
  *
  * @param User $user 
  * @return void
  * @author Craig Ulliott
  */
 public static function setSessionUser(UserModel $user)
 {
     // we use the facebookID for the wib library
     self::$uid = $user->getID();
 }
示例#9
0
 /**
  * Return an array of Facebook albums owned by the given user
  *
  * @param User $user 
  * @return array
  */
 public static function getAlbums(UserModel $user)
 {
     // this method requires a session key
     if (!($session_user = self::$user)) {
         return array();
     }
     $albums = array();
     // get facebookID for the given user
     $uid = $user->getID();
     // pull albums for the given user
     try {
         $fql = 'SELECT aid, owner, cover_pid, name, size, link, description, created, modified, location FROM album WHERE owner = ' . $uid;
         $results = self::getClient()->api_client->fql_query($fql);
     } catch (Exception $e) {
         $results = array('error_code' => $e->getCode(), 'error_msg' => $e->getMessage());
     }
     // if an error occred, log it
     if (isset($results['error_code'])) {
         self::log('facebook getPhotos-' . $uid . '-' . $results['error_msg']);
     } elseif ($results) {
         foreach ($results as $row) {
             // if album is empty skip it
             if (isset($row['size']) && $row['size']) {
                 // format data how wib likes it
                 $album = array('albumID' => $row['aid'], 'coverPID' => $row['cover_pid'], 'name' => $row['name'], 'description' => $row['description'], 'location' => $row['location'], 'link' => $row['link'], 'size' => $row['size'], 'created' => $row['created']);
                 $albums[$row['aid']] = $album;
             }
         }
     }
     return $albums;
 }