gpt4 book ai didi

ios - 更改密码 PFuser

转载 作者:行者123 更新时间:2023-11-29 03:05:52 25 4
gpt4 key购买 nike

如何让用户更改密码、邮件、用户名等。有什么想法吗?到目前为止,我有这段代码,您可以在下面看到。我的问题是旧数据没有显示,我无法更新它。我会喜欢一些帮助! :) 非常感谢

#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import <MobileCoreServices/UTCoreTypes.h>
#import <QuartzCore/QuartzCore.h>

@interface SettingsUPEViewController : UIViewController <UITextFieldDelegate>




@property (strong, nonatomic) IBOutlet UITextField *usernameField;

@property (strong, nonatomic) IBOutlet UITextField *passwordField;
//@property (strong, nonatomic) IBOutlet UITextField *password2Field;
@property (strong, nonatomic) IBOutlet UITextField *mailField;
- (IBAction)updateSave:(id)sender;

@end





#import "SettingsUPEViewController.h"

@interface SettingsUPEViewController ()


@end

@implementation SettingsUPEViewController


NSArray *retriveFormParse;
NSArray *profileArray;


- (id)initWithCoder:(NSCoder *)aCoder
{
self = [super initWithCoder:aCoder];
if (self) {

PFQuery *query= [PFUser query];

[query whereKey:@"username" equalTo:[[PFUser currentUser]username]];



[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {

profileArray = [[NSArray alloc] initWithArray:objects];






// The find succeeded.
NSLog(@"@%", objects.count);
// Do something with the found objects
for (PFObject *object in objects) {
NSLog(@"%@", objects);
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];



}
return self;
}


- (void)viewDidLoad
{
[super viewDidLoad];



PFQuery *query= [PFUser query];

[query whereKey:@"username" equalTo:[[PFUser currentUser]username]];

PFObject *object = [query getFirstObject]; // synchronous request, not ideal, look at getFirstObjectInBackgroundWithBlock

_usernameField.text = [object valueForKey:@"newname"];
_passwordField.text = [object valueForKey:@"newpassword"];
_mailField.text = [object valueForKey:@"newmail"];

_usernameField.delegate = self;
_passwordField.delegate = self;
_mailField.delegate = self;



_usernameField.delegate = self;
_passwordField.delegate = self;
_mailField.delegate = self;



_usernameField.layer.masksToBounds=YES;
_usernameField.layer.borderColor=[[UIColor whiteColor]CGColor];
_usernameField.layer.borderWidth= 1.0f;

_passwordField.layer.masksToBounds=YES;
_passwordField.layer.borderColor=[[UIColor whiteColor]CGColor];
_passwordField.layer.borderWidth= 1.0f;


//_password2Field.layer.masksToBounds=YES;
//_password2Field.layer.borderColor=[[UIColor whiteColor]CGColor];
//_password2Field.layer.borderWidth= 1.0f;


_mailField.layer.masksToBounds=YES;
_mailField.layer.borderColor=[[UIColor whiteColor]CGColor];
_mailField.layer.borderWidth= 1.0f;




_usernameField.delegate = self;
_passwordField.delegate = self;
_mailField.delegate = self;

}


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSUInteger newLength = [textField.text length] + [string length] - range.length;
return (newLength > 18) ? NO : YES;
}

- (void) retriveFromParse {

PFQuery *query= [PFUser query];

[query whereKey:@"username" equalTo:[[PFUser currentUser]username]];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"@%", objects.count);
// Do something with the found objects
for (PFObject *object in objects) {
NSLog(@"%@", objects);
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];

}

- (IBAction)updateSave:(id)sender {
// Create PFObject with recipe information
PFUser *profile = [PFUser currentUser];
[profile setObject:_usernameField.text forKey:@"newname"];
[profile setObject:_passwordField.text forKey:@"newpassword"];
[profile setObject:_mailField.text forKey:@"newmail"];




// Upload recipe to Parse
[profile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {


if (!error) {
// Show success message
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Upload Complete" message:@"Successfully saved profile" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];

// Notify table view to reload the profile from Parse cloud

// Dismiss the controller
// [self dismissViewControllerAnimated:YES completion:nil];
[self performSegueWithIdentifier:@"nameSet" sender:self];

} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Upload Failure" message:[error localizedDescription] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];

}

}];

}


/// if(![oldPassword.text isEqualToString:[user password]]){
/// [alertMessagePassword setMessage:@"The old password is incorrect!"];
/// [alertMessagePassword show];





#pragma mark - Textfield delegate

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}




@end

最佳答案

您的代码看起来不错。只有这个应该有效:

[PFUser currentUser].password = someTextField.text;

但有时 XCode 会缓存数据。清理您的项目,然后再次尝试构建。

关于ios - 更改密码 PFuser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22781831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com