summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Juick/APIClient.m14
-rw-r--r--Juick/Model/User.m3
2 files changed, 10 insertions, 7 deletions
diff --git a/Juick/APIClient.m b/Juick/APIClient.m
index b812057..ae2ebad 100644
--- a/Juick/APIClient.m
+++ b/Juick/APIClient.m
@@ -31,10 +31,6 @@
self.manager = [[AFHTTPSessionManager alloc] initWithBaseURL:[NSURL URLWithString:baseURLString]];
self.manager.requestSerializer = [AFJSONRequestSerializer new];
[self.manager.requestSerializer setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
- NSString *username = [SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.username"];
- if (username) {
- [self.manager.requestSerializer setAuthorizationHeaderFieldWithUsername:username password:[SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.password"]];
- }
self.backgroundQueue = [NSOperationQueue new];
self.dateFormatter = [[NSDateFormatter alloc] init];
self.dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
@@ -43,6 +39,16 @@
return self;
}
+-(AFHTTPSessionManager *) manager {
+ NSString *username = [SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.username"];
+ if (username) {
+ [_manager.requestSerializer
+ setAuthorizationHeaderFieldWithUsername:username
+ password:[SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.password"]];
+ }
+ return _manager;
+}
+
-(void) pullNextFromPath:(NSString *)path params:(NSDictionary *) params callback:(void(^)(NSArray *, NSError *))callback {
AFHTTPSessionManager *manager = [APIClient sharedClient].manager;
[self.backgroundQueue addOperationWithBlock:^{
diff --git a/Juick/Model/User.m b/Juick/Model/User.m
index 848fc2a..7f97e34 100644
--- a/Juick/Model/User.m
+++ b/Juick/Model/User.m
@@ -40,9 +40,6 @@
+(void) checkIsValid:(void (^)(BOOL))callback {
AFHTTPSessionManager *manager = [APIClient sharedClient].manager;
- NSString *username = [SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.username"];
- NSString *password = [SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.password"];
- [manager.requestSerializer setAuthorizationHeaderFieldWithUsername:username password:password];
[manager POST:@"post" parameters:nil progress:nil success:nil failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSInteger statusCode = ((NSHTTPURLResponse *)task.response).statusCode;
if (statusCode == 400) {