Blame view

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