Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for Qt

Portal user info

Sample Viewer View Sample on GitHub

This sample demonstrates how to retrieve a user's details via a Portal.

How it works

  1. A Portal is created, and supplied a Credential which uses OAuth in user mode.
  2. When the app launches, the portal is loaded, which triggers an authentication challenge.
  3. An AuthenticationView listens to the challenge and displays a login screen to allow user credentials to be entered.
  4. If the portal is successfully loaded, the portalUser property is used to populate a series of fields including:
  • fullName
  • username
  • email
  • description
  • access
  1. The thumbnailUrl property is bound to a QML Image to display the user's avatar.
  2. Similarly, the portalInfo property is used to populate:
  • organizationName
  • organizationDescription
  • thumbnailUrl
  • canSearchPublic
  • canSharePublic

Relevant API

  • AuthenticationManager
  • AuthenticationView
  • Credential
  • PortalInfo
  • PortalUser

About the data

This sample signs into your ArcGIS online account and displays the user's profile information.

Tags

account, avatar, bio, cloud and portal, email, login, picture, profile, user, username

Sample Code

import QtQuick 2.6
import QtQuick.Controls 2.2
import Esri.ArcGISRuntime 100.9
import Esri.ArcGISRuntime.Toolkit.Dialogs 100.9

Rectangle {
    id: rootRectangle
    clip: true
    width: 800
    height: 600
    
    readonly property var detailNames: ["Full name", "Username", "Email", "Bio", "Who can see your profile?"]
    readonly property var detailValue: ["fullName", "username", "email", "userDescription", "access"]
    readonly property var infoLabels: ["Description", "Can Find External Content", "Can Share Items Externally"]
    readonly property var infoValues: ["organizationDescription", "canSearchPublic", "canSharePublic"]
    property var user: portal.portalUser

    BusyIndicator {
        id: loadingIndicator
        anchors.centerIn: parent
        running: portal.loadStatus !== Enums.LoadStatusLoaded
    }

    Column {
        id: userDetailsColumn
        visible: portal.loadStatus === Enums.LoadStatusLoaded
        anchors {
            top: parent.top
            left: parent.left
            right: parent.right
            margins: 10
        }
        spacing: 10

        Text {
            text: user ? user.fullName + " Profile" : ("????")
            font.bold: true
            font.pointSize: 15
        }

        Image {
            source : user && user.thumbnailUrl.toString().length > 0 ? user.thumbnailUrl : "qrc:/Samples/CloudAndPortal/PortalUserInfo/placeholder_img.png"
            height: 32
            width: 32
        }
    }

    ListView {
        id: userList
        visible: portal.loadStatus === Enums.LoadStatusLoaded
        anchors {
            top: userDetailsColumn.bottom;
            bottom: midLine.top
            left: parent.left;
            right: parent.right;
            margins: 10
        }
        spacing: 10
        clip: true
        model: detailNames.length

        delegate: Column {
            Text {
                text: detailNames[index]
                font.bold: true
            }

            Text {
                text: {
                    if (!user)
                        return "????";

                    if(detailValue[index] !== "access")
                        return user[detailValue[index]];

                    if (user.access === Enums.PortalAccessOrganization)
                        return "Organization";
                    else if (user.access === Enums.PortalAccessPrivate)
                        return "Only you";
                    else if (user.access === Enums.PortalAccessPublic)
                        return "Everyone";
                    else if (user.access === Enums.PortalAccessShared)
                        return "Shared Groups";
                    return "????";
                }
                color: "grey"
            }
        }
    }

    Rectangle {
        id: midLine
        anchors {
            verticalCenter: parent.verticalCenter
            margins: 8
            left: parent.left
            right: parent.right
        }
        height: 4
        visible: portal.loadStatus === Enums.LoadStatusLoaded
        color: "lightgrey"
    }

    Column {
        id: portalDetailsColumn
        visible: portal.loadStatus === Enums.LoadStatusLoaded
        anchors {
            top: midLine.bottom
            left: parent.left
            right: parent.right
            margins: 10
        }
        spacing: 10

        Text {
            text: portal.portalInfo ? portal.portalInfo.organizationName : ""
            font.bold: true
            font.pointSize: 15
        }

        Image {
            source : portal.portalInfo ? portal.portalInfo.thumbnailUrl : ""
            height: 32
            width: 32
        }
    }

    ListView {
        id: infoList
        visible: portal.loadStatus === Enums.LoadStatusLoaded
        anchors {
            top: portalDetailsColumn.bottom
            bottom: parent.bottom
            left: parent.left
            right: parent.right
            margins: 10
        }
        spacing: 10
        clip: true
        model: infoValues.length

        delegate: Column {
            Text {
                text: portal.portalInfo ? infoLabels[index] : ""
                font.bold: true
            }

            Text {
                text: portal.portalInfo ? portal.portalInfo[infoValues[index]] : ""
                color: "grey"
            }
        }
    }

    //! [PortalUserInfo create portal]
    Portal {
        id: portal
        credential: Credential {
            oAuthClientInfo: OAuthClientInfo {
                oAuthMode: Enums.OAuthModeUser
                clientId: "iLkGIj0nX8A4EJda"
            }
        }

        Component.onCompleted: load();

        onLoadStatusChanged: {
            if (loadStatus === Enums.LoadStatusFailedToLoad)
                retryLoad();
        }
    }

    /* Uncomment this section when running as standalone application
    AuthenticationView {
        id: authView
        authenticationManager: AuthenticationManager
    }
    */
    //! [PortalUserInfo create portal]
}