Advertisement
Guest User

Untitled

a guest
Oct 4th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  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. [alertView release];
  38.  
  39. //not sure of the below line
  40. [self dismissModalViewControllerAnimated:YES];
  41.  
  42. }else {
  43. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sign In Alert"
  44. message:@"Sign in Unsuccessful"
  45. delegate:nil cancelButtonTitle:@"Dismiss"
  46. otherButtonTitles:nil];
  47. [alertView show];
  48. [alertView release];
  49. }
  50.  
  51. }
  52. failure:^(NSData *data, NSError *error){
  53. NSLog(@"XXError! %@",[error localizedDescription]);
  54. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error - Signing in"
  55. message:[error localizedDescription]
  56. delegate:nil cancelButtonTitle:@"Dismiss"
  57. otherButtonTitles:nil];
  58. [alertView show];
  59. [alertView release];
  60. }
  61. ];
  62. }
  63.  
  64. - (IBAction) showRegisterView:(id) sender{
  65. [self hideKeyboard:nil];
  66. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle: @"Register Alert"
  67. message:@"You Clicked on Register"
  68. delegate:nil cancelButtonTitle:@"Dismiss"
  69. otherButtonTitles:nil];
  70. [alertView show];
  71. [alertView release];
  72. }
  73.  
  74.  
  75. - (IBAction) hideKeyboard: (id) sender{
  76. [mobileNumber resignFirstResponder];
  77. [password resignFirstResponder];
  78. }
  79.  
  80. // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
  81. /*
  82. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  83. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  84. if (self) {
  85. // Custom initialization.
  86. }
  87. return self;
  88. }
  89. */
  90.  
  91. /*
  92. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  93. - (void)viewDidLoad {
  94. [super viewDidLoad];
  95. }
  96. */
  97.  
  98. /*
  99. // Override to allow orientations other than the default portrait orientation.
  100. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  101. // Return YES for supported orientations.
  102. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  103. }
  104. */
  105.  
  106. - (void)didReceiveMemoryWarning {
  107. // Releases the view if it doesn't have a superview.
  108. [super didReceiveMemoryWarning];
  109.  
  110. // Release any cached data, images, etc. that aren't in use.
  111. }
  112.  
  113. - (void)viewDidUnload {
  114. [super viewDidUnload];
  115. // Release any retained subviews of the main view.
  116. // e.g. self.myOutlet = nil;
  117. }
  118.  
  119.  
  120. - (void)dealloc {
  121. [mobileNumber release];
  122. [password release];
  123.  
  124. [super dealloc];
  125. }
  126.  
  127.  
  128. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement