mirror of
https://github.com/lakaola/chat-flutter.git
synced 2026-05-21 00:16:48 +08:00
55 lines
1.2 KiB
Dart
55 lines
1.2 KiB
Dart
import 'dart:math';
|
||
import 'package:demo/tools/tools_regex.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:demo/views/login/login_index_view.dart';
|
||
|
||
// 鉴权接口
|
||
class JsonAuth {
|
||
// 发送验证码
|
||
static Future<String> sendCode(
|
||
String phone,
|
||
) async {
|
||
// 生成一个0到99之间的随机整数(包括0和99)
|
||
int random = Random().nextInt(10000);
|
||
return random.toString().padLeft(4, '0');
|
||
}
|
||
|
||
// 密码登录
|
||
static Future<AuthModel> loginPass(String phone, String password) async {
|
||
return AuthModel.fromJson({'phone': phone});
|
||
}
|
||
|
||
// 验证码登录
|
||
static Future<AuthModel> loginCode(String phone, String code) async {
|
||
return AuthModel.fromJson({'phone': phone});
|
||
}
|
||
|
||
// 注册账号
|
||
static Future<void> register(
|
||
String phone,
|
||
String code,
|
||
) async {}
|
||
|
||
// 退出登录
|
||
static Future<void> logout() async {
|
||
// 跳转
|
||
Get.offAllNamed(LoginIndexView.routeName);
|
||
}
|
||
}
|
||
|
||
class AuthModel {
|
||
String token;
|
||
String phone;
|
||
AuthModel(
|
||
this.token,
|
||
this.phone,
|
||
);
|
||
|
||
factory AuthModel.fromJson(Map<String, dynamic>? data) {
|
||
return AuthModel(
|
||
data?['token'] ?? ToolsRegex.token(),
|
||
data?['phone'] ?? '',
|
||
);
|
||
}
|
||
}
|