Skip to content

Commit

Permalink
Fix for not working user login & creation
Browse files Browse the repository at this point in the history
I had added:
* missing body for user creation request
* changed URI creation for login, because previous one didn't worked. Full url was setted as a path
* this commit also include changes from this pull request parse-community#5
  • Loading branch information
PiotrWpl committed Oct 12, 2018
1 parent 5567b2d commit a3fe276
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions lib/parse_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'parse_http_client.dart';
class User implements ParseBaseObject {
final String className = '_User';
final ParseHTTPClient client = ParseHTTPClient();
String path = "/parse/classes/_User";
String path = "/classes/_User";
Map<String, dynamic> objectData = {};

static ParseUserData userData;
Expand Down Expand Up @@ -70,26 +70,44 @@ class User implements ParseBaseObject {
objectData = {}..addAll(objectData)..addAll(objectInitialData);
}
_resetObjectId();
print(objectData);
final response = this.client.post("${client.data.serverUrl}$path",

Map<String, dynamic> bodyData = {};
bodyData["email"] = userData.username;
bodyData["password"] = userData.password;
bodyData["username"] = userData.username;

Uri tempUri = Uri.parse(client.data.serverUrl);

Uri url = Uri(
scheme: tempUri.scheme,
host: tempUri.host,
path: "${tempUri.path}$path"
);

final response = this.client.post(url,
headers: {
'X-Parse-Revocable-Session': "1",
},
body: JsonEncoder().convert(objectData));
body: JsonEncoder().convert(bodyData));

return response.then((value) {
_handleResponse(value.body);
return objectData;
});
}

Future<Map<String, dynamic>> login() async {

Uri url = new Uri(
path: "${client.data.serverUrl}/parse/login",
queryParameters: {
"username": userData.username,
"password": userData.password
});
Uri tempUri = Uri.parse(client.data.serverUrl);

Uri url = Uri(
scheme: tempUri.scheme,
host: tempUri.host,
path: "${tempUri.path}/login",
queryParameters: {
"username": userData.username,
"password": userData.password
}
);

final response = this.client.post(url, headers: {
'X-Parse-Revocable-Session': "1",
Expand All @@ -102,7 +120,7 @@ class User implements ParseBaseObject {

Future<Map<String, dynamic>> verificationEmailRequest() async {
final response = this.client.post(
"${client.data.serverUrl}/parse/verificationEmailRequest",
"${client.data.serverUrl}/verificationEmailRequest",
body: JsonEncoder().convert({"email": userData.emailAddress}));
return response.then((value) {
return _handleResponse(value.body);
Expand All @@ -111,7 +129,7 @@ class User implements ParseBaseObject {

Future<Map<String, dynamic>> requestPasswordReset() async {
final response = this.client.post(
"${client.data.serverUrl}/parse/requestPasswordReset",
"${client.data.serverUrl}/requestPasswordReset",
body: JsonEncoder().convert({"email": userData.emailAddress}));
return response.then((value) {
return _handleResponse(value.body);
Expand Down

0 comments on commit a3fe276

Please sign in to comment.