user_dao.dart
1.97 KB
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:wow_english/common/core/user_util.dart';
import 'package:wow_english/models/user_entity.dart';
import '../request_client.dart';
class UserDao {
/// 登录
static Future<UserEntity?> login(phoneNumber, type, checkKey, checkNumber) async {
var params = {'phoneNum': phoneNumber, 'type': type, checkKey: checkNumber};
var data = await requestClient.post<UserEntity>(
Apis.login,
data: params,
);
if (data != null && data.token.isNotEmpty) {
UserUtil.saveUser(data);
}
return data;
}
/// 登出
static Future logout() async {
var result = await requestClient.post(Apis.logout);
print('logout result=$result');
UserUtil.logout();
return result;
}
/// 发送验证码
static Future sendCode(phoneNumber, {smsType = 'login'}) async {
final params = {'phoneNum': phoneNumber, 'smsType': smsType};
await requestClient.post(Apis.sendSmsCode, data: params);
}
/// 设置密码,初始化密码
/// [password] 密码
static Future initPassword(String password) async {
final params = {'password': password};
await requestClient.post(Apis.initPassword, data: params);
}
/// 修改密码
/// [password] 密码
static Future changePassword(String password) async {
final params = {'password': password};
await requestClient.post(Apis.changePassword, data: params);
}
/// 忘记密码
/// [password] 密码
static Future resetPassword(String phoneNum, String password, String smsCode) async {
final params = {'phoneNum': phoneNum, 'password': password, 'code': smsCode};
await requestClient.post(Apis.resetPassword, data: params);
}
/// 获取用户信息
static Future<UserEntity?> getUserInfo() async {
return await requestClient.post(Apis.getUserInfo);
}
/// 更新用户信息,返回即成功,无body
static Future updateUserInfo(UserEntity userEntity) async {
return await requestClient.put(Apis.setUserInfo, data: userEntity.toUpdateJson());
}
}