Search in sources :

Example 1 with UserBean

use of com.mtm.mrecord.mvp.model.entity.UserBean in project Mvp-Rxjava-Retrofit-dagger2 by pengMaster.

the class SplashPresenter method login4userInfo.

/**
 * 登录并获取用户信息
 *
 * @param loginUserBean
 */
private void login4userInfo(LoginUserBean loginUserBean) {
    try {
        boolean loginType = loginUserBean.isLoginType();
        if (!loginType) {
            showInfoDialog("登陆失败", "请重新进行人员认证!");
            return;
        }
        UserBean user = loginUserBean.getUser();
        // 将User存放全局
        GlobalConstantUtils.setUser(user);
        // 将User存本地
        Gson gson = new Gson();
        String jsonStr = gson.toJson(user);
        // 设置当前时间
        setLoginDate();
        // 将用户名密码写进手机Data目录
        String fxyjPackagePath = FileUtils.getPackagePath(AppLifecyclesImpl.mAppContext);
        FileUtils.createDirs(fxyjPackagePath);
        FileUtils.writeProperties(FileUtils.loginPath(AppLifecyclesImpl.mAppContext), "USER", jsonStr, true, "");
        // 登录跳转
        toActDownLoadNetKey();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : UserBean(com.mtm.mrecord.mvp.model.entity.UserBean) LoginUserBean(com.mtm.mrecord.mvp.model.entity.LoginUserBean) Gson(com.google.gson.Gson) LoginException(javax.security.auth.login.LoginException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 2 with UserBean

use of com.mtm.mrecord.mvp.model.entity.UserBean in project Mvp-Rxjava-Retrofit-dagger2 by pengMaster.

the class SplashPresenter method getLoginUserInfo.

/**
 * 获取登录User信息
 *
 * @param u 用户名
 * @param p 用户密码
 */
private void getLoginUserInfo(String u, String p) {
    try {
        // 读取存储到本地的User信息
        String filePath = FileUtils.loginPath(AppLifecyclesImpl.mAppContext);
        String str = FileUtils.readProperties(filePath, "USER", "");
        String date = FileUtils.readProperties(filePath, "DATE", "");
        Gson gson = new Gson();
        UserBean user = gson.fromJson(str, new TypeToken<UserBean>() {
        }.getType());
        // 本地缓存有数据
        if (null != user) {
            GlobalConstantUtils.setUser(user);
            GlobalConstantUtils.setLoginDate(date);
            // 放自己的的登录跳转
            toActDownLoadNetKey();
        } else {
            // 没有数据在线下载
            if (TextUtils.isEmpty(u) || TextUtils.isEmpty(p)) {
                // showInfoDialog("未登录", "请在监督执法桌面 - 我的 中进行人员认证后重试!");
                // 放自己的的登录跳转
                toActDownLoadNetKey();
            } else {
                login(u, p);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : UserBean(com.mtm.mrecord.mvp.model.entity.UserBean) LoginUserBean(com.mtm.mrecord.mvp.model.entity.LoginUserBean) TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) LoginException(javax.security.auth.login.LoginException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 3 with UserBean

use of com.mtm.mrecord.mvp.model.entity.UserBean in project Mvp-Rxjava-Retrofit-dagger2 by pengMaster.

the class SettingFragment method initData.

@Override
public void initData(Bundle savedInstanceState) {
    if (GlobalConstantUtils.user != null) {
        UserBean user = GlobalConstantUtils.getUser();
        tvUserName.setText(user.getUserName());
        tvPhone.setText(user.getSupervisorsNumber());
    } else {
        tvUserName.setText("请登录");
        tvPhone.setVisibility(View.GONE);
    }
}
Also used : UserBean(com.mtm.mrecord.mvp.model.entity.UserBean)

Aggregations

UserBean (com.mtm.mrecord.mvp.model.entity.UserBean)3 Gson (com.google.gson.Gson)2 LoginUserBean (com.mtm.mrecord.mvp.model.entity.LoginUserBean)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 LoginException (javax.security.auth.login.LoginException)2 TypeToken (com.google.gson.reflect.TypeToken)1