Blame view

lib/common/request/dao/user_dao.dart 3.77 KB
94342c3f   Key   feat: user util
1
  import 'package:wow_english/common/core/user_util.dart';
05f9b20a   Key   fixed: api调用方式,未完善
2
  import 'package:wow_english/models/user_entity.dart';
e6a4e63c   Key   fixed: 修改个人信息性别
3
  import 'package:wow_english/utils/log_util.dart';
05f9b20a   Key   fixed: api调用方式,未完善
4
  
056970d8   Key   feat: api
5
6
  import '../request_client.dart';
  
da82bd70   Key   feat: user_inform...
7
8
  enum SmsType { login, change_passWord, stdDestroy }
  
056970d8   Key   feat: api
9
  class UserDao {
c95453ce   Key   feat: User界面完善
10
    /// 登录
94342c3f   Key   feat: user util
11
    static Future<UserEntity?> login(phoneNumber, type, checkKey, checkNumber) async {
05f9b20a   Key   fixed: api调用方式,未完善
12
      var params = {'phoneNum': phoneNumber, 'type': type, checkKey: checkNumber};
94342c3f   Key   feat: user util
13
      var data = await requestClient.post<UserEntity>(
05f9b20a   Key   fixed: api调用方式,未完善
14
15
16
        Apis.login,
        data: params,
      );
aa4e28be   Key   removed: cache_bl...
17
      if (data != null) {
94342c3f   Key   feat: user util
18
        UserUtil.saveUser(data);
278208b8   吴启风   feat:1、用户访问权限调整;2...
19
20
21
22
23
24
        // 由于userInfo接口不会返回token,所以这里需要再次保存一下token
        final token = data.token;
        //登录成功后zip一下getUserInfo,因为进入首页需要的信息在userinfo里,保证进入首页数据是最新的
        data = await getUserInfo();
        data?.token = token;
        UserUtil.saveUser(data);
94342c3f   Key   feat: user util
25
      }
05f9b20a   Key   fixed: api调用方式,未完善
26
      return data;
056970d8   Key   feat: api
27
    }
39e06486   liangchengyou   feat:获取验证码逻辑处理
28
  
c95453ce   Key   feat: User界面完善
29
30
31
    /// 登出
    static Future logout() async {
      var result = await requestClient.post(Apis.logout);
a4d8eaa2   Key   feat: 登录时账户有效性校验
32
33
34
35
36
37
      UserUtil.logout();
      return result;
    }
  
    /// 注销账号
    static Future deleteAccount() async {
210d15e0   Key   fixed: 账户注销接口
38
      var result = await requestClient.put(Apis.deleteAccount);
c95453ce   Key   feat: User界面完善
39
40
41
42
43
      UserUtil.logout();
      return result;
    }
  
    /// 发送验证码
da82bd70   Key   feat: user_inform...
44
    /// [msgType] 消息类型 登录:login, 更改密码:change_passWord, 账号注销:stdDestroy
c95453ce   Key   feat: User界面完善
45
46
47
48
49
    static Future sendCode(phoneNumber, {smsType = 'login'}) async {
      final params = {'phoneNum': phoneNumber, 'smsType': smsType};
      await requestClient.post(Apis.sendSmsCode, data: params);
    }
  
4b2c2f07   Key   feat: 三种修改密码的类型及接口
50
51
52
53
54
55
56
57
    /// 设置密码,初始化密码
    /// [password] 密码
    static Future initPassword(String password) async {
      final params = {'password': password};
      await requestClient.post(Apis.initPassword, data: params);
    }
  
    /// 修改密码
da82bd70   Key   feat: user_inform...
58
    /// [phoneNum] 手机号
4b2c2f07   Key   feat: 三种修改密码的类型及接口
59
    /// [password] 密码
da82bd70   Key   feat: user_inform...
60
61
62
    /// [smsCode] 短信验证码
    static Future changePassword(String phoneNum, String password, String smsCode) async {
      final params = {'phoneNum': phoneNum, 'password': password, 'code': smsCode};
4b2c2f07   Key   feat: 三种修改密码的类型及接口
63
64
65
66
      await requestClient.post(Apis.changePassword, data: params);
    }
  
    /// 忘记密码
da82bd70   Key   feat: user_inform...
67
    /// [phoneNum] 手机号
4b2c2f07   Key   feat: 三种修改密码的类型及接口
68
    /// [password] 密码
da82bd70   Key   feat: user_inform...
69
    /// [smsCode] 短信验证码
4b2c2f07   Key   feat: 三种修改密码的类型及接口
70
71
72
73
74
    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);
    }
  
da82bd70   Key   feat: user_inform...
75
76
77
78
79
80
81
    /// 验证短信验证码
    /// [msgType] 消息类型 登录:login, 更改密码:change_passWord, 账号注销:stdDestroy
    static Future checkSmsCode(String phoneNum, String smsCode, String msgType) async {
      final params = {'phoneNum': phoneNum, 'code': smsCode, 'msgType': msgType};
      await requestClient.post(Apis.checkSmsCode, data: params);
    }
  
c95453ce   Key   feat: User界面完善
82
83
    /// 获取用户信息
    static Future<UserEntity?> getUserInfo() async {
a4d8eaa2   Key   feat: 登录时账户有效性校验
84
      return await requestClient.get(Apis.getUserInfo);
c95453ce   Key   feat: User界面完善
85
86
87
88
    }
  
    /// 更新用户信息,返回即成功,无body
    static Future updateUserInfo(UserEntity userEntity) async {
e6a4e63c   Key   fixed: 修改个人信息性别
89
      Log.d('updateUserInfo, userEntity: $userEntity');
c95453ce   Key   feat: User界面完善
90
      return await requestClient.put(Apis.setUserInfo, data: userEntity.toUpdateJson());
39e06486   liangchengyou   feat:获取验证码逻辑处理
91
    }
e6a4e63c   Key   fixed: 修改个人信息性别
92
  
01e73e19   Key   暂时关闭修改个人信息
93
94
95
    /// 更新用户信息指定字段
    static Future updateUserInfoField({String? name, int? age, int? gender, String? avatarUrl}) async {
      Log.d('name=$name, age=$age, gender=$gender, avatarUrl=$avatarUrl');
e6a4e63c   Key   fixed: 修改个人信息性别
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
      final Map<String, dynamic> data = <String, dynamic>{};
      if (name != null) {
        data['name'] = name;
      }
      if (age != null) {
        data['age'] = age;
      }
      if (gender != null) {
        data['gender'] = gender;
      }
      if (avatarUrl != null) {
        data['avatarUrl'] = avatarUrl;
      }
      return await requestClient.put(Apis.setUserInfo, data: data);
    }
056970d8   Key   feat: api
111
  }