Mikhail Kuznetsov avatar Mikhail Kuznetsov committed c29a561

login alerts; second view;

Comments (0)

Files changed (3)

MyShows/Classes/MyShowsApi.m

                                        ]
                   ];
     NSLog(@"Requesting url is %@", url);
-    SEL requestSelector = NSSelectorFromString([[NSString alloc] initWithFormat:@"request%@Finished", [resource uppercaseString]]);
+    SEL requestSelector = NSSelectorFromString([[NSString alloc] initWithFormat:@"request%@Finished:", [resource capitalizedString]]);
     
     ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
     
     [request setDelegate:self];
+    //NSLog(@"Checking for custom finish selector %@", requestSelector);
     if ([self respondsToSelector:requestSelector]) {
+        NSLog(@"Setting custom finish selector");
         [request setDidFinishSelector:requestSelector];
     }
     [request startSynchronous];
 - (void) requestFinished:(ASIHTTPRequest *)request {
     NSLog(@"Request finished with %d status code", [request responseStatusCode]);
     
+    /*NSHTTPCookie *cookie;
+    NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
+    for (cookie in [cookieJar cookies]) {
+        NSLog(@"%@", cookie);
+    }*/
+    
     if ([request responseStatusCode] == 200) {
+        NSLog(@"Storing response...");
         responseString = [request responseString]; 
     }
     else {
+        NSLog(@"Request failed...");
         [[request delegate] requestFailed:request];
     }
 }
 
 - (void) requestFailed:(ASIHTTPRequest *)request {
-    NSLog(@"Request failed");
+    NSLog(@"Request failed with %d status code", [request responseStatusCode]);
 }
 
 - (void) requestLoginFinished:(ASIHTTPRequest *)request {
     [self requestFinished:request];
     
-    NSDictionary *data = [[NSDictionary alloc] initWithObjectsAndKeys:
-                          @"status", @"ok",
-                          nil];
-        
-    if ([[self responder] respondsToSelector:@selector(didRequestSucceed:)]) {
-        [[self responder] didRequestSucceed:data];
+    if ([request responseStatusCode] == 200 ||
+        [request responseStatusCode] == 403 ||
+        [request responseStatusCode] == 404) 
+    {
+        NSDictionary *data = [[NSDictionary alloc] initWithObjectsAndKeys:
+                              [[NSNumber alloc] initWithInt:[request responseStatusCode]], @"status",
+                              nil];
+        NSLog(@"Checking for selector");    
+        if ([[self responder] respondsToSelector:@selector(didRequestSucceed:)]) {
+            NSLog(@"Responding to selector didRequestSucceed");
+            [[self responder] didRequestSucceed:data];
+        }
     }
 }
 @end

MyShows/ViewController.m

 - (IBAction)signInButtonPressed:(id)sender {
     NSLog(@"Signing in...");
     
-    if (login.text != nil && password.text != nil){
+    if ([login.text length] != 0 && [password.text length] != 0){
         NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:
                                 login.text, @"login",
                                 [NSString Md5Hash:password.text], @"password", 
         
         [api sendRequest:@"login" queryParams:params];
     }
+    else {
+        UIAlertView *alert = [[UIAlertView alloc]
+                              initWithTitle:@"Please, enter your username and password"
+														message:nil
+													   delegate:nil
+                                              cancelButtonTitle:@"OK"
+											  otherButtonTitles:nil];
+        [alert show];
+    }
 }
 
 - (IBAction)signUpButtonPressed:(id)sender {
-    
+    NSLog(@"Signing up...");
 }
 
 - (void) didRequestSucceed:(NSDictionary *) data {
+    NSLog(@"Returned to view after successful request with data %@", data);
+    int status = [(NSNumber *)[data objectForKey:@"status"] intValue];
     
+    if (status == 200 ) {
+        [self performSegueWithIdentifier:@"login_to_main_controller" sender:nil];
+    }
+    else {
+        UIAlertView *alert = [[UIAlertView alloc]
+                              initWithTitle:@""
+                              message:nil
+                              delegate:nil
+                              cancelButtonTitle:@"OK"
+                              otherButtonTitles:nil];
+        if (status == 404) {
+            [alert setTitle:@"User not found"];
+        }
+        else if (status == 403) {
+            [alert setTitle:@"Wrong credentials"];
+        }
+        [alert show];
+    }
 }
 
 - (void) didRequestFailed:(NSDictionary *) data {

MyShows/en.lproj/MainStoryboard.storyboard

 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="1.0" toolsVersion="1938" systemVersion="11C74" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="2">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="1.0" toolsVersion="1938" systemVersion="11C74" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="2DL-wh-LZG">
     <dependencies>
         <development defaultVersion="4200" identifier="xcode"/>
         <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="933"/>
                                 <state key="highlighted">
                                     <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                 </state>
+                                <connections>
+                                    <action selector="signUpButtonPressed:" destination="2" eventType="touchUpInside" id="qDT-WN-Oh9"/>
+                                </connections>
                             </button>
                             <imageView userInteractionEnabled="NO" contentMode="scaleToFill" image="logo-tv.gif" id="OWp-eM-ugt">
                                 <rect key="frame" x="131" y="31" width="58" height="52"/>
                         </subviews>
                         <color key="backgroundColor" red="0.65621905150000004" green="0.76122931500000002" blue="0.90816326530000002" alpha="1" colorSpace="calibratedRGB"/>
                     </view>
+                    <navigationItem key="navigationItem" id="qjh-0j-ylF"/>
                     <connections>
                         <outlet property="login" destination="WLh-O4-Mna" id="5gU-AE-Cj6"/>
                         <outlet property="password" destination="W93-vI-wFX" id="tKw-gf-ATE"/>
+                        <segue destination="1qP-2z-udP" kind="push" identifier="login_to_main_controller" id="nZg-ts-aJj"/>
+                    </connections>
+                </viewController>
+            </objects>
+            <point key="canvasLocation" x="346" y="-87"/>
+        </scene>
+        <scene sceneID="ysL-OL-Sg2">
+            <objects>
+                <placeholder placeholderIdentifier="IBFirstResponder" id="LlN-H3-iK2" userLabel="First Responder" sceneMemberID="firstResponder"/>
+                <navigationController navigationBarHidden="YES" id="2DL-wh-LZG" sceneMemberID="viewController">
+                    <toolbarItems/>
+                    <navigationBar key="navigationBar" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="XRL-1W-U69">
+                        <rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
+                        <autoresizingMask key="autoresizingMask"/>
+                    </navigationBar>
+                    <nil name="viewControllers"/>
+                    <connections>
+                        <segue destination="2" kind="relationship" relationship="rootViewController" id="Nnh-Lo-Co2"/>
                     </connections>
+                </navigationController>
+            </objects>
+            <point key="canvasLocation" x="-564" y="-15"/>
+        </scene>
+        <scene sceneID="w6c-v9-Zaj">
+            <objects>
+                <placeholder placeholderIdentifier="IBFirstResponder" id="v4Z-BQ-88c" userLabel="First Responder" sceneMemberID="firstResponder"/>
+                <viewController id="sLz-U7-UeI" sceneMemberID="viewController">
+                    <view key="view" contentMode="scaleToFill" id="7yq-tZ-eHD">
+                        <rect key="frame" x="0.0" y="20" width="320" height="411"/>
+                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+                        <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
+                    </view>
+                    <tabBarItem key="tabBarItem" title="Item 2" id="N3t-aH-i6e"/>
+                </viewController>
+            </objects>
+            <point key="canvasLocation" x="337" y="1243"/>
+        </scene>
+        <scene sceneID="gMO-U8-RlT">
+            <objects>
+                <placeholder placeholderIdentifier="IBFirstResponder" id="LeL-sQ-QuP" userLabel="First Responder" sceneMemberID="firstResponder"/>
+                <viewController id="ltE-k4-kem" sceneMemberID="viewController">
+                    <view key="view" contentMode="scaleToFill" id="HSo-AE-bxV">
+                        <rect key="frame" x="0.0" y="20" width="320" height="411"/>
+                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+                        <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
+                    </view>
+                    <tabBarItem key="tabBarItem" title="Item 1" id="fBt-qw-aVm"/>
                 </viewController>
             </objects>
+            <point key="canvasLocation" x="337" y="679"/>
+        </scene>
+        <scene sceneID="HOY-Hz-hTg">
+            <objects>
+                <placeholder placeholderIdentifier="IBFirstResponder" id="40S-0K-hz3" userLabel="First Responder" sceneMemberID="firstResponder"/>
+                <tabBarController definesPresentationContext="YES" id="1qP-2z-udP" sceneMemberID="viewController">
+                    <navigationItem key="navigationItem" id="QPx-gk-xP8"/>
+                    <simulatedTabBarMetrics key="simulatedBottomBarMetrics"/>
+                    <tabBar key="tabBar" contentMode="scaleToFill" id="IYG-8o-e2o">
+                        <rect key="frame" x="129" y="330" width="163" height="49"/>
+                        <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
+                        <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
+                    </tabBar>
+                    <connections>
+                        <segue destination="ltE-k4-kem" kind="relationship" relationship="viewControllers" id="tRj-Zw-dhk"/>
+                        <segue destination="sLz-U7-UeI" kind="relationship" relationship="viewControllers" id="P1c-em-wsC"/>
+                    </connections>
+                </tabBarController>
+            </objects>
+            <point key="canvasLocation" x="-199" y="963"/>
         </scene>
     </scenes>
     <resources>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.