Blame view

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