Guest User

Untitled

a guest
Jun 24th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. - (void)authenticateWithUser:(NSString *)_user andPassword:(NSString *)_password {
  2. if (_user == nil || _password == nil) {
  3. [[NSNotificationCenter defaultCenter] postNotificationName:TUserHasNotBeenAuthenticatedNotification
  4. object:nil
  5. userInfo:nil];
  6. } else {
  7. NSURLConnection * connection;
  8. NSURL * url;
  9. NSString * stringUrl;
  10. NSMutableURLRequest * request;
  11. NSString * credentials;
  12. credentials = [NSString stringWithFormat:@"tiiptop:test", _user, _password];
  13. stringUrl = [NSString stringWithFormat:@"%@users/validate", [ObjectiveResourceConfig getSite]];
  14. url = [[NSURL alloc] initWithString:stringUrl];
  15. request = [[NSMutableURLRequest alloc] initWithURL:url];
  16. NSData * data = [NSData dataWithBase64EncodedString:credentials];
  17. [request addValue:[NSString stringWithFormat:@"Basic %s", [data bytes]]
  18. forHTTPHeaderField:@"Authorization"];
  19.  
  20. NSLog(@"%@", [request allHTTPHeaderFields]);
  21. connection = [[NSURLConnection alloc] initWithRequest:request
  22. delegate:self
  23. startImmediately:YES];
  24.  
  25. [[NSUserDefaults standardUserDefaults] setValue:_user forKey:@"user"];
  26. [[NSUserDefaults standardUserDefaults] setValue:_password forKey:@"password"];
  27. [connection autorelease];
  28. [request release];
  29. [url release];
  30. }
  31. }
Add Comment
Please, Sign In to add comment