From d85476a651c80ad66894f7774189b4ec214f7282 Mon Sep 17 00:00:00 2001
From: klanmiko <eternity01033@gmail.com>
Date: Fri, 1 Feb 2019 23:01:08 -0800
Subject: [PATCH 1/3] add all the changes since history diverged

---
 lib/parse.dart                       |  2 +
 lib/src/base/parse_constants.dart    |  1 +
 lib/src/enums/parse_enum_api_rq.dart |  1 +
 lib/src/objects/parse_file.dart      | 55 ++++++++++++++++++++++++++--
 lib/src/objects/parse_user.dart      | 35 +++++++++++++++++-
 lib/src/utils/parse_decoder.dart     |  2 +-
 6 files changed, 90 insertions(+), 6 deletions(-)

diff --git a/lib/parse.dart b/lib/parse.dart
index 516851a63..ff2ba1e03 100644
--- a/lib/parse.dart
+++ b/lib/parse.dart
@@ -10,6 +10,8 @@ import 'package:meta/meta.dart';
 import 'package:path/path.dart' as path;
 import 'package:shared_preferences/shared_preferences.dart';
 import 'package:web_socket_channel/io.dart';
+import 'package:uuid/uuid.dart';
+import 'package:path_provider/path_provider.dart';
 
 part 'src/base/parse_constants.dart';
 
diff --git a/lib/src/base/parse_constants.dart b/lib/src/base/parse_constants.dart
index 6e2ba9494..4d7c03af2 100644
--- a/lib/src/base/parse_constants.dart
+++ b/lib/src/base/parse_constants.dart
@@ -7,6 +7,7 @@ const String keyLibraryName= 'Flutter Parse SDK';
 // End Points
 const String keyEndPointUserName = '/users/me';
 const String keyEndPointLogin = '/login';
+const String keyEndPointUsers = '/users';
 const String keyEndPointVerificationEmail = '/verificationEmailRequest';
 const String keyEndPointRequestPasswordReset = '/requestPasswordReset';
 const String keyEndPointClasses = '/classes/';
