1 | <!DOCTYPE html>
|
2 | <html lang="en">
|
3 | <head>
|
4 | <meta charset="utf-8">
|
5 | <title>JSDoc: Source: lib/model/User.js</title>
|
6 |
|
7 | <script src="scripts/prettify/prettify.js"> </script>
|
8 | <script src="scripts/prettify/lang-css.js"> </script>
|
9 | |
10 |
|
11 |
|
12 | <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
13 | <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
14 | </head>
|
15 |
|
16 | <body>
|
17 |
|
18 | <div id="main">
|
19 |
|
20 | <h1 class="page-title">Source: lib/model/User.js</h1>
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | <section>
|
28 | <article>
|
29 | <pre class="prettyprint source linenums"><code>
|
30 | var util = require('../util');
|
31 |
|
32 | /**
|
33 | * Rapresent an user
|
34 | *
|
35 | * @constructor
|
36 | * @param {Object} res user details
|
37 | * @param {Container} container the main container
|
38 | */
|
39 | var User = function(res, container) {
|
40 |
|
41 | this.data = {
|
42 | uuid: null,
|
43 | username: null,
|
44 | password: null,
|
45 | email: null,
|
46 | enabled: true,
|
47 | roles: []
|
48 | }
|
49 |
|
50 | if(container === undefined)
|
51 | throw new Error("Missing container reference");
|
52 |
|
53 | this.setContainer(container)
|
54 | this.exportProperties();
|
55 | if(res) this.parseJSON(res);
|
56 | };
|
57 | util.extends(User, 'Container');
|
58 |
|
59 | /**
|
60 | * Save the local modification to the user object
|
61 | */
|
62 | User.prototype.update = function () {
|
63 | this.getContainer().auth.users.update(this.toJSON());
|
64 | };
|
65 |
|
66 | /**
|
67 | * Fetch the user object
|
68 | */
|
69 | User.prototype.read = function () {
|
70 | var me = this
|
71 | this.getContainer().auth.users.read(this.toJSON().uuid).then(function(res) {
|
72 | me.parseJSON(res)
|
73 | });
|
74 | };
|
75 |
|
76 | /**
|
77 | * Login the current user and retrieve a session apiKey
|
78 | *
|
79 | * @return {Promise} token A Promise containing the session apiKey
|
80 | */
|
81 | User.prototype.login = function () {
|
82 | var me = this
|
83 | return this.getContainer().auth.login(this.toJSON()).then(function(res) {
|
84 | me.parseJSON(res.user)
|
85 | return Promise.resolve(res.token)
|
86 | });
|
87 | };
|
88 |
|
89 | /**
|
90 | * Logout the current user
|
91 | *
|
92 | * @return {Promise} response
|
93 | */
|
94 | User.prototype.logout = function () {
|
95 | return this.getContainer().auth.logout(this.toJSON());
|
96 | };
|
97 |
|
98 | module.exports = User;
|
99 | </code></pre>
|
100 | </article>
|
101 | </section>
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | </div>
|
107 |
|
108 | <nav>
|
109 | <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Action.html">Action</a></li><li><a href="Channel.html">Channel</a></li><li><a href="Client.html">Client</a></li><li><a href="Raptor.html">Raptor</a></li><li><a href="RecordSet.html">RecordSet</a></li><li><a href="ResultSet.html">ResultSet</a></li><li><a href="ServiceObject.html">ServiceObject</a></li><li><a href="Stream.html">Stream</a></li><li><a href="User.html">User</a></li></ul><h3>Global</h3><ul><li><a href="global.html#Container">Container</a></li></ul>
|
110 | </nav>
|
111 |
|
112 | <br class="clear">
|
113 |
|
114 | <footer>
|
115 | Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.2</a> on Wed Nov 02 2016 11:15:06 GMT+0100 (CET)
|
116 | </footer>
|
117 |
|
118 | <script> prettyPrint(); </script>
|
119 | <script src="scripts/linenumber.js"> </script>
|
120 | </body>
|
121 | </html>
|