Skip to content

Commit

Permalink
feat: multiuser
Browse files Browse the repository at this point in the history
  • Loading branch information
Adis Durakovic committed Dec 31, 2024
1 parent f32d278 commit 3f0bd5f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
3 changes: 2 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.microphone" android:required="false" />
<uses-feature android:name="android.software.leanback" android:required="false" />
Expand Down
8 changes: 4 additions & 4 deletions lib/data/models/auth_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -34,13 +35,13 @@ class AuthModel extends StateNotifier<AuthState> with BaseHelper {
AuthObject? me;
AuthModel(this.ref, this.db, this.validation) : super(AuthState.error);

Future<void> check() async {
Future<void> 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;
}
Expand Down Expand Up @@ -87,8 +88,7 @@ class AuthModel extends StateNotifier<AuthState> with BaseHelper {
Future<void> delete(String id) async {
logWarning(id);
await db.users?.delete(id);
logInfo(await getAllCreds());
check();
check(showSelect: true);
}

Future<void> clear(String device) async {
Expand Down
14 changes: 13 additions & 1 deletion lib/data/services/api.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -93,6 +94,15 @@ final statusProvider = FutureProvider<dynamic>((ref) async {
});

class ValidationService with BaseHelper {
Future<String> getDeviceInfo() async {
try {
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
return "${androidInfo.manufacturer} ${androidInfo.model}";
} catch (_) {}
return "Unknown";
}

Future<Either<bool, dynamic>> check(String url, String device) async {
final dio2 = Dio();
(dio2.httpClientAdapter as IOHttpClientAdapter).createHttpClient = () {
Expand All @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies:
mqtt_client:
json_annotation:
google_fonts:
device_info_plus:
hive_ce:
hive_ce_flutter:
html_unescape:
Expand Down

0 comments on commit 3f0bd5f

Please sign in to comment.