Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  SignInViewController.m
  3. //  mtracker
  4. //
  5. //  Created by Temitope Faro on 7/21/11.
  6. //  Copyright 2011 Sleek Computers. All rights reserved.
  7.  
  8. #import "SignInViewController.h"
  9. #import "SFHttpRequestDispatcher.h"
  10. #import "NSURLConnection-block.h"
  11. #import "User.h"
  12. #import "JSONKit.h"
  13. #import "Util.h"
  14. #import "settings.h"
  15.  
  16. @implementation SignInViewController
  17.  
  18. @synthesize mobileNumber;
  19. @synthesize password;
  20.  
  21. - (IBAction) signInUser:(id) sender{
  22.     [self hideKeyboard:nil];
  23.    
  24.     SFHttpRequestDispatcher *dispatcher = [Util dispatcherForIsActivatedWithMobileNumber:mobileNumber.text
  25.                                                                                 password:password.text];
  26.     [NSURLConnection asyncRequest:[dispatcher doGetOrPost]
  27.                           success:^(NSData *data, NSURLResponse *response) {  
  28.                               NSDictionary *jsonDictionary = [data objectFromJSONData];
  29.                               NSNumber *success = (NSNumber *) [jsonDictionary objectForKey:@"activated"] ;
  30.                               NSLog(@"activated: %d", [success boolValue]);
  31.                               if([success boolValue] == true){
  32.                                   UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sign In Alert"
  33.                                                                                       message:@"Sign In Successful"
  34.                                                                                      delegate:nil cancelButtonTitle:@"Dismiss"
  35.                                                                             otherButtonTitles:nil];
  36.                                   [alertView show];
  37.                                  
  38.                                   //not sure of the below line
  39.                                   [self dismissModalViewControllerAnimated:YES];
  40.                                   [alertView release];
  41.                               }else {
  42.                                   UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sign In Alert"
  43.                                                                                       message:@"Sign in Unsuccessful"
  44.                                                                                      delegate:nil cancelButtonTitle:@"Dismiss"
  45.                                                                             otherButtonTitles:nil];
  46.                                   [alertView show];
  47.                                   [alertView release];
  48.                               }
  49.                              
  50.                           }
  51.                           failure:^(NSData *data, NSError *error){  
  52.                               NSLog(@"XXError! %@",[error localizedDescription]);  
  53.                               UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error - Signing in"
  54.                                                                                   message:[error localizedDescription]
  55.                                                                                  delegate:nil cancelButtonTitle:@"Dismiss"
  56.                                                                         otherButtonTitles:nil];
  57.                               [alertView show];
  58.                               [alertView release];
  59.                           }
  60.      ];  
  61. }
  62.  
  63. - (IBAction) showRegisterView:(id) sender{
  64.     [self hideKeyboard:nil];
  65.     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle: @"Register Alert"
  66.                                                         message:@"You Clicked on Register"
  67.                                                        delegate:nil cancelButtonTitle:@"Dismiss"
  68.                                               otherButtonTitles:nil];
  69.     [alertView show];
  70.     [alertView release];
  71. }
  72.  
  73.  
  74. - (IBAction) hideKeyboard: (id) sender{
  75.     [mobileNumber resignFirstResponder];
  76.     [password resignFirstResponder];
  77. }
  78.  
  79. // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
  80. /*
  81.  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  82.  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  83.  if (self) {
  84.  // Custom initialization.
  85.  }
  86.  return self;
  87.  }
  88.  */
  89.  
  90. /*
  91.  // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  92.  - (void)viewDidLoad {
  93.  [super viewDidLoad];
  94.  }
  95.  */
  96.  
  97. /*
  98.  // Override to allow orientations other than the default portrait orientation.
  99.  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  100.  // Return YES for supported orientations.
  101.  return (interfaceOrientation == UIInterfaceOrientationPortrait);
  102.  }
  103.  */
  104.  
  105. - (void)didReceiveMemoryWarning {
  106.     // Releases the view if it doesn't have a superview.
  107.     [super didReceiveMemoryWarning];
  108.    
  109.     // Release any cached data, images, etc. that aren't in use.
  110. }
  111.  
  112. - (void)viewDidUnload {
  113.     [super viewDidUnload];
  114.     // Release any retained subviews of the main view.
  115.     // e.g. self.myOutlet = nil;
  116. }
  117.  
  118.  
  119. - (void)dealloc {
  120.     [mobileNumber release];
  121.     [password release];
  122.    
  123.     [super dealloc];
  124. }
  125.  
  126.  
  127. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement