PFUser *user = [PFUser currentUser];
// I can see the details of the users when this is called including password
if (user) {
if ([_login_txtpassword.text isEqualToString:user[@"UserPasswrod"]]) {
user[@"userPassword"] = _login_txtnewpassword.text;
[user saveInBackground];
NSLog(@"done");
}
}
此代码不起作用。我已经放了块来测试我的代码...它不传递 if 语句
与解析相关的概念中的一些冲突(所以将我视为菜鸟(附言我已经阅读了文档并搜索了互联网,但找不到解决方案。
非常感谢
正确的方法是尝试使用旧密码登录用户,如果成功,则设置新密码。 (请注意,此代码使用 parse 用户password
属性,而不是像 OP 代码中那样@"userPassword"
,这在任何情况下都不起作用(...
NSString *username = [PFUser currentUser].username;
NSString *oldPassword = self.oldPasswordTextField.text;
NSString *newPassword = self.newPasswordTextField.text;
[PFUser logInWithUsernameInBackground:username password:oldPassword
block:^(PFUser *user, NSError *error) {
if (user) {
user.password = newPassword;
[user saveInBackground];
} else {
// update UI to tell user that the old password is incorrect
}
}];
实际上,
您无法直接从ViewController覆盖当前用户的密码。用户应该请求一个新密码,该密码将通过Parse发送到他/她的电子邮件。
PFUser *currentUser = [PFUser currentUser];
NSString *userEmail = [NSString stringWithFormat: @"%@", currentUser.email];
[PFUser requestPasswordResetForEmailInBackground:userEmail];
或
[PFUser requestPasswordResetForEmailInBackground:self.userEmailTextfield.text];