<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- users.qdoc --> <title>Enginio QML Examples - Users | Enginio Manual 1.6.3</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td >Qt 1.6</td><td ><a href="enginio-index.html">Enginio Manual</a></td><td >Enginio QML Examples - Users</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right"><a href="enginio-index.html">Qt 1.6.3 Reference Documentation</a></td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"> <div class="toc"> <h3><a name="toc">Contents</a></h3> <ul> <li class="level1"><a href="#introduction">Introduction</a></li> <li class="level1"><a href="#general-example-structure">General Example Structure</a></li> <li class="level1"><a href="#browsing-user-data">Browsing User Data</a></li> <li class="level1"><a href="#user-authentication">User Authentication</a></li> <li class="level1"><a href="#registering-a-new-user">Registering a New User</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">Enginio QML Examples - Users</h1> <span class="subtitle"></span> <!-- $$$users-brief --> <p>The Users example introduces user registration, authentication, and browsing.</p> <!-- @@@users --> <!-- $$$users-description --> <div class="descr"> <a name="details"></a> <a name="introduction"></a> <h2 id="introduction">Introduction</h2> <p>This example will demonstrate how to register and authenticate a user, and what kind of information is attached to an authenticated session. This is a simple example, and data access rights management is not covered here. For such information, please refer to the Social Todo example.</p> <p class="centerAlign"><font color="red">[Missing image users-example.png]</font></p><p>There is no special need for the backend setup. This example will use only predefined structures, which are the same for every backend.</p> <p>The example is an application that shows users registered in the backend, allows registration of new users, and shows how to login in separate tabs.</p> <p>Each backend contains the "users" object type, which defines a structure that stores all basic data about an application's users. The collection of "users" is not really different from any other collection. Therefore, we do not need any special methods to manipulate it. Typical data associated with a user is:</p> <ul> <li><code>username</code> - required name used for logging in.</li> <li><code>email</code> - unique email address of a user.</li> <li><code>firstName</code>, lastName - user's credentials (optional).</li> <li><code>password</code> - write-only property, this value is used during authentication.</li> </ul> <p>The <code>users</code> object can be extended by custom properties too.</p> <p><b>Note: </b><i>username</i> and <i>password</i> are always required and cannot be empty.</p><a name="general-example-structure"></a> <h2 id="general-example-structure">General Example Structure</h2> <p>This example uses QtEnginio library together with Qt Quick Controls, therefore both have to be imported.</p> <pre class="qml"> </pre> <p>We will also use a common <a href="qml-enginio-enginioclient.html">EnginioClient</a> connection as shown here:</p> <pre class="qml"> </pre> <p>The example is organized into separate tabs by using TabView. Each tab shows a different functionality.</p> <a name="browsing-user-data"></a> <h2 id="browsing-user-data">Browsing User Data</h2> <p>The most convenient method to browse users is to use <a href="qml-enginio-enginiomodel.html">EnginioModel</a>. The model can automatically download all data that we need. It is sufficient to set three properties: <a href="qml-enginio-enginiomodel.html#client-prop">client</a>, <a href="qml-enginio-enginiomodel.html#query-prop">query</a> and <a href="qml-enginio-enginiomodel.html#operation-prop">operation</a> as shown below:</p> <pre class="qml"> </pre> <p>The model is used directly by TableView, in which we define data that will be shown.</p> <pre class="qml"> </pre> <a name="user-authentication"></a> <h2 id="user-authentication">User Authentication</h2> <p>Authentication is quite easy. The only thing that needs to be done is to assign an identity, for example, <a href="qml-enginio-enginiooauth2authentication.html">EnginioOAuth2Authentication</a> object to <a href="qml-enginio-enginioclient.html#identity-prop">EnginioClient::identity</a>. After a while, <a href="qml-enginio-enginioclient.html#authenticationState-prop">EnginioClient::authenticationState</a> will change and <a href="qml-enginio-enginioclient.html#sessionAuthenticated-signal">sessionAuthenticated</a> or <a href="qml-enginio-enginioclient.html#sessionAuthenticationError-signal">sessionAuthenticationError</a> will be emitted.</p> <p>The first thing we need to do is to create an identity object: <a href="qml-enginio-enginiooauth2authentication.html">EnginioOAuth2Authentication</a></p> <pre class="qml"> </pre> <p>Then, depending on the state of the application, we assign the object to our enginioClient instance. There are four possible states, defined by Enginio::AuthenticationState. After assigning the Identity object, the state changes from the initial <code>NotAuthenticated</code> to <code>Authenticating</code>.</p> <pre class="qml"> </pre> <p>Once the authentication query has finished, the state changes to <code>Authenticated</code> or <code>AuthenticationFailure</code> depending on the authentication result. Null assignment to the <a href="qml-enginio-enginioclient.html#identity-prop">identity</a> causes the session to terminate immediately:</p> <pre class="qml"> </pre> <p>For educational purposes, in the example we also show a log window with data attached to a session that is changing state.</p> <pre class="qml"> </pre> <a name="registering-a-new-user"></a> <h2 id="registering-a-new-user">Registering a New User</h2> <p>Registration of a new user is as simple as adding a new object to the <code>users</code> collection. It can be achieved by using the <a href="qml-enginio-enginioclient.html#create-method">create</a> function, as shown below:</p> <pre class="qml"> </pre> <p>We could also use the <a href="qml-enginio-enginiomodel.html#append-method">EnginioModel::append</a> method in the browsing example to accomplish the same task.</p> </div> <!-- @@@users --> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2019 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br/> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br/> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. </p> </div> </body> </html>