Commit e30cd5ab authored by Herry's avatar Herry

added login page + logic

parent ada25cad
# This is a generated file; do not edit or check into version control. # This is a generated file; do not edit or check into version control.
integration_test=C:\\Libs\\flutter\\packages\\integration_test\\ integration_test=C:\\Libs\\flutter\\packages\\integration_test\\
path_provider=C:\\Libs\\flutter\\.pub-cache\\hosted\\pub.dartlang.org\\path_provider-1.6.27\\
path_provider_linux=C:\\Libs\\flutter\\.pub-cache\\hosted\\pub.dartlang.org\\path_provider_linux-0.0.1+2\\
path_provider_macos=C:\\Libs\\flutter\\.pub-cache\\hosted\\pub.dartlang.org\\path_provider_macos-0.0.4+8\\
path_provider_windows=C:\\Libs\\flutter\\.pub-cache\\hosted\\pub.dartlang.org\\path_provider_windows-0.0.5\\
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"integration_test","path":"C:\\\\Libs\\\\flutter\\\\packages\\\\integration_test\\\\","dependencies":[]}],"android":[{"name":"integration_test","path":"C:\\\\Libs\\\\flutter\\\\packages\\\\integration_test\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"integration_test","dependencies":[]}],"date_created":"2021-03-09 22:08:04.726748","version":"2.0.1"} {"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"integration_test","path":"C:\\\\Libs\\\\flutter\\\\packages\\\\integration_test\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\Libs\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.27\\\\","dependencies":[]}],"android":[{"name":"integration_test","path":"C:\\\\Libs\\\\flutter\\\\packages\\\\integration_test\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\Libs\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-1.6.27\\\\","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"C:\\\\Libs\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-0.0.4+8\\\\","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Libs\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-0.0.1+2\\\\","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Libs\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-0.0.5\\\\","dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"integration_test","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux","path_provider_windows"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2021-03-10 23:11:13.267004","version":"2.0.1"}
\ No newline at end of file \ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# #
# For more info see: https://dart.dev/go/dot-packages-deprecation # For more info see: https://dart.dev/go/dot-packages-deprecation
# #
# Generated by pub on 2021-03-09 22:03:23.618434. # Generated by pub on 2021-03-10 23:08:31.372244.
apex_flutter_sdk:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/apex_flutter_sdk-1.1.1+1/lib/ apex_flutter_sdk:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/apex_flutter_sdk-1.1.1+1/lib/
archive:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/archive-2.0.13/lib/ archive:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/archive-2.0.13/lib/
args:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/args-1.6.0/lib/ args:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/args-1.6.0/lib/
...@@ -11,7 +11,7 @@ async:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.5.0/lib ...@@ -11,7 +11,7 @@ async:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.5.0/lib
boolean_selector:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/boolean_selector-2.1.0/lib/ boolean_selector:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/boolean_selector-2.1.0/lib/
characters:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/characters-1.1.0/lib/ characters:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/characters-1.1.0/lib/
charcode:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/charcode-1.2.0/lib/ charcode:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/charcode-1.2.0/lib/
circlegraph:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/circlegraph-0.0.5/lib/ circlegraph:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/circlegraph-0.0.6/lib/
clock:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/clock-1.1.0/lib/ clock:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/clock-1.1.0/lib/
collection:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/collection-1.15.0/lib/ collection:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/collection-1.15.0/lib/
convert:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/convert-2.1.1/lib/ convert:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/convert-2.1.1/lib/
...@@ -19,21 +19,30 @@ crypto:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/crypto-2.1.5/l ...@@ -19,21 +19,30 @@ crypto:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/crypto-2.1.5/l
cupertino_icons:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/cupertino_icons-1.0.2/lib/ cupertino_icons:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/cupertino_icons-1.0.2/lib/
enhanced_future_builder:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/enhanced_future_builder-1.0.3/lib/ enhanced_future_builder:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/enhanced_future_builder-1.0.3/lib/
fake_async:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/fake_async-1.2.0/lib/ fake_async:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/fake_async-1.2.0/lib/
ffi:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/ffi-1.0.0/lib/
file:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/file-6.0.0/lib/ file:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/file-6.0.0/lib/
flutter:file:///C:/Libs/flutter/packages/flutter/lib/ flutter:file:///C:/Libs/flutter/packages/flutter/lib/
flutter_driver:file:///C:/Libs/flutter/packages/flutter_driver/lib/ flutter_driver:file:///C:/Libs/flutter/packages/flutter_driver/lib/
flutter_spinkit:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_spinkit-5.0.0/lib/
flutter_test:file:///C:/Libs/flutter/packages/flutter_test/lib/ flutter_test:file:///C:/Libs/flutter/packages/flutter_test/lib/
fuchsia_remote_debug_protocol:file:///C:/Libs/flutter/packages/fuchsia_remote_debug_protocol/lib/ fuchsia_remote_debug_protocol:file:///C:/Libs/flutter/packages/fuchsia_remote_debug_protocol/lib/
graphview:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/graphview-0.6.7/lib/ graphview:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/graphview-0.6.7/lib/
http:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.2/lib/ http:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.2/lib/
http_parser:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/http_parser-3.1.4/lib/ http_parser:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/http_parser-3.1.4/lib/
integration_test:file:///C:/Libs/flutter/packages/integration_test/lib/ integration_test:file:///C:/Libs/flutter/packages/integration_test/lib/
localstorage:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/localstorage-3.0.6+9/lib/
logger:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/logger-0.9.4/lib/ logger:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/logger-0.9.4/lib/
matcher:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.10/lib/ matcher:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.10/lib/
meta:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.3.0/lib/ meta:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.3.0/lib/
path:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/path-1.8.0/lib/ path:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/path-1.8.0/lib/
path_provider:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.27/lib/
path_provider_linux:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.0.1+2/lib/
path_provider_macos:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+8/lib/
path_provider_platform_interface:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_platform_interface-1.0.4/lib/
path_provider_windows:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-0.0.5/lib/
pedantic:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/pedantic-1.11.0/lib/ pedantic:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/pedantic-1.11.0/lib/
platform:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/platform-3.0.0/lib/ platform:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/platform-3.0.0/lib/
plugin_platform_interface:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/plugin_platform_interface-1.0.3/lib/
process:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/process-4.0.0/lib/ process:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/process-4.0.0/lib/
shamsi_date:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/shamsi_date-0.8.1/lib/ shamsi_date:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/shamsi_date-0.8.1/lib/
sky_engine:file:///C:/Libs/flutter/bin/cache/pkg/sky_engine/lib/ sky_engine:file:///C:/Libs/flutter/bin/cache/pkg/sky_engine/lib/
...@@ -48,4 +57,6 @@ typed_data:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/typed_data ...@@ -48,4 +57,6 @@ typed_data:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/typed_data
vector_math:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.0/lib/ vector_math:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.0/lib/
vm_service:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/vm_service-5.5.0/lib/ vm_service:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/vm_service-5.5.0/lib/
webdriver:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/webdriver-2.1.2/lib/ webdriver:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/webdriver-2.1.2/lib/
win32:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/win32-2.0.0/lib/
xdg_directories:file:///C:/Libs/flutter/.pub-cache/hosted/pub.dartlang.org/xdg_directories-0.1.2/lib/
dashboard:lib/ dashboard:lib/
...@@ -14,5 +14,6 @@ import io.flutter.embedding.engine.FlutterEngine; ...@@ -14,5 +14,6 @@ import io.flutter.embedding.engine.FlutterEngine;
public final class GeneratedPluginRegistrant { public final class GeneratedPluginRegistrant {
public static void registerWith(@NonNull FlutterEngine flutterEngine) { public static void registerWith(@NonNull FlutterEngine flutterEngine) {
flutterEngine.getPlugins().add(new dev.flutter.plugins.integration_test.IntegrationTestPlugin()); flutterEngine.getPlugins().add(new dev.flutter.plugins.integration_test.IntegrationTestPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.pathprovider.PathProviderPlugin());
} }
} }
class ServerConstants {
static const String host = "https://articonf1.itec.aau.at:30401/";
}
class LoginException implements Exception {
final String message;
LoginException(this.message);
}
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
class LoadingScreen extends StatelessWidget {
final String message;
LoadingScreen({this.message = "Loading..."});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SpinKitRotatingCircle(
color: Theme.of(context).primaryColor,
size: 150.0,
),
SizedBox(height: 16),
Text(message),
],
),
),
);
}
}
import 'package:dashboard/exceptions/login_exception.dart';
import 'package:dashboard/graphing/communitygraph.dart'; import 'package:dashboard/graphing/communitygraph.dart';
import 'package:dashboard/loading.dart';
import 'package:dashboard/sign_in/loginpage.dart';
import 'package:dashboard/util/loginhelper.dart';
import 'package:dashboard/util/user.dart';
import 'package:enhanced_future_builder/enhanced_future_builder.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
void main() { void main() {
runApp(MyApp()); runApp(MyApp());
} }
class MyApp extends StatelessWidget { class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Future<BackendUser> _checkLoginStuff() async {
await Future.delayed(Duration(milliseconds: 500));
try {
return await LoginHelper().loggedInUser;
} on LoginException {
return null;
}
}
@override @override
Widget build(BuildContext context) => MaterialApp( Widget build(BuildContext context) => MaterialApp(
home: CommunityGraphViewPage("worldnews"), home: EnhancedFutureBuilder<BackendUser>(
future: _checkLoginStuff(),
whenNotDone: LoadingScreen(),
rememberFutureResult: false,
whenDone: (BackendUser snapshotData) {
if (snapshotData == null) return LoginPage();
return CommunityGraphViewPage("worldnews");
},
),
); );
} }
...@@ -28,14 +28,19 @@ class _LoginFormState extends State<LoginForm> { ...@@ -28,14 +28,19 @@ class _LoginFormState extends State<LoginForm> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
_busy = false; _busy = false;
return Column( return FractionallySizedBox(
mainAxisSize: MainAxisSize.min, widthFactor: .3,
crossAxisAlignment: CrossAxisAlignment.center, child: FocusTraversalGroup(
children: [ policy: OrderedTraversalPolicy(),
FractionallySizedBox( child: Column(
widthFactor: 0.3, mainAxisSize: MainAxisSize.min,
child: Center( crossAxisAlignment: CrossAxisAlignment.center,
child: TextField( children: [
Image.asset(
"assets/articonf-logo.png",
),
SizedBox(height: 32),
TextField(
readOnly: _busy, readOnly: _busy,
autofocus: true, autofocus: true,
decoration: InputDecoration( decoration: InputDecoration(
...@@ -53,42 +58,54 @@ class _LoginFormState extends State<LoginForm> { ...@@ -53,42 +58,54 @@ class _LoginFormState extends State<LoginForm> {
maxLines: 1, maxLines: 1,
maxLength: 50, maxLength: 50,
), ),
), TextField(
), readOnly: _busy,
FractionallySizedBox( autofocus: false,
widthFactor: 0.3, obscureText: true,
child: TextField( decoration: InputDecoration(
readOnly: _busy, hintText: "Password",
autofocus: false, border: OutlineInputBorder(
obscureText: true, borderRadius: BorderRadius.circular(5.0),
decoration: InputDecoration( borderSide: BorderSide(
hintText: "Password", color: Colors.blue,
border: OutlineInputBorder( style: BorderStyle.solid,
borderRadius: BorderRadius.circular(5.0), ),
borderSide: BorderSide(
color: Colors.blue,
style: BorderStyle.solid,
), ),
), ),
onChanged: (content) => _password = content,
minLines: 1,
maxLines: 1,
maxLength: 50,
), ),
onChanged: (content) => _password = content, // error message
minLines: 1, if (widget.error != null && widget.error.isNotEmpty)
maxLines: 1, Padding(
maxLength: 50, padding: const EdgeInsets.only(bottom: 16.0),
), child: Text(
), widget.error,
// error message style: TextStyle(color: Colors.red),
if (widget.error != null && widget.error.isNotEmpty) ),
Text( ),
widget.error,
style: TextStyle(color: Colors.red), TextButton.icon(
), onPressed: _submit,
FloatingActionButton( icon: Icon(
onPressed: _submit, Icons.login,
child: Icon(Icons.login), size: 32,
backgroundColor: _busy ? Colors.grey : Colors.blue, color: Colors.white,
),
label: Text(
"Sign In",
style: TextStyle(fontSize: 20, color: Colors.white),
),
style: TextButton.styleFrom(
backgroundColor: Theme.of(context).primaryColor,
padding: EdgeInsets.all(18),
),
),
],
), ),
], ),
); );
} }
} }
import 'package:dashboard/exceptions/login_exception.dart';
import 'package:dashboard/main.dart';
import 'package:dashboard/sign_in/login_form.dart'; import 'package:dashboard/sign_in/login_form.dart';
import 'package:dashboard/util/loginhelper.dart';
import 'package:dashboard/util/user.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
class LoginPage extends StatefulWidget { class LoginPage extends StatefulWidget {
LoginPage(); LoginPage();
@override @override
...@@ -10,6 +16,7 @@ class LoginPage extends StatefulWidget { ...@@ -10,6 +16,7 @@ class LoginPage extends StatefulWidget {
class _LoginPageState extends State<LoginPage> { class _LoginPageState extends State<LoginPage> {
String _error; String _error;
final Logger logger = Logger();
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
...@@ -20,32 +27,24 @@ class _LoginPageState extends State<LoginPage> { ...@@ -20,32 +27,24 @@ class _LoginPageState extends State<LoginPage> {
} }
void tryLogin(String username, String password) async { void tryLogin(String username, String password) async {
await Future.delayed(Duration(seconds: 1)); BackendUser user;
setState(() { try {
_error = "Test fehlermeldung :)"; user = await LoginHelper().login(username, password);
}); } on LoginException catch (e) {
setState(() {
// String json = _error = e.message;
// "{\"username\":\"" + username + "\",\"password\":\"" + password + "\"}"; });
return;
// Future<Map<String, dynamic>> tokenJson = JsonGetter.postJson( }
// "https://articonf1.itec.aau.at:30401/api/tokens", json);
logger.i("token: ${user.token}");
// tokenJson.then((value) {
// print("bruh"); // restart app (should login automatically)
// Credentials().token = value["token"] as String; Navigator.of(context).pushReplacement(
// Navigator.push( MaterialPageRoute(
// context, builder: (context) => MyApp(),
// MaterialPageRoute( ),
// builder: (context) => CommunityMetaGraphViewPage())); );
// }).catchError(
// () {
// print("omegabruh");
// setState(
// () => error = "Wrong Credentials :(",
// );
// },
// );
} }
} }
import 'dart:convert';
import 'dart:io';
import 'package:dashboard/constants/server_constants.dart';
import 'package:dashboard/exceptions/login_exception.dart';
import 'package:dashboard/util/user.dart';
import 'package:localstorage/localstorage.dart';
import 'package:logger/logger.dart';
import 'package:http/http.dart' as http;
class LoginHelper {
static final LoginHelper _instance = LoginHelper._internal();
factory LoginHelper() => _instance;
// private constructor
LoginHelper._internal();
final Logger _logger = Logger();
static const String _storageName = "login_storage";
static const String _keyUser = "user";
Future<LocalStorage> get _loginStorage async {
LocalStorage storage = LocalStorage(_storageName);
await storage.ready;
return storage;
}
Future<BackendUser> get loggedInUser async {
LocalStorage storage = await _loginStorage;
Map<String, dynamic> row = storage.getItem(_keyUser);
if (row == null) throw LoginException("No user is currently logged in");
return BackendUser.fromMap(row);
}
Future<void> logout() async {
LocalStorage storage = await _loginStorage;
storage.setItem(_keyUser, null);
}
Future<BackendUser> login(String username, String password) async {
if (username.isEmpty || password.isEmpty)
throw LoginException("Fields cannot be empty!");
String json = jsonEncode({
"username": username,
"password": password,
});
String url = "${ServerConstants.host}/api/tokens";
_logger.v("calling $url");
http.Response response = await http.post(
url,
headers: {
HttpHeaders.contentTypeHeader: "application/json",
},
body: json,
);
if (response.statusCode != 200) {
_logger.e(
"Server responded with (${response.statusCode}): ${response.body}");
if (response.statusCode == 400 &&
response.body.endsWith("does not exist"))
throw LoginException("No user was found!");
throw LoginException(
"An unexpected error occurred (${response.statusCode}");
}
_logger
.v("Server responded with (${response.statusCode}): ${response.body}");
Map<String, dynamic> data = jsonDecode(response.body);
String token = data["token"];
if (token == null || token.isEmpty)
throw LoginException("An unknown problem occurred!");
LocalStorage storage = await _loginStorage;
BackendUser user = BackendUser(username, token);
storage.setItem(_keyUser, user.toMap());
Map<String, dynamic> row = storage.getItem(_keyUser);
return BackendUser.fromMap(row);
}
}
class BackendUser {
final String username;
final String token;
BackendUser(this.username, this.token);
factory BackendUser.fromMap(Map<String, dynamic> row) =>
BackendUser(row["username"], row["token"]);
Map<String, dynamic> toMap() => {"username": username, "token": token};
}
...@@ -56,7 +56,7 @@ packages: ...@@ -56,7 +56,7 @@ packages:
name: circlegraph name: circlegraph
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.0.5" version: "0.0.6"
clock: clock:
dependency: transitive dependency: transitive
description: description:
...@@ -106,6 +106,13 @@ packages: ...@@ -106,6 +106,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0" version: "1.2.0"
ffi:
dependency: transitive
description:
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
file: file:
dependency: transitive dependency: transitive
description: description:
...@@ -123,6 +130,13 @@ packages: ...@@ -123,6 +130,13 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
flutter_spinkit:
dependency: "direct main"
description:
name: flutter_spinkit
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.0"
flutter_test: flutter_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter
...@@ -159,6 +173,13 @@ packages: ...@@ -159,6 +173,13 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.9.2+2" version: "0.9.2+2"
localstorage:
dependency: "direct main"
description:
name: localstorage
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.6+9"
logger: logger:
dependency: "direct main" dependency: "direct main"
description: description:
...@@ -187,6 +208,41 @@ packages: ...@@ -187,6 +208,41 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.0" version: "1.8.0"
path_provider:
dependency: transitive
description:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.27"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1+2"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4+8"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.5"
pedantic: pedantic:
dependency: transitive dependency: transitive
description: description:
...@@ -201,6 +257,13 @@ packages: ...@@ -201,6 +257,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.0.0" version: "3.0.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
process: process:
dependency: transitive dependency: transitive
description: description:
...@@ -297,6 +360,20 @@ packages: ...@@ -297,6 +360,20 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.2" version: "2.1.2"
win32:
dependency: transitive
description:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
sdks: sdks:
dart: ">=2.12.0-0.0 <3.0.0" dart: ">=2.12.0 <3.0.0"
flutter: ">=1.17.0" flutter: ">=2.0.0"
...@@ -15,9 +15,11 @@ dependencies: ...@@ -15,9 +15,11 @@ dependencies:
apex_flutter_sdk: ^1.1.1+1 apex_flutter_sdk: ^1.1.1+1
enhanced_future_builder: ^1.0.3 enhanced_future_builder: ^1.0.3
http: ^0.12.2 http: ^0.12.2
circlegraph: ^0.0.5 circlegraph: ^0.0.6
cupertino_icons: ^1.0.1 cupertino_icons: ^1.0.1
logger: ^0.9.4 logger: ^0.9.4
localstorage: ^3.0.6
flutter_spinkit: ^5.0.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
...@@ -28,6 +30,5 @@ dev_dependencies: ...@@ -28,6 +30,5 @@ dev_dependencies:
flutter: flutter:
assets: assets:
- assets/user.png - assets/
- assets/carcarbinks.jpg
uses-material-design: true uses-material-design: true
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment