-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcloudUser.html
More file actions
365 lines (315 loc) · 15.2 KB
/
cloudUser.html
File metadata and controls
365 lines (315 loc) · 15.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<a id='CloudUser' name="CloudUser" class="section-anchor"> </a>
<div class="method-section">
<div class="method-description">
<h1>CloudUser</h1>
<p>
There is a notion of user accounts that lets users access their information in a secure manner.
We provide a specialized user class called <code>CloudUser</code> that automatically handles
much of the functionality required for user account management.
</p>
<p>
<code>CloudUser</code> is a subclass of <code>CloudObject</code>, and has all the same features, such as flexible
schema, automatic persistence, and a key value interface. All the methods that are on
<code>CloudObject</code> also exist in <code>CloudUser</code>. The difference is that <code>CloudUser</code> has some special
additions specific to user accounts. With this class, you'll be able to add user account
functionality in your app.
</p>
<p>
There is a special object <code>CloudUser.current</code> which holds the
information of the current user logged in.
</p>
</div>
<div class="method-example" id="api-summary-example">
</div>
</div>
<a id='CloudUser-constructor' name="CloudUser-constructor" class="section-anchor"> </a>
<div class="method-section">
<div class="method-description">
<h3>Constructor</h3>
<p>
Instantiates a <code>CloudUser</code> object.
</p>
<div class="method-list">
<h3>Package</h3>
<p>
<code>import com.cloudboost.CloudUser;</code>
</p>
<h6>Argument</h6>
<p>It takes no argument.</p>
</div>
</div>
<div class="method-example" id="api-summary-example">
<code class="method-request"><span class="prompt"></span><span class="lang lang-node"><span class="highlight_js javascript">CloudUser obj = new CloudUser();</span></span></code>
</div><!-- method-example -->
</div> <!-- method-section -->
<a id='CloudUser-signUp' name="CloudUser-signUp" class="section-anchor"> </a>
<div class="method-section">
<div class="method-description">
<h3>CloudUser.signUp( )</h3>
<p>
It registers new user given its <i>username</i>, <i>email</i> and <i>password</i>.
Registration is successful if the given <i>email</i> is not already registered to an existing user.
</p>
<p>
It sets the attributes of <code>CloudUser.current</code> object with the
<code>CloudUser</code> object recieved.
</p>
<div class="method-list">
<h6>Returns</h6>
<p>
It returns a <code>CloudUser</code> object which has the user information if registration is successful.
</p>
<h6>Error Handling</h6>
It throws <code>CloudBoostException</code>
</div>
</div>
<div class="method-example" id="api-summary-example">
<code class="method-request"><span class="prompt"></span><span class="lang lang-node"><span class="highlight_js javascript">CloudUser user = new CloudUser();
user.set("username", "my_username");
user.set("password", "my_solid_password");
user.set("email", "email@sample.com");
user.signUp();
</span></span></code>
</div><!-- method-example -->
</div> <!-- method-section -->
<a id='CloudUser-logIn' name="CloudUser-logIn" class="section-anchor"> </a>
<div class="method-section">
<div class="method-description">
<h3>CloudUser.logIn( )</h3>
<p>
It logs in user given its <i>username</i> and <i>password</i>.
Login is successful if the given <i>username</i> and <i>password</i> pair is already present in the database.
</p>
<p>
It sets the attributes of <code>CloudUser.current</code> object with the
<code>CloudUser</code> object recieved.
</p>
<div class="method-list">
</dl>
<h6>Returns</h6>
<p>
It returns a <code>CloudUser</code> object which has the user information if registration is
successful.</p>
<h6>Error Handling</h6>
It throws <code>CloudBoostException</code>
</div>
</div>
<div class="method-example" id="api-summary-example">
<code class="method-request"><span class="prompt"></span><span class="lang lang-node"><span class="highlight_js javascript">
CloudUser user = new CloudUser();
user.set("username", "my_username");
user.set("password", "my_solid_password");
CloudUserCallback callbackObj = new CloudUserCallback(){
@Override
public void done(CloudObject obj,CloudException e) {
//
}
};
user.logIn(callbackObj);
</span></span></code>
</div><!-- method-example -->
</div> <!-- method-section -->
<a id='CloudUser-logOut' name="CloudUser-logOut" class="section-anchor"> </a>
<div class="method-section">
<div class="method-description">
<h3>CloudUser.logOut( )</h3>
<p>
It logs the user out.
</p>
<p>
It sets the <code>CloudUser.current</code> object to <i>null</i>.
</p>
<div class="method-list">
<h6>Returns</h6>
<p>
It returns a <code>CloudUser</code> object having the user information of the user who was logged in.
</p>
<h6>Error Handling</h6>
It throws <code>CloudBoostException</code>
</div>
</div>
<div class="method-example" id="api-summary-example">
<code class="method-request"><span class="prompt"></span><span class="lang lang-node"><span class="highlight_js javascript">
CloudUserCallback callbackObj = new CloudUserCallback(){
@Override
public void done(CloudObject obj,CloudException e) {
//
}
};
CloudUser.getCurrent().logOut(callbackObj);
</span></span></code>
</div><!-- method-example -->
</div> <!-- method-section -->
<a id='CloudUser-current' name="CloudUser-current" class="section-anchor"> </a>
<div class="method-section">
<div class="method-description">
<h3>CloudUser.getCurrent( )</h3>
<p>
Get the current logged in user.
</p>
</div>
<div class="method-example" id="api-summary-example">
<code class="method-request"><span class="prompt"></span><span class="lang lang-node"><span class="highlight_js javascript">
//gets the current user if user is loggedIn, null otherwise.
CloudUser currentUser = CloudUser.getCurrent();</span></span></code>
</div><!-- method-example -->
</div> <!-- method-section -->
<a id='CloudUser-addToRole' name="CloudUser-addToRole" class="section-anchor"> </a>
<div class="method-section">
<div class="method-description">
<h3>CloudUser.addToRole( <code>role</code> )</h3>
<p>
A user can be a part of many roles, like in real world. For this functionality
user should get added to a Role.
</p>
<p>
For this purpose <code>addToRole()</code> of <code>CloudUser</code> comes in handy.
</p>
<div class="method-list">
<h6>Arguments</h6>
<dl class="argument-list">
<dt>role</dt>
<dd class="">CloudRole Object <span> The <code>CloudRole</code> object of the role you want to
add the user to.</span></dd>
<div class="clearfix"></div>
</dl>
<h6>Returns</h6>
<p>
It returns a <code>CloudUser</code> object having the user information of the user who was logged in.
</p>
<h6>Error Handling</h6>
It throws <code>CloudBoostExceptionn</code>
</div>
</div>
<div class="method-example" id="api-summary-example">
<code class="method-request"><span class="prompt"></span><span class="lang lang-node"><span class="highlight_js javascript">
CloudUserCallback callbackObj = new CloudUserCallback(){
@Override
public void done(CloudObject obj,CloudException e) {
//
}
};
//role is an instance of CloudRole Object.
CloudUser.getCurrent().addToRole(role,callbackObj);
</span></span></code>
<p>Given <a href="#CloudRole-getRole">getRole()</a> is discussed later</p>
</div><!-- method-example -->
</div> <!-- method-section -->
<a id='CloudUser-isInRole' name="CloudUser-isInRole" class="section-anchor"> </a>
<div class="method-section">
<div class="method-description">
<h3>CloudUser.isInRole( <code>role</code> )</h3>
<p>
To check if the current user is in the role provided by the role object.
</p>
<div class="method-list">
<h6>Argument</h6>
<dl class="argument-list">
<dt>role</dt>
<dd class="">CloudRole Object <span> The <code>CloudRole</code> object of the role you want to
check the user to.</span></dd>
<div class="clearfix"></div>
</dl>
<h6>Returns</h6>
<p>
It returns a <i>true/false</i> based on whether the user is in the given
role or not respectively.
</p>
<h6>Error Handling</h6>
It throws <code>CloudBoostException</code>
</div>
</div>
<div class="method-example" id="api-summary-example">
<code class="method-request"><span class="prompt"></span><span class="lang lang-node"><span class="highlight_js javascript">
//role is the instance of the CloudRole object.
if(CloudUser.getCurrent().isInRole(role)) {
//The current user is in the given role.
} else {
//The user is not in the given role.
}
}</span></span></code>
<p>Given <a href="#CloudRole-getRole">getRole()</a> is discussed later</p>
</div><!-- method-example -->
</div> <!-- method-section -->
<a id='CloudUser-removeFromRole' name="CloudUser-removeFromRole" class="section-anchor"> </a>
<div class="method-section">
<div class="method-description">
<h3>CloudUser.removeFromRole( <code>role</code> )</h3>
<p>
Removes the user from the given role provided in <code>role</code> object.
</p>
<div class="method-list">
<h6>Argument</h6>
<dl class="argument-list">
<dt>role</dt>
<dd class="">CloudRole Object <span> The <code>CloudRole</code> object of the role you want to
remove the user from.</span></dd>
<div class="clearfix"></div>
</dl>
<h6>Returns</h6>
<p>
It returns a <code>CloudUser</code> object having the user information of the user who was logged in.
</p>
<h6>Error Handling</h6>
It throws <code>CloudBoostException</code>
</div>
</div>
<div class="method-example" id="api-summary-example">
<code class="method-request"><span class="prompt"></span><span class="lang lang-node"><span class="highlight_js javascript">
CloudUserCallback callbackObj = new CloudUserCallback(){
@Override
public void done(CloudObject obj,CloudException e) {
//
}
};
//role is an instance of CloudRole Object.
CloudUser.getCurrent().removeFromRole(role,callbackObj);
</span></span></code>
<p>Given <a href="#CloudRole-getRole">getRole()</a> is discussed later</p>
</div><!-- method-example -->
</div> <!-- method-section -->
<a id='CloudUser-changePassword' name="CloudUser-changePassword" class="section-anchor"> </a>
<div class="method-section">
<div class="method-description">
<h3>CloudUser.changePassword( )</h3>
<p>
To change the password of a user you need to call the changePassword function of the CB.CloudUser instance. Before you call the changePassword function make sure the current user is loggedIn and the current session is valid. Please note : Calling change password will not log the user out of its current session.
</p>
</div>
<div class="method-example" id="api-summary-example">
<code class="method-request"><span class="prompt"></span><span class="lang lang-node"><span class="highlight_js javascript">
CloudUser.getCurrentUser().changePassword("oldPassword","newPassword",
new CloudUserCallback(){
@Override
public void done(CloudUser user,CloudException e){
if(user!=null)
//user
if(e!=null)
//e
}
});
</span></span></code>
</div><!-- method-example -->
</div> <!-- method-section -->
<a id='CloudUser-resetPassword' name="CloudUser-resetPassword" class="section-anchor"> </a>
<div class="method-section">
<div class="method-description">
<h3>CloudUser.resetPassword( )</h3>
<p>
To reset the password of a user you need to call the resetPassword function of the CB.CloudUser class. Reset Password takes in an email of the user as first parameter and callback as second parameter. CloudBoost automatically takes care of emailing the user with password reset link. Please note : If you want to change the format the email which CloudBoost sends by default. You can head over to your CloudBoost App Dashboard and change the email settings of an app.
</p>
</div>
<div class="method-example" id="api-summary-example">
<code class="method-request"><span class="prompt"></span><span class="lang lang-node"><span class="highlight_js javascript">
CloudUser.resetPassword("email",new CloudStringCallback(){
@Override
public void done(String msg,CloudException e){
if(msg!=null)
//reset password email sent
if(e!=null)
//e
}
});
</span></span></code>
</div><!-- method-example -->
</div> <!-- method-section -->