public void tryLog(final String id, final String psw, final ContextCallback contextCallback) { final User user = new User(); user.setId(id); user.setPassWord(psw); HttpApi.log( user, new HttpListener() { @Override public void succ(String message, String data, byte[] bytes) { getDataProvider().setUserState(DataProvider.LOGIN); try { user.initByJson(data); } catch (JSONException e) { e.printStackTrace(); } getDataProvider().setUser(user); if (user == null) { contextCallback.response(ContextCallback.FAIL, "数据处理出错"); return; } if (isIdExist(user.getId())) { String[] attr = {DataBaseTable.UserDataTable.ID}; String[] value = {user.getId()}; dataBaseOperator.update( user, DataBaseTable.UserDataTable.USER_TABLE_NAME, attr, value); } else { dataBaseOperator.insert(user, DataBaseTable.UserDataTable.USER_TABLE_NAME); } contextCallback.response(ContextCallback.SUCC, message); recordAccunt(id, psw); getPhoto(user.getImg(), contextCallback); } @Override public void fail(String message) { contextCallback.response(ContextCallback.FAIL, "登录失败"); } }); }
public void tryReg( final String account, final String password, final String nickname, final ContextCallback contextCallback) { final User user = new User(); user.setPassWord(password); user.setId(account); user.setNickName(nickname); HttpApi.register( user, new HttpListener() { @Override public void succ(String message, String data, byte[] bytes) { getDataProvider().setUser(user); contextCallback.response(ContextCallback.SUCC, message); } @Override public void fail(String message) { contextCallback.response(ContextCallback.FAIL, message); } }); }
public void forceTolog(ContextCallback contextCallback) { user.setId(sharedPreference.get("account", "")); user.setPassWord(sharedPreference.get("password", "")); this.tryAutoLog(contextCallback); }