diff options
author | Vitaly Takmazov | 2019-03-21 13:55:21 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2019-03-21 14:09:26 +0300 |
commit | 7d16bf22b2ae69a7a6512587b28414a59aa95995 (patch) | |
tree | f73a738757acdbec36f123c4162127d6b1eb4330 /Juick | |
parent | 2ddd7f7964d09236b43485c795970038dd1c309f (diff) |
Move isAuthenticated to APIClient
Diffstat (limited to 'Juick')
-rw-r--r-- | Juick/APIClient.m | 4 | ||||
-rw-r--r-- | Juick/Model/User.h | 2 | ||||
-rw-r--r-- | Juick/Model/User.m | 5 | ||||
-rw-r--r-- | Juick/ViewControllers/DiscoverViewController.m | 4 |
4 files changed, 6 insertions, 9 deletions
diff --git a/Juick/APIClient.m b/Juick/APIClient.m index f637710..44e7537 100644 --- a/Juick/APIClient.m +++ b/Juick/APIClient.m @@ -200,6 +200,10 @@ } ]; } +-(BOOL) isAuthenticated { + NSString *password = [SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.password"]; + return password != nil; +} - (void)fetchImageWithURL:(NSURL *)url callback:(void (^)(NSData *))callback { NSURLSessionDataTask *dataTask = [self.urlSession dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { diff --git a/Juick/Model/User.h b/Juick/Model/User.h index 6265687..4a4988a 100644 --- a/Juick/Model/User.h +++ b/Juick/Model/User.h @@ -15,8 +15,6 @@ + (User *) fromJSON:(NSDictionary *)jsonData; -+ (BOOL) isAuthenticated; - + (void) throwUnableToLogin:(UIViewController *)view error:(NSError *)error; @end diff --git a/Juick/Model/User.m b/Juick/Model/User.m index 344eb7b..5c5e553 100644 --- a/Juick/Model/User.m +++ b/Juick/Model/User.m @@ -19,11 +19,6 @@ return user; } -+(BOOL) isAuthenticated { - NSString *password = [SAMKeychain passwordForService:[[NSBundle mainBundle] bundleIdentifier] account:@"com.juick.password"]; - return password != nil; -} - +(void) throwUnableToLogin:(UIViewController *)view error:(NSError *)error { UIAlertController *alert = [UIAlertController new]; [alert setTitle:@"Something went wrong"]; diff --git a/Juick/ViewControllers/DiscoverViewController.m b/Juick/ViewControllers/DiscoverViewController.m index ea720be..94e1d16 100644 --- a/Juick/ViewControllers/DiscoverViewController.m +++ b/Juick/ViewControllers/DiscoverViewController.m @@ -23,7 +23,7 @@ -(void) viewDidLoad { self.messagesDelegate = self; - if ([User isAuthenticated]) { + if ([[APIClient sharedClient] isAuthenticated]) { [[APIClient sharedClient] authenticate:^(User *user, NSError *error) { if (user) { if ([self.path length] == 0) { @@ -99,7 +99,7 @@ } } - (IBAction)filterAction:(id)sender { - if (![User isAuthenticated]) { + if (![[APIClient sharedClient] isAuthenticated]) { [self.navigationController performSegueWithIdentifier:@"loginSegue" sender:self.navigationController]; return; } |