This repository was archived by the owner on Jun 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountViewController.m
More file actions
101 lines (85 loc) · 3.47 KB
/
AccountViewController.m
File metadata and controls
101 lines (85 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// AccountViewController.m
// TeachNotes With Parse
//
// Created by Davis Carlson on 2014-06-06.
// Copyright (c) 2014 Davis Carlson. All rights reserved.
//
#import "AccountViewController.h"
@interface AccountViewController ()
@end
@implementation AccountViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
username.text = [[PFUser currentUser]username];
self.navigationController.navigationBarHidden = NO;
}
- (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.
}
*/
-(IBAction)goHome:(id)sender {
UIViewController *home = [self.storyboard instantiateViewControllerWithIdentifier:@"Home"];
home.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:home animated:YES completion:nil];
}
-(IBAction)logOut:(id)sender {
if ([PFUser currentUser]) {
[PFUser logOut];
[self.navigationController popToRootViewControllerAnimated:YES];
} else {
[self.navigationController popToRootViewControllerAnimated:YES];
}
}
-(IBAction)saveUser:(id)sender {
PFUser *currentUser = [PFUser currentUser];
PFQuery *query = [PFUser query];
[query whereKey:@"username" equalTo:username.text];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
NSLog(@"%lu",(unsigned long)[objects count]);
if ([username.text isEqual:currentUser.username]){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"You haven't made a change to your username" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil];
// optional - add more buttons:
[alert show];
} else if ([objects count] == 1) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"A user already has that username" delegate:self cancelButtonTitle:@"Try Again" otherButtonTitles:nil];
// optional - add more buttons:
[alert show];
} else if ([objects count] < 1) {
[[PFUser currentUser] setUsername:username.text];
[[PFUser currentUser] saveInBackground];
[self.view endEditing:YES];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Complete" message:@"Your username has been sucessfully changed" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil];
// optional - add more buttons:
[alert show];
}
}];
}
-(IBAction)savePass:(id)sender {
[[PFUser currentUser] setPassword:password.text];
[[PFUser currentUser] saveInBackground];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Complete" message:@"Your Password Has Been Sucessfully Changed" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil];
// optional - add more buttons:
[alert show];
}
@end