forked from organicmaps/organicmaps
[ios] Added async login & error alert.
This commit is contained in:
parent
41480a567a
commit
bb4f881d10
2 changed files with 68 additions and 8 deletions
|
@ -1,5 +1,7 @@
|
|||
#import "Common.h"
|
||||
#import "MWMAuthorizationCommon.h"
|
||||
#import "MWMAuthorizationOSMLoginViewController.h"
|
||||
#import "MWMCircularProgress.h"
|
||||
#import "UIColor+MapsMeColor.h"
|
||||
#import "UITextField+RuntimeAttributes.h"
|
||||
|
||||
|
@ -20,9 +22,12 @@ typedef NS_OPTIONS(NSUInteger, MWMFieldCorrect)
|
|||
@property (weak, nonatomic) IBOutlet UITextField * passwordTextField;
|
||||
@property (weak, nonatomic) IBOutlet UIButton * loginButton;
|
||||
@property (weak, nonatomic) IBOutlet UIButton * forgotButton;
|
||||
@property (weak, nonatomic) IBOutlet UIView * spinnerView;
|
||||
|
||||
@property (nonatomic) MWMFieldCorrect isCorrect;
|
||||
|
||||
@property (nonatomic) MWMCircularProgress * spinner;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MWMAuthorizationOSMLoginViewController
|
||||
|
@ -33,6 +38,7 @@ typedef NS_OPTIONS(NSUInteger, MWMFieldCorrect)
|
|||
self.title = L(@"osm_login");
|
||||
self.isCorrect = MWMFieldCorrectNO;
|
||||
[self checkConnection];
|
||||
[self stopSpinner];
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotate
|
||||
|
@ -100,15 +106,62 @@ typedef NS_OPTIONS(NSUInteger, MWMFieldCorrect)
|
|||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
|
||||
- (void)showInvalidCredentialsAlert
|
||||
{
|
||||
NSString * title = L(@"invalid_username_or_password");
|
||||
NSString * ok = L(@"ok");
|
||||
if (isIOSVersionLessThan(8))
|
||||
{
|
||||
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:title
|
||||
message:nil
|
||||
delegate:nil
|
||||
cancelButtonTitle:ok
|
||||
otherButtonTitles:nil];
|
||||
[alertView show];
|
||||
return;
|
||||
}
|
||||
UIAlertController * alertController =
|
||||
[UIAlertController alertControllerWithTitle:title
|
||||
message:nil
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
UIAlertAction * okAction =
|
||||
[UIAlertAction actionWithTitle:ok style:UIAlertActionStyleCancel handler:nil];
|
||||
[alertController addAction:okAction];
|
||||
[self presentViewController:alertController animated:YES completion:nil];
|
||||
}
|
||||
|
||||
- (void)startSpinner
|
||||
{
|
||||
self.spinnerView.hidden = NO;
|
||||
self.spinner = [[MWMCircularProgress alloc] initWithParentView:self.spinnerView];
|
||||
[self.spinner startSpinner];
|
||||
self.loginTextField.enabled = NO;
|
||||
self.passwordTextField.enabled = NO;
|
||||
self.forgotButton.enabled = NO;
|
||||
[self.loginButton setTitle:@"" forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
- (void)stopSpinner
|
||||
{
|
||||
self.spinnerView.hidden = YES;
|
||||
[self.spinnerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
|
||||
[self.spinner stopSpinner];
|
||||
self.spinner = nil;
|
||||
self.loginTextField.enabled = YES;
|
||||
self.passwordTextField.enabled = YES;
|
||||
self.forgotButton.enabled = YES;
|
||||
[self.loginButton setTitle:L(@"login") forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
#pragma mark - Actions
|
||||
|
||||
- (IBAction)login
|
||||
{
|
||||
if (!self.loginButton.enabled)
|
||||
if (!self.loginButton.enabled || self.spinner)
|
||||
return;
|
||||
if (Platform::IsConnected())
|
||||
{
|
||||
// TODO: Add async loader spinner
|
||||
[self startSpinner];
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^
|
||||
{
|
||||
string const username = self.loginTextField.text.UTF8String;
|
||||
|
@ -116,14 +169,11 @@ typedef NS_OPTIONS(NSUInteger, MWMFieldCorrect)
|
|||
BOOL const credentialsOK = osm::ServerApi06(username, password).CheckUserAndPassword();
|
||||
dispatch_async(dispatch_get_main_queue(), ^
|
||||
{
|
||||
[self stopSpinner];
|
||||
if (credentialsOK)
|
||||
{
|
||||
[self storeCredentials];
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Add alert "wrong username or password"
|
||||
}
|
||||
[self showInvalidCredentialsAlert];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1420,7 +1420,6 @@
|
|||
<userDefinedRuntimeAttribute type="string" keyPath="textColorName" value="whiteColor"/>
|
||||
<userDefinedRuntimeAttribute type="string" keyPath="backgroundColorName" value="buttonEnabledBlueText"/>
|
||||
<userDefinedRuntimeAttribute type="string" keyPath="backgroundHighlightedColorName" value="clearColor"/>
|
||||
<userDefinedRuntimeAttribute type="string" keyPath="localizedText" value="login"/>
|
||||
</userDefinedRuntimeAttributes>
|
||||
<connections>
|
||||
<action selector="login" destination="4R7-Vk-fQr" eventType="touchUpInside" id="IIp-Wz-gj1"/>
|
||||
|
@ -1443,9 +1442,18 @@
|
|||
<segue destination="oZQ-Rp-tGs" kind="custom" customClass="MWMSegue" id="aZN-Th-ilh"/>
|
||||
</connections>
|
||||
</button>
|
||||
<view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="jMt-5d-INe">
|
||||
<rect key="frame" x="290" y="160" width="20" height="20"/>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="20" id="9HJ-T7-PfS"/>
|
||||
<constraint firstAttribute="width" constant="20" id="cgc-jq-2QK"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstItem="jMt-5d-INe" firstAttribute="centerX" secondItem="QoF-Wv-nc2" secondAttribute="centerX" id="2Kv-5N-0Cj"/>
|
||||
<constraint firstItem="2p5-BG-sgS" firstAttribute="top" secondItem="diV-OZ-JSc" secondAttribute="bottom" constant="20" id="4Ka-53-cIL"/>
|
||||
<constraint firstItem="2p5-BG-sgS" firstAttribute="leading" secondItem="S9T-iq-RN6" secondAttribute="leading" id="Ch6-8Q-5GT"/>
|
||||
<constraint firstAttribute="trailing" secondItem="dOX-WF-oyI" secondAttribute="trailing" constant="16" id="Gc8-5a-YG2"/>
|
||||
|
@ -1454,6 +1462,7 @@
|
|||
<constraint firstItem="dOX-WF-oyI" firstAttribute="leading" secondItem="S9T-iq-RN6" secondAttribute="leading" constant="16" id="RhA-2F-rfW"/>
|
||||
<constraint firstAttribute="trailing" secondItem="QoF-Wv-nc2" secondAttribute="trailing" constant="16" id="agP-PG-A0J"/>
|
||||
<constraint firstItem="QoF-Wv-nc2" firstAttribute="leading" secondItem="S9T-iq-RN6" secondAttribute="leading" constant="16" id="s3b-o3-XfX"/>
|
||||
<constraint firstItem="jMt-5d-INe" firstAttribute="centerY" secondItem="QoF-Wv-nc2" secondAttribute="centerY" id="t4E-xp-u3E"/>
|
||||
<constraint firstAttribute="trailing" secondItem="2p5-BG-sgS" secondAttribute="trailing" id="wDK-U5-BEZ"/>
|
||||
</constraints>
|
||||
<userDefinedRuntimeAttributes>
|
||||
|
@ -1472,6 +1481,7 @@
|
|||
<outlet property="loginButton" destination="QoF-Wv-nc2" id="KfJ-7W-yr1"/>
|
||||
<outlet property="loginTextField" destination="NyD-Tz-Vq4" id="hUR-bj-DSY"/>
|
||||
<outlet property="passwordTextField" destination="e51-Qs-t6a" id="h5w-aQ-WYh"/>
|
||||
<outlet property="spinnerView" destination="jMt-5d-INe" id="pnF-tq-p2h"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="cdo-Ng-y40" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
|
|
Loading…
Add table
Reference in a new issue