forked from zhoho/APP_ConveUntact_Yookhaehan
generated from osamhack2021/flutter-devcontainer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
unit_controller.dart
64 lines (54 loc) · 1.79 KB
/
unit_controller.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import 'package:get/get.dart';
import 'package:myapp/domain/unit/unit.dart';
import 'package:myapp/domain/unit/unit_repository.dart';
class UnitController extends GetxController {
final UnitRepository _UnitRepository = UnitRepository();
final RxBool isLogin = false.obs; // UI가 관찰 가능한 변수 => 변경 => UI가 자동 업데이트
final principal = Unit().obs;
Future<void> logout() async {
await _UnitRepository.logout();
this.principal.value = Unit();
this.isLogin.value = false;
// Get.Storage()
}
Future<void> findByEmail(String email) async {
Unit unit = await _UnitRepository.findByEmail(email);
this.principal.value = unit;
}
Future<void> findByCode(String unitcode) async {
Unit unit = await _UnitRepository.findByCode(unitcode);
this.principal.value = unit;
}
Future<int> login(String email, String password) async {
Unit principal = await _UnitRepository.login(email, password);
if (principal.uid != null) {
this.isLogin.value = true;
this.principal.value = principal;
return 1;
} else {
return -1;
}
}
Future<int> join(Unit newunit, String? password) async {
print("----------------");
print(newunit.unitcode);
print(newunit.unitname);
print(password);
print(newunit.picture);
print(newunit.email);
print("----------------");
Unit principal = await _UnitRepository.join(newunit, password);
if (principal.uid != null) {
this.isLogin.value = true;
this.principal.value = principal;
print("uid : ${principal.uid}");
print("isLogin : ${isLogin.value}");
print(this.principal.value);
return 1;
} else {
return -1;
}
}
Future<int> checkCode(String unitcode) async =>
await _UnitRepository.checkCode(unitcode);
}