From 3f0bd5febc058c766bf414f60545af409e3d57fb Mon Sep 17 00:00:00 2001 From: Adis Durakovic Date: Tue, 31 Dec 2024 20:51:19 +0100 Subject: [PATCH] feat: multiuser --- android/app/src/main/AndroidManifest.xml | 3 ++- lib/data/models/auth_model.dart | 8 +++---- lib/data/services/api.dart | 14 +++++++++++- pubspec.lock | 29 ++++++++++++++++++++++++ pubspec.yaml | 1 + 5 files changed, 49 insertions(+), 6 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index e87fae7..a55c831 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -4,7 +4,8 @@ - + + diff --git a/lib/data/models/auth_model.dart b/lib/data/models/auth_model.dart index 984b7bf..884a9ee 100644 --- a/lib/data/models/auth_model.dart +++ b/lib/data/models/auth_model.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:convert'; import 'package:flutter/foundation.dart'; +import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:hive_ce_flutter/hive_flutter.dart'; import 'package:odin/data/services/api.dart'; @@ -34,13 +35,13 @@ class AuthModel extends StateNotifier with BaseHelper { AuthObject? me; AuthModel(this.ref, this.db, this.validation) : super(AuthState.error); - Future check() async { + Future check({bool showSelect = false}) async { final allcreds = await getAllCreds(); if (allcreds.isEmpty) { login(); return; } - if (allcreds.length > 0) { + if (allcreds.length > 1 || showSelect) { state = AuthState.multiple; return; } @@ -87,8 +88,7 @@ class AuthModel extends StateNotifier with BaseHelper { Future delete(String id) async { logWarning(id); await db.users?.delete(id); - logInfo(await getAllCreds()); - check(); + check(showSelect: true); } Future clear(String device) async { diff --git a/lib/data/services/api.dart b/lib/data/services/api.dart index 4bc0b4c..5e4c59f 100644 --- a/lib/data/services/api.dart +++ b/lib/data/services/api.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'dart:io'; +import 'package:device_info_plus/device_info_plus.dart'; import 'package:dio/dio.dart'; import 'package:dio/io.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -93,6 +94,15 @@ final statusProvider = FutureProvider((ref) async { }); class ValidationService with BaseHelper { + Future getDeviceInfo() async { + try { + DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); + AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; + return "${androidInfo.manufacturer} ${androidInfo.model}"; + } catch (_) {} + return "Unknown"; + } + Future> check(String url, String device) async { final dio2 = Dio(); (dio2.httpClientAdapter as IOHttpClientAdapter).createHttpClient = () { @@ -116,8 +126,10 @@ class ValidationService with BaseHelper { return handler.next(options); })); + final name = await getDeviceInfo(); + try { - final resp = await dio2.get("$url/-/device/verify/$device"); + final resp = await dio2.get("$url/-/device/verify/$device/$name"); return Right({"status": resp.statusCode!, "user": resp.data}); } on DioException catch (e) { logWarning(e); diff --git a/pubspec.lock b/pubspec.lock index 6e0661b..b08ae03 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -238,6 +238,22 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.7" + device_info_plus: + dependency: "direct main" + description: + name: device_info_plus + sha256: "4fa68e53e26ab17b70ca39f072c285562cfc1589df5bb1e9295db90f6645f431" + url: "https://pub.dev" + source: hosted + version: "11.2.0" + device_info_plus_platform_interface: + dependency: transitive + description: + name: device_info_plus_platform_interface + sha256: "0b04e02b30791224b31969eb1b50d723498f402971bff3630bca2ba839bd1ed2" + url: "https://pub.dev" + source: hosted + version: "7.0.2" dio: dependency: "direct main" description: @@ -360,6 +376,11 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" font_awesome_flutter: dependency: "direct main" description: @@ -1062,6 +1083,14 @@ packages: url: "https://pub.dev" source: hosted version: "5.9.0" + win32_registry: + dependency: transitive + description: + name: win32_registry + sha256: "21ec76dfc731550fd3e2ce7a33a9ea90b828fdf19a5c3bcf556fa992cfa99852" + url: "https://pub.dev" + source: hosted + version: "1.1.5" xdg_directories: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index a11397c..dc71ec3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -38,6 +38,7 @@ dependencies: mqtt_client: json_annotation: google_fonts: + device_info_plus: hive_ce: hive_ce_flutter: html_unescape: