summaryrefslogtreecommitdiff
path: root/Juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-01-19 23:38:50 +0300
committerGravatar Vitaly Takmazov2017-01-19 23:38:50 +0300
commit917fd3b930b8c25551b751608b9bd0dd104b56e5 (patch)
treef6e5d623c402d83b2868cb07b963c0bc5af5150f /Juick
parent87c992e9db9464215d12a3987fe384d65e96bc50 (diff)
Handle changed password
Diffstat (limited to 'Juick')
-rw-r--r--Juick/AppDelegate.h2
-rw-r--r--Juick/AppDelegate.m36
-rw-r--r--Juick/Model/Message.m6
-rw-r--r--Juick/ViewControllers/RevealPanelViewController.m14
4 files changed, 23 insertions, 35 deletions
diff --git a/Juick/AppDelegate.h b/Juick/AppDelegate.h
index c0a7650..04a8bb2 100644
--- a/Juick/AppDelegate.h
+++ b/Juick/AppDelegate.h
@@ -16,4 +16,6 @@
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UIViewController *viewController;
+- (void) pushLoginForm;
+
@end
diff --git a/Juick/AppDelegate.m b/Juick/AppDelegate.m
index 51304dc..8240892 100644
--- a/Juick/AppDelegate.m
+++ b/Juick/AppDelegate.m
@@ -17,6 +17,8 @@
@implementation AppDelegate
+SWRevealViewController *reveal;
+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UINavigationBar appearance] setTintColor:[ColorScheme linkColor]];
@@ -29,7 +31,7 @@
UINavigationController *main = [[UINavigationController alloc] initWithRootViewController:messages];
UINavigationController *rearNav = [[UINavigationController alloc] initWithRootViewController:rear];
- SWRevealViewController *reveal = [[SWRevealViewController alloc] initWithRearViewController:rearNav frontViewController:main];
+ reveal = [[SWRevealViewController alloc] initWithRearViewController:rearNav frontViewController:main];
self.viewController = reveal;
[messages.navigationController.navigationBar addGestureRecognizer:reveal.panGestureRecognizer];
UIBarButtonItem *revealButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"reveal-icon.png"]
@@ -58,31 +60,13 @@
return YES;
}
-- (void)applicationWillResignActive:(UIApplication *)application
-{
- // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
- // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
-}
-
-- (void)applicationDidEnterBackground:(UIApplication *)application
-{
- // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
- // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
-}
-
-- (void)applicationWillEnterForeground:(UIApplication *)application
-{
- // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
-}
-
-- (void)applicationDidBecomeActive:(UIApplication *)application
-{
- // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
-}
-
-- (void)applicationWillTerminate:(UIApplication *)application
-{
- // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
+- (void) pushLoginForm {
+ if ([reveal isBeingPresented]) {
+ [reveal revealToggle:self];
+ }
+ UIViewController *loginView = [[LoginViewController alloc] init];
+ UINavigationController *messages = (UINavigationController *)reveal.frontViewController;
+ [messages pushViewController:loginView animated:YES];
}
@end
diff --git a/Juick/Model/Message.m b/Juick/Model/Message.m
index a4bcd2c..a7934ac 100644
--- a/Juick/Model/Message.m
+++ b/Juick/Model/Message.m
@@ -8,6 +8,7 @@
#import "Message.h"
#import "PDKeychainBindings.h"
+#import "AppDelegate.h"
@implementation Message
@@ -34,6 +35,11 @@
callback(messages);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"REST Error: %@", error);
+ NSInteger statusCode = ((NSHTTPURLResponse *)task.response).statusCode;
+ if (statusCode == 401) {
+ AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
+ [appDelegate pushLoginForm];
+ }
}];
}
diff --git a/Juick/ViewControllers/RevealPanelViewController.m b/Juick/ViewControllers/RevealPanelViewController.m
index d890f97..b74d556 100644
--- a/Juick/ViewControllers/RevealPanelViewController.m
+++ b/Juick/ViewControllers/RevealPanelViewController.m
@@ -16,6 +16,7 @@
#import "NavCell.h"
#import "Message.h"
#import "User.h"
+#import "AppDelegate.h"
static NSString *CellIdentifier = @"NavCell";
@@ -79,7 +80,8 @@ static NSString *CellIdentifier = @"NavCell";
-(void) signInOut {
[self refreshInfo];
- [self pushLoginForm];
+ AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
+ [appDelegate pushLoginForm];
}
-(void) viewWillLayoutSubviews {
@@ -137,13 +139,6 @@ static NSString *CellIdentifier = @"NavCell";
return cell;
}
-- (void) pushLoginForm {
- [self.revealViewController revealToggle:self];
- UIViewController *loginView = [[LoginViewController alloc] init];
- UINavigationController *messages = (UINavigationController *)self.revealViewController.frontViewController;
- [messages pushViewController:loginView animated:YES];
-}
-
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = indexPath.row;
NSString *targetPath;
@@ -151,7 +146,8 @@ static NSString *CellIdentifier = @"NavCell";
NSString *targetTitle;
if (row == 0) {
if ([[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"] == nil) {
- [self pushLoginForm];
+ AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
+ [appDelegate pushLoginForm];
return;
} else {
targetTitle = @"My feed";