Skip to content

Commit 5e80d4f

Browse files
committed
Version 1.0.3 - Added decoder
1 parent 92f2e48 commit 5e80d4f

File tree

4 files changed

+47
-26
lines changed

4 files changed

+47
-26
lines changed

CHANGELOG.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## 1.0.3
22

3-
Added persistant storage. When a logged in user closes the app, then reopens, the data
4-
will now be persistant. Best practice would be to Parse.init, then Parse.currentUser. This
5-
will return the current user session and allow autologin.
3+
Added persistent storage. When a logged in user closes the app, then reopens, the data
4+
will now be persistent. Best practice would be to Parse.init, then Parse.currentUser. This
5+
will return the current user session and allow auto login. Can also pin data in storage.
66

77
## 1.0.2
88

README.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ The features available are:-
115115
* Query - By object Id
116116
* Delete
117117
* Complex queries as shown above
118+
* Pin
118119
* Plenty more
119120

120121
## Custom Objects
@@ -146,21 +147,21 @@ var user = ParseUser().create("TestFlutter", "TestPassword123", "TestFlutterSDK
146147
Then have the user sign up:
147148

148149
```
149-
user = await ParseUser().signUp();
150+
user = await user.signUp();
150151
```
151152
You can also logout and login with the user:
152153
```
153-
user = await ParseUser().login();
154+
user = await user.login();
154155
```
155-
Also, once logged in you can manage sessions tokens:
156+
Also, once logged in you can manage sessions tokens. This feature can be called after Parse().init() on startup to check for a logged in user.
156157
```
157-
user = await ParseUser().currentUser(fromServer: true);
158+
user = ParseUser.currentUser();
158159
```
159160
Other user features are:-
160161
* Request Password Reset
161-
* Verification Email Request
162+
* Verification Email Request
162163
* Get all users
163-
* Save
164+
* Save
164165
* Destroy user
165166

166167
## Other Features of this library
@@ -171,6 +172,7 @@ Main:
171172
* Queries
172173
* LiveQueries
173174
* GeoPoints
175+
* Persistent storage
174176
* Debug Mode - Logging API calls
175177
* Manage Session ID's tokens
176178

example/lib/main.dart

+7-2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class _MyAppState extends State<MyApp> {
9999
}
100100

101101
initUser() async {
102+
103+
// All return type ParseUser except all
102104
var user = ParseUser("TestFlutter", "TestPassword123", "[email protected]");
103105
user = await user.signUp();
104106
user = await user.login();
@@ -109,9 +111,12 @@ class _MyAppState extends State<MyApp> {
109111
user = await user.getCurrentUserFromServer();
110112
user = await user.requestPasswordReset();
111113
user = await user.verificationEmailRequest();
112-
user = await user.all();
114+
113115
user = await user.save();
114-
//await user.destroy();
116+
await user.destroy();
117+
118+
// Returns type ParseResponse as its a query, not a single result
119+
var response = await ParseUser.all();
115120
}
116121

117122
function() {

lib/src/objects/parse_user.dart

+29-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
part of flutter_parse_sdk;
22

33
class ParseUser extends ParseBase {
4-
ParseHTTPClient _client;
54
static final String className = '_User';
6-
String path = "/classes/$className";
5+
static final String path = "/classes/$className";
76
bool _debug;
7+
ParseHTTPClient _client;
88

99
String acl;
1010
String username;
@@ -21,9 +21,7 @@ class ParseUser extends ParseBase {
2121
/// Requires [String] username, [String] password. [String] email address
2222
/// is required as well to create a full new user object on ParseServer. Only
2323
/// username and password is required to login
24-
ParseUser(this.username, this.password, this.emailAddress,
25-
{bool debug, ParseHTTPClient client})
26-
: super() {
24+
ParseUser(this.username, this.password, this.emailAddress, {bool debug, ParseHTTPClient client}) : super() {
2725
client == null ? _client = ParseHTTPClient() : _client = client;
2826
_debug = isDebugEnabled(client, objectLevelDebug: debug);
2927
}
@@ -222,12 +220,23 @@ class ParseUser extends ParseBase {
222220
}
223221

224222
/// Gets a list of all users (limited return)
225-
all() async {
223+
static all() async {
224+
225+
var emptyUser = ParseUser(null, null, null);
226+
226227
try {
227-
final response = await _client.get(_client.data.serverUrl + "$path");
228-
return _handleResponse(response, ParseApiRQ.all);
228+
final response = await ParseHTTPClient().get(
229+
"${ParseCoreData().serverUrl}/$path");
230+
231+
ParseResponse parseResponse = ParseResponse.handleResponse(emptyUser, response);
232+
233+
if (ParseCoreData().debug) {
234+
logger(ParseCoreData().appName, className, ParseApiRQ.getAll.toString(), parseResponse);
235+
}
236+
237+
return parseResponse;
229238
} on Exception catch (e) {
230-
return _handleException(e, ParseApiRQ.all);
239+
return ParseResponse.handleException(emptyUser, e);
231240
}
232241
}
233242

@@ -267,17 +276,22 @@ class ParseUser extends ParseBase {
267276

268277
/// Handles all the response data for this class
269278
_handleResponse(Response response, ParseApiRQ type) {
270-
Map<String, dynamic> responseData = JsonDecoder().convert(response.body);
271-
if (responseData.containsKey('sessionToken')) {
272-
fromJson(responseData);
273-
_client.data.sessionId = responseData['sessionToken'];
274-
}
275279

276280
ParseResponse parseResponse = ParseResponse.handleResponse(this, response);
277281
if (_debug) {
278282
logger(ParseCoreData().appName, className, type.toString(), parseResponse);
279283
}
280284

281-
return this;
285+
Map<String, dynamic> responseData = JsonDecoder().convert(response.body);
286+
if (responseData.containsKey('objectId')) {
287+
fromJson(responseData);
288+
_client.data.sessionId = responseData['sessionToken'];
289+
}
290+
291+
if (type == ParseApiRQ.getAll) {
292+
return parseResponse;
293+
} else {
294+
return this;
295+
}
282296
}
283297
}

0 commit comments

Comments
 (0)