예제 #1
0
  /** 修改email(API上说的开启邮箱验证不知道怎么开???) */
  public void updEmail() {
    String email = setEmail.getText().toString();
    AVUser currentUser = AVUser.getCurrentUser();
    if (TextUtils.isEmpty(email) || currentUser == null || !currentUser.isAuthenticated()) return;
    showLoadingDialog("修改邮箱...");

    currentUser.setEmail(email);
    currentUser.saveInBackground(saveCallback);
  }
예제 #2
0
  /** 更新用户名(login和signUp得到的user是授权的) */
  public void updUsername() {
    AVUser user = AVUser.getCurrentUser();
    String usernmae = setUsername.getText().toString();
    if (TextUtils.isEmpty(usernmae)) return;
    if (user == null) {
      Utils.showToast(this, "当前无登陆用户");
      return;
    }
    if (!user.isAuthenticated()) {
      Utils.showToast(this, "当前登陆用户无授权,请重新登录");
      return;
    }
    showLoadingDialog("正在更改username");
    user.setUsername(usernmae); // 自己的用户信息登陆后可以修改
    user.saveInBackground(
        new SaveCallback() {
          @Override
          public void done(AVException e) {
            if (e == null) {
              textView.setText("保存成功");
            } else {
              textView.setText(e.getMessage());
            }
            AVUser user1 = AVUser.getCurrentUser();
            if (user1 != null) {
              Log.i("Session-token", user1.getUsername() + user1.getSessionToken());
            }
            cancelLoadingDialog();
          }
        });

    // 查询得到的user都是没有授权的
    /*ParseQuery<ParseUser> query = ParseUser.getQuery();
    query.getInBackground("WXIMPuEaUZ", new GetCallback<ParseUser>() {
        @Override
        public void done(ParseUser object, ParseException e) {
            if (object != null) {
                object.setUsername("李某某");
                object.saveInBackground(saveCallback);
            }
        }
    });*/
  }
예제 #3
0
 /** 手动更改密码,更改后自动重新登陆即可同步session-token */
 public void updPassword() {
   final String password = setPassword.getText().toString();
   final AVUser currentUser = AVUser.getCurrentUser();
   if (TextUtils.isEmpty(password) || currentUser == null || !currentUser.isAuthenticated())
     return;
   showLoadingDialog("正在修改密码...");
   currentUser.setPassword(password); // 修改完密码后session-token会失效(再去修改用户信息时异常),重新登陆(重置了session-token)
   currentUser.saveInBackground(
       new SaveCallback() {
         @Override
         public void done(AVException e) {
           if (e == null) { // 修改成功
             cancelLoadingDialog();
             showLoadingDialog("正在重新登陆");
             AVUser.logInInBackground(
                 currentUser.getUsername(),
                 password,
                 new LogInCallback<User>() {
                   @Override
                   public void done(User newUser, AVException e) {
                     if (e == null) {
                       Utils.showToast(UserActivity.this, "重新登陆成功");
                       textView.setText(
                           "Username:"******"\n"
                               + "DisplayName:"
                               + newUser.getDisplayName()
                               + "\n");
                     } else {
                       textView.setText(e.getMessage());
                     }
                     cancelLoadingDialog();
                   }
                 },
                 User.class);
           } else {
             textView.setText(e.getMessage());
             cancelLoadingDialog();
           }
         }
       });
 }
예제 #4
0
 /** 重置密码(通过邮箱验证,会先检验邮箱正确与否),往往在忘记密码时候使用,所以无需注销 */
 public void resetPwd() {
   final String email = setEmail.getText().toString();
   AVUser currentUser = AVUser.getCurrentUser();
   if (TextUtils.isEmpty(email) || currentUser == null || !currentUser.isAuthenticated()) return;
   showLoadingDialog("重置密码中...");
   AVUser.requestPasswordResetInBackground(
       email,
       new RequestPasswordResetCallback() {
         @Override
         public void done(AVException e) {
           if (e == null) {
             Utils.showToast(UserActivity.this, "重置密码成功,请去" + email + "邮箱验证");
           } else {
             textView.setText(e.getMessage());
           }
           cancelLoadingDialog();
         }
       });
 }
예제 #5
0
 /** 验证手机号 */
 public void signMobile() {
   String code = setCode.getText().toString();
   AVUser user = AVUser.getCurrentUser();
   if (TextUtils.isEmpty(code) || user == null || !user.isAuthenticated()) return;
   showLoadingDialog("正在验证手机号");
   AVUser.verifyMobilePhoneInBackground(
       code,
       new AVMobilePhoneVerifyCallback() {
         @Override
         public void done(AVException e) {
           if (e == null) {
             Utils.showToast(UserActivity.this, "手机号验证成功!");
           } else {
             textView.setText(e.getMessage());
           }
           cancelLoadingDialog();
         }
       });
 }