/** 登陆 */ public void login() { String username = setUsername.getText().toString(); String password = setPassword.getText().toString(); if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) return; if (AVUser.getCurrentUser() != null) { showLoadingDialog("当前用户为:" + AVUser.getCurrentUser().getUsername() + "\n正在切换用户..."); } else { showLoadingDialog("正在登陆..."); } AVUser.logInInBackground( username, password, new LogInCallback<AVUser>() { @Override public void done(AVUser u, AVException e) { if (e == null) { Utils.showToast(UserActivity.this, "登陆成功"); User user = AVUser.getCurrentUser(User.class); textView.setText( "Username:"******"\n" + "DisplayName:" + user.getDisplayName() + "\n"); Log.i("Session-token", user.getUsername() + user.getSessionToken()); } else { textView.setText(e.getMessage()); } cancelLoadingDialog(); } }); }
/** 登录 */ private void login(final String username, final String password) { AVUser.logInInBackground( username, password, new LogInCallback<AVUser>() { @Override public void done(AVUser avUser, AVException e) { if (e == null) { // 登录成功,将账号、密码保存到本地 preference.putString(NotePreference.ACCOUNT, username); preference.putString(NotePreference.PASSWORD, password); openActivity(MainActivity.class, null); } else { showToast(e.getMessage()); } } }); }
private void login() { String userName = userNameEt.getText().toString(); String password = passwordEt.getText().toString(); if (!TextUtils.isEmpty(userName) && !TextUtils.isEmpty(password)) { AVUser.logInInBackground( userName, password, new LogInCallback() { public void done(AVUser user, AVException e) { if (user != null) { Notify.getInstance() .NotifyActivity(new NotifyInfo(EventType.EVENT_LOGIN)); // 通知登录成功 finish(); } else { Toast.makeText(LoginRegActivity.this, "用户名或密码错误!", Toast.LENGTH_LONG).show(); } } }); } }
/** * 用户创建结果的回调 * * @param event */ public void onEventMainThread(UserCreateEvent event) { if (event.isSuccess()) { EventBus.getDefault().post(new LoginActivityFinishEvent()); // 记录登陆状态 PreferenceHelper.getInstance(getContext()).setIsFistIn(false); // 注册后直接登陆 AVUser.logInInBackground( etUserName.getText().toString(), etPassword.getText().toString(), new LogInCallback<AVUser>() { @Override public void done(AVUser avUser, AVException e) { EventBus.getDefault().post(new LoginActivityFinishEvent()); MainActivity.start(getContext()); ToastHelper.show(getContext(), "登陆成功"); } }); } else { ToastHelper.show(getContext(), "该用户名已被使用"); EventBus.getDefault().post(new ProgressBarEvent(false)); btnSignup.setClickable(true); } }