Skip to content

Commit

Permalink
working on auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Cioni committed Jul 14, 2020
1 parent e5ab834 commit 50347c3
Show file tree
Hide file tree
Showing 20 changed files with 279 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_keyboard_visibility","path":"/Users/andrea/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_keyboard_visibility-0.7.0/","dependencies":[]}],"android":[{"name":"flutter_keyboard_visibility","path":"/Users/andrea/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_keyboard_visibility-0.7.0/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_keyboard_visibility","dependencies":[]}],"date_created":"2020-07-07 23:24:50.658298","version":"1.17.0"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_keyboard_visibility","path":"/Users/andrea/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_keyboard_visibility-0.7.0/","dependencies":[]}],"android":[{"name":"flutter_keyboard_visibility","path":"/Users/andrea/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_keyboard_visibility-0.7.0/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_keyboard_visibility","dependencies":[]}],"date_created":"2020-07-09 23:18:15.827984","version":"1.17.5"}
19 changes: 19 additions & 0 deletions .idea/libraries/Dart_SDK.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/Flutter_for_Android.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/libraries/KotlinJavaRuntime.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/runConfigurations/main_dart.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
gradle-wrapper.jar
/.gradle
/captures/
/gradlew
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java
29 changes: 29 additions & 0 deletions android/weekly_menu_app_android.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android" name="Android">
<configuration>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="GEN_FOLDER_RELATIVE_PATH_APT" value="/gen" />
<option name="GEN_FOLDER_RELATIVE_PATH_AIDL" value="/gen" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/app/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/app/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/app/src/main/assets" />
<option name="LIBS_FOLDER_RELATIVE_PATH" value="/app/src/main/libs" />
<option name="PROGUARD_LOGS_FOLDER_RELATIVE_PATH" value="/app/src/main/proguard_logs" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/app/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/app/src/main/kotlin" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
</content>
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Flutter for Android" level="project" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>
32 changes: 32 additions & 0 deletions ios/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
*.mode1v3
*.mode2v3
*.moved-aside
*.pbxuser
*.perspectivev3
**/*sync/
.sconsign.dblite
.tags*
**/.vagrant/
**/DerivedData/
Icon?
**/Pods/
**/.symlinks/
profile
xcuserdata
**/.generated/
Flutter/App.framework
Flutter/Flutter.framework
Flutter/Flutter.podspec
Flutter/Generated.xcconfig
Flutter/app.flx
Flutter/app.zip
Flutter/flutter_assets/
Flutter/flutter_export_environment.sh
ServiceDefinitions.json
Runner/GeneratedPluginRegistrant.*

# Exceptions to above rules.
!default.mode1v3
!default.mode2v3
!default.pbxuser
!default.perspectivev3
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PreviewsEnabled</key>
<false/>
</dict>
</plist>
8 changes: 8 additions & 0 deletions ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PreviewsEnabled</key>
<false/>
</dict>
</plist>
29 changes: 24 additions & 5 deletions lib/datasource/network.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class NetworkDatasource {

Future<void> patchRecipe(
String recipeId, Map<String, dynamic> jsonMap) async {
jsonMap.removeWhere((k, _) => k =='_id');
jsonMap.removeWhere((k, _) => k == '_id');
var resp = await _dio.patch('$BASE_URL/recipes/$recipeId', data: jsonMap);

return resp.data;
Expand Down Expand Up @@ -161,9 +161,10 @@ class NetworkDatasource {
await _dio.delete('$BASE_URL/ingredients/$ingredientId');
}

Future<Map<String, dynamic>> createRecipe(Map<String, dynamic> jsonMap) async {
jsonMap.removeWhere((k, _) => k =='_id');
var resp = await _dio.post(
Future<Map<String, dynamic>> createRecipe(
Map<String, dynamic> jsonMap) async {
jsonMap.removeWhere((k, _) => k == '_id');
var resp = await _dio.post(
'$BASE_URL/recipes',
data: jsonMap,
);
Expand All @@ -172,7 +173,7 @@ class NetworkDatasource {
}

Future<void> putMenu(String id, Map<String, dynamic> jsonMap) async {
jsonMap.removeWhere((k, _) => k =='_id');
jsonMap.removeWhere((k, _) => k == '_id');
await _dio.put(
'$BASE_URL/menus/$id',
data: jsonMap,
Expand All @@ -184,4 +185,22 @@ class NetworkDatasource {
'$BASE_URL/recipes/$recipeId',
);
}

Future<void> register(String email, password) async {
var resp = await _dio.post('$BASE_URL/auth/register',
data: {'username': email, 'password': password});

return resp.data;
}

Future<Map<String, dynamic>> login(String email, password) async {
var resp = await _dio.post('$BASE_URL/auth/login',
data: {'username': email, 'password': password});

return resp.data;
}

Future<void> logout() async {
await _dio.post('$BASE_URL/auth/logout');
}
}
17 changes: 17 additions & 0 deletions lib/models/AuthToken.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

import 'package:json_annotation/json_annotation.dart';

@JsonSerializable()
class AuthToken {

@JsonKey(name: 'access_token')
final String accessToken;
final String refreshToken;
final int expiresIn;

AuthToken({this.accessToken, this.refreshToken, this.expiresIn});

factory AuthToken.fromJson(Map<String, dynamic> json) => _$AuthTokenFromJson(json);

Map<String, dynamic> toJson() => _$AuthTokenToJson(this);
}
21 changes: 21 additions & 0 deletions lib/providers/auth_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart';

import '../datasource/network.dart';

class AuthProvider with ChangeNotifier {
final log = Logger((AuthProvider).toString());
final NetworkDatasource _restApi = NetworkDatasource.getInstance();

Future<void> register({@required String email, @required String password}) async {
await _restApi.register(email, password);
}

Future<void> login(String email, password) async {
await _restApi.login(email, password);
}

Future<void> logout() async {
await _restApi.logout();
}
}
5 changes: 3 additions & 2 deletions lib/widgets/recipe_view/recipe_tags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ class RecipeTags extends StatelessWidget {
helperText: 'Add',
suggestions: _availableTags(context),
textCapitalization: TextCapitalization.words,
maxLength: 10,
maxLength: 20,
onSubmitted: (newTag) => recipe.addTag(newTag),
constraintSuggestion: false)
constraintSuggestion: false,
)
: null,
);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies:
sdk: flutter

dio: ^3.0.9
flutter_tags: ^0.4.8
flutter_tags: ^0.4.8+2
intl: ^0.16.1
expandable: ^2.2.3
grouped_buttons: ^1.0.4
Expand Down
18 changes: 18 additions & 0 deletions weekly_menu_app.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>

0 comments on commit 50347c3

Please sign in to comment.