diff --git a/lib/src/enums/parse_enum_api_rq.dart b/lib/src/enums/parse_enum_api_rq.dart
index 324e70253..6166516ff 100644
--- a/lib/src/enums/parse_enum_api_rq.dart
+++ b/lib/src/enums/parse_enum_api_rq.dart
@@ -12,6 +12,7 @@ enum ParseApiRQ {
   currentUser,
   signUp,
   login,
+  loginAnonymous,
   verificationEmailRequest,
   requestPasswordReset,
   destroy,
diff --git a/lib/src/objects/parse_file.dart b/lib/src/objects/parse_file.dart
index 142633156..f777ba4a6 100644
--- a/lib/src/objects/parse_file.dart
+++ b/lib/src/objects/parse_file.dart
@@ -13,6 +13,12 @@ class ParseFile extends ParseObject {
 
   String get url => _fileUrl;
 
+  File get file => _file;
+
+  set url(String url) => _fileUrl = url;
+
+  set name(String name) => _fileName = name;
+
   bool get saved => url != null;
 
   @override
@@ -24,12 +30,53 @@ class ParseFile extends ParseObject {
   /// Creates a new file
   ///
   /// {https://docs.parseplatform.org/rest/guide/#files/}
-  ParseFile(this._file, {bool debug, ParseHTTPClient client}) : super (keyFile){
+  ParseFile(this._file, {String name, String url, bool debug, ParseHTTPClient client}) : super (keyFile){
     client == null ? _client = ParseHTTPClient() : _client = client;
     _debug = isDebugEnabled(objectLevelDebug: debug);
+    if(_file != null) {
+      this._fileName = path.basename(_file.path);
+      this._path = 'files/$_fileName';
+    }
+    else {
+      this._fileName = name;
+      this._fileUrl = url;
+    }
+  }
+
+  Future<ParseFile> loadStorage() async {
+    Directory tempPath = await getTemporaryDirectory();
+
+    if(_fileName == null) {
+      _file = null;
+      return this;
+    }
+
+    File possibleFile = new File("${tempPath.path}/$_fileName");
+    bool exists = await possibleFile.exists();
+
+    if(exists) {
+      _file = possibleFile;
+    }
+    else {
+      _file = null;
+    }
+
+    return this;
+  }
+
+  Future<ParseFile> download() async {
+    if(_fileUrl == null) {
+      return this;
+    }
+    
+    Directory tempPath = await getTemporaryDirectory();
+    this._file = new File("${tempPath.path}/$_fileName");
+    await _file.create();
+
+    var response = await _client.get(_fileUrl);
+    _file.writeAsBytes(response.bodyBytes);
 
-    this._fileName = path.basename(_file.path);
-    this._path = 'files/$_fileName';
+    return this;
   }
 
   /// Uploads a file to Parse Server
@@ -48,4 +95,4 @@ class ParseFile extends ParseObject {
     final response = await _client.post(uri, headers: headers, body: body);
     return super.handleResponse<ParseFile>(response, ParseApiRQ.upload);
   }
-}
\ No newline at end of file
+}
diff --git a/lib/src/objects/parse_user.dart b/lib/src/objects/parse_user.dart
index a5a523ed4..d5dd0ec18 100644
--- a/lib/src/objects/parse_user.dart
+++ b/lib/src/objects/parse_user.dart
@@ -155,6 +155,37 @@ class ParseUser extends ParseObject implements ParseCloneable {
     }
   }
 
+  // Logs in a user anonymously
+  Future<ParseResponse> loginAnonymous() async {
+    try {
+       Uri tempUri = Uri.parse(_client.data.serverUrl);
+
+      Uri url = Uri(
+          scheme: tempUri.scheme,
+          host: tempUri.host,
+          path: "${tempUri.path}$keyEndPointUsers",
+          );
+
+      var uuid = new Uuid();
+
+      final response = await _client.post(url, headers: {
+        keyHeaderRevocableSession: "1",
+
+      }, body: jsonEncode({
+        "authData": {
+          "anonymous": {
+            "id": uuid.v4()
+          }
+        }
+      }));
+
+      return _handleResponse(response, ParseApiRQ.loginAnonymous);
+    }
+    on Exception catch (e) {
+      return _handleException(e, ParseApiRQ.loginAnonymous);
+    }
+  }
+
   /// Removes the current user from the session data
   logout() {
     _client.data.sessionId = null;
@@ -198,7 +229,9 @@ class ParseUser extends ParseObject implements ParseCloneable {
         var uri = _client.data.serverUrl + "$path/$objectId";
         var body =
             json.encode(toJson(forApiRQ: true), toEncodable: dateTimeEncoder);
-        final response = await _client.put(uri, body: body);
+        final response = await _client.put(uri, 
+            headers: {keyHeaderSessionToken: _client.data.sessionId}, 
+            body: body);
         return _handleResponse(response, ParseApiRQ.save);
       } on Exception catch (e) {
         return _handleException(e, ParseApiRQ.save);
diff --git a/lib/src/utils/parse_decoder.dart b/lib/src/utils/parse_decoder.dart
index 9199b1a07..b0022bfde 100644
--- a/lib/src/utils/parse_decoder.dart
+++ b/lib/src/utils/parse_decoder.dart
@@ -64,7 +64,7 @@ dynamic parseDecode(dynamic value) {
       }
       return ParseObject(className).fromJson(map);
     case "File":
-      return new ParseFile(null).fromJson(map);
+      return new ParseFile(null, url: map["url"], name: map["name"]).fromJson(map);
     case "GeoPoint":
       num latitude = map["latitude"] ?? 0.0;
       num longitude = map["longitude"] ?? 0.0;

From f5a26d0e0aa775cac5664ffd5fc6fb316bbc6a29 Mon Sep 17 00:00:00 2001
From: klanmiko <eternity01033@gmail.com>
Date: Fri, 1 Feb 2019 23:02:35 -0800
Subject: [PATCH 2/3] add dependencies

---
 pubspec.yaml | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/pubspec.yaml b/pubspec.yaml
index c25a51adb..3865a1c7e 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -17,4 +17,9 @@ dependencies:
 
   # Utils
   shared_preferences: ^0.4.3
-  path_provider: ^0.4.1
\ No newline at end of file
+<<<<<<< HEAD
+  path_provider: ^0.4.1
+  uuid: ^1.0.0
+=======
+  path_provider: ^0.4.1
+>>>>>>> 9c70784113c26313035f15b424361bdd30362abe

From 92bd3333a6afb4d962178270085fadfef18df0d5 Mon Sep 17 00:00:00 2001
From: Kaelan Mikowicz <eternity01033@gmail.com>
Date: Sat, 2 Feb 2019 12:26:32 -0800
Subject: [PATCH 3/3] remove merge conflict from pubspec

---
 pubspec.yaml | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/pubspec.yaml b/pubspec.yaml
index 3865a1c7e..9e7df516b 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -17,9 +17,5 @@ dependencies:
 
   # Utils
   shared_preferences: ^0.4.3
-<<<<<<< HEAD
   path_provider: ^0.4.1
   uuid: ^1.0.0
-=======
-  path_provider: ^0.4.1
->>>>>>> 9c70784113c26313035f15b424361bdd30362abe