Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. NSArray *results = [context executeFetchRequest:request error:&error];
  2.  
  3. for (AccountBase *account in results) {
  4.  
  5. _label.text = [NSString stringWithFormat:@"%@", account.email];
  6.  
  7. }
  8.  
  9. -(IBAction)signup:(id)sender{
  10.  
  11. NSManagedObjectContext *context = [self managedObjectContext];
  12.  
  13. if (self.contactdb) {
  14. // Update existing device
  15. // [self.contactdb setValue:self.fullname.text forKey:@"fullname"];
  16. //[self.contactdb setValue:self.email.text forKey:@"email"];
  17. //[self.contactdb setValue:self.phone.text forKey:@"phone"];
  18.  
  19. } else {
  20. // Create a new device
  21. NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:@"Account" inManagedObjectContext:context];
  22. [newDevice setValue:self.email.text forKey:@"email"];
  23. [newDevice setValue:self.password.text forKey:@"password"];
  24.  
  25. NSLog(@"%@",newDevice);
  26. //[newDevice setValue:self.phone.text forKey:@"phone"];
  27. }
  28. NSError *error = nil;
  29. // Save the object to persistent store
  30. if (![context save:&error]) {
  31. NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
  32. }
  33.  
  34. [self dismissViewControllerAnimated:YES completion:nil];
  35.  
  36. - (IBAction)processLogin:(id)sender {
  37.  
  38.  
  39.  
  40. NSManagedObjectContext *context = [self managedObjectContext];
  41.  
  42. // CORE DATA
  43. NSFetchRequest *request = [[NSFetchRequest alloc] init];
  44. NSEntityDescription *entity = [NSEntityDescription entityForName:@"Account" inManagedObjectContext:context];
  45.  
  46. // set entity for request
  47. [request setEntity:entity];
  48.  
  49. // filter results using a predicate
  50. NSPredicate *pred =[NSPredicate predicateWithFormat:(@"email = %@"), _emailfld.text];
  51. NSPredicate *pred2 =[NSPredicate predicateWithFormat:(@"password = %@"), _passwordfld.text];
  52.  
  53. // set predicate for the request
  54. [request setPredicate:pred];
  55. [request setPredicate:pred2];
  56.  
  57. NSError *error = nil;
  58.  
  59. // store DB usernames in results array
  60. NSArray *results = [context executeFetchRequest:request error:&error];
  61.  
  62. NSLog(@"The returned results are %@",results);
  63.  
  64. // check text field against results stored in DB
  65. for (Account *anAccount in results) {
  66. if ([anAccount.email isEqualToString:_emailfld.text] || [anAccount.password isEqualToString:_passwordfld.text]){
  67. // NSLog(@"Your username exists");
  68. NSLog(@"Your pin is correct");
  69. [self performSegueWithIdentifier:@"showhome" sender:sender];
  70.  
  71. }
  72.  
  73. else if (![anAccount.email isEqualToString:_emailfld.text] || [anAccount.password isEqualToString:_passwordfld.text]){
  74.  
  75. [self dismissViewControllerAnimated:YES completion:nil];
  76.  
  77. NSLog(@"Your username is bad");
  78. }
  79.  
  80. else{
  81. [self dismissViewControllerAnimated:YES completion:nil];
  82. NSLog(@"Username dosent exitst");
  83. }
  84.  
  85. }
  86.  
  87.  
  88. }
  89.  
  90. @property (strong,nonatomic) Account *currentUser;
  91.  
  92. - (IBAction)processLogin:(id)sender {
  93.  
  94.  
  95.  
  96. NSManagedObjectContext *context = [self managedObjectContext];
  97.  
  98. // CORE DATA
  99. NSFetchRequest *request = [[NSFetchRequest alloc] init];
  100. NSEntityDescription *entity = [NSEntityDescription entityForName:@"Account" inManagedObjectContext:context];
  101.  
  102. // set entity for request
  103. [request setEntity:entity];
  104.  
  105. // filter results using a predicate
  106. NSPredicate *pred =[NSPredicate predicateWithFormat:(@"email = %@"), _emailfld.text];
  107. NSPredicate *pred2 =[NSPredicate predicateWithFormat:(@"password = %@"), _passwordfld.text];
  108.  
  109. // set predicate for the request
  110. [request setPredicate:pred];
  111. [request setPredicate:pred2];
  112.  
  113. NSError *error = nil;
  114.  
  115. // store DB usernames in results array
  116. NSArray *results = [context executeFetchRequest:request error:&error];
  117.  
  118. NSLog(@"The returned results are %@",results);
  119.  
  120. // check text field against results stored in DB
  121. for (Account *anAccount in results) {
  122. if ([anAccount.email isEqualToString:_emailfld.text] || [anAccount.password isEqualToString:_passwordfld.text]){
  123. // NSLog(@"Your username exists");
  124. NSLog(@"Your pin is correct");
  125. AppDelegate *app=(AppDelegate *)[UIApplication sharedApplication].delegate;
  126. app.currentUser=anAccount;
  127. [self performSegueWithIdentifier:@"showhome" sender:sender];
  128.  
  129. }
  130.  
  131. else if (![anAccount.email isEqualToString:_emailfld.text] || [anAccount.password isEqualToString:_passwordfld.text]){
  132.  
  133. [self dismissViewControllerAnimated:YES completion:nil];
  134.  
  135. NSLog(@"Your username is bad");
  136. }
  137.  
  138. else{
  139. [self dismissViewControllerAnimated:YES completion:nil];
  140. NSLog(@"Username dosent exitst");
  141. }
  142.  
  143. }
  144.  
  145. }
  146.  
  147. *AppDelegate *app=(AppDelegate *)[UIApplication sharedApplication].delegate;
  148. self.sometextfield.text=app.currentUser.email;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement