Skip to content

Commit

Permalink
Update LoginController.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
mortzaCFT authored Nov 9, 2024
1 parent 98d7e73 commit e6005d6
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/controllers/LoginController.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:msf/screens/HomeScreen.dart';
import '../unit/com.dart';
import 'package:msf/unit/api/HttpService.dart';
import 'package:msf/unit/api/WebSocketService.dart';
import 'package:msf/unit/com.dart';

class LoginController extends GetxController {
var loginProcess = false.obs;
Expand All @@ -11,12 +13,15 @@ class LoginController extends GetxController {
String username = "";
String password = "";

final Com _communication = Com();
final Com api = Com(
httpService: HttpService(),
webSocketService: WebSocketService(),
);

Future<void> login(String username, String password) async {
this.username = username;
this.password = password;
print("received login input");
print("Received login input");

if (username.isEmpty || password.isEmpty) {
Get.snackbar(
Expand Down Expand Up @@ -44,9 +49,9 @@ class LoginController extends GetxController {
}

loginProcess.value = true;
await _communication.login(username, password);
await api.login(username, password);

if (_communication.sessionId != null) {
if (api.httpService.sessionId != null) {
otpRequired.value = true;
Get.snackbar(
"",
Expand Down Expand Up @@ -102,7 +107,7 @@ class LoginController extends GetxController {
Future<void> verifyOtp(int otp) async {
loginProcess.value = true;

final otpSuccess = await _communication.verifyOtp(otp);
final otpSuccess = await api.verifyOtp(otp);

if (otpSuccess) {
loginSuccess.value = true;
Expand All @@ -121,8 +126,9 @@ class LoginController extends GetxController {
icon: const Padding(
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
child: Icon(
Icons.info_sharp,
Icons.check_circle,
size: 30,
color: Colors.green,
),
),
maxWidth: 360,
Expand All @@ -145,8 +151,9 @@ class LoginController extends GetxController {
icon: const Padding(
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
child: Icon(
Icons.info_sharp,
Icons.error,
size: 30,
color: Colors.red,
),
),
maxWidth: 360,
Expand Down

0 comments on commit e6005d6

Please sign in to comment.