2010-10-31 23:02:13 -04:00
|
|
|
//
|
|
|
|
// LoginViewController.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Samuel Clay on 10/31/10.
|
|
|
|
// Copyright 2010 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "LoginViewController.h"
|
2015-06-06 16:12:32 -05:00
|
|
|
#import "../Other Sources/OnePasswordExtension/OnePasswordExtension.h"
|
2013-10-01 11:18:49 +05:00
|
|
|
//#import <QuartzCore/QuartzCore.h>
|
2010-10-31 23:02:13 -04:00
|
|
|
|
|
|
|
@implementation LoginViewController
|
|
|
|
|
|
|
|
@synthesize appDelegate;
|
2011-10-03 23:20:17 -07:00
|
|
|
@synthesize usernameInput;
|
|
|
|
@synthesize passwordInput;
|
|
|
|
@synthesize emailInput;
|
2012-06-13 12:19:35 -07:00
|
|
|
@synthesize signUpUsernameInput;
|
|
|
|
@synthesize signUpPasswordInput;
|
|
|
|
@synthesize selectSignUpButton;
|
|
|
|
@synthesize selectLoginButton;
|
|
|
|
@synthesize signUpView;
|
|
|
|
@synthesize logInView;
|
2012-06-13 12:25:53 -07:00
|
|
|
|
2010-11-10 21:54:40 -05:00
|
|
|
@synthesize jsonString;
|
2011-08-13 23:00:51 -07:00
|
|
|
@synthesize errorLabel;
|
2011-10-03 23:20:17 -07:00
|
|
|
@synthesize loginControl;
|
|
|
|
@synthesize usernameLabel;
|
|
|
|
@synthesize usernameOrEmailLabel;
|
|
|
|
@synthesize passwordLabel;
|
|
|
|
@synthesize emailLabel;
|
|
|
|
@synthesize passwordOptionalLabel;
|
2015-06-06 16:12:32 -05:00
|
|
|
@synthesize onePasswordButton;
|
2010-10-31 23:02:13 -04:00
|
|
|
|
2012-06-15 09:42:09 -07:00
|
|
|
|
2010-11-11 20:05:53 -05:00
|
|
|
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
|
|
|
|
|
|
|
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
|
2012-07-30 12:56:44 -07:00
|
|
|
|
2010-11-11 20:05:53 -05:00
|
|
|
}
|
|
|
|
return self;
|
2012-06-13 12:19:35 -07:00
|
|
|
|
|
|
|
}
|
2010-11-11 20:05:53 -05:00
|
|
|
|
2012-08-02 18:00:48 -07:00
|
|
|
- (void)viewDidLoad {
|
2012-06-13 12:19:35 -07:00
|
|
|
self.usernameInput.borderStyle = UITextBorderStyleRoundedRect;
|
|
|
|
self.passwordInput.borderStyle = UITextBorderStyleRoundedRect;
|
|
|
|
self.emailInput.borderStyle = UITextBorderStyleRoundedRect;
|
|
|
|
self.signUpPasswordInput.borderStyle = UITextBorderStyleRoundedRect;
|
|
|
|
self.signUpUsernameInput.borderStyle = UITextBorderStyleRoundedRect;
|
2015-06-06 16:12:32 -05:00
|
|
|
|
2017-11-28 23:13:05 -08:00
|
|
|
if (@available(iOS 11.0, *)) {
|
|
|
|
self.usernameInput.textContentType = UITextContentTypeUsername;
|
|
|
|
self.passwordInput.textContentType = UITextContentTypePassword;
|
|
|
|
self.emailInput.textContentType = UITextContentTypeEmailAddress;
|
|
|
|
} else {
|
|
|
|
// Fallback on earlier versions
|
|
|
|
}
|
|
|
|
|
2013-10-11 17:46:09 -07:00
|
|
|
[self.loginControl
|
|
|
|
setTitleTextAttributes:@{NSFontAttributeName:
|
|
|
|
[UIFont fontWithName:@"Helvetica-Bold" size:11.0f]}
|
|
|
|
forState:UIControlStateNormal];
|
2012-06-13 12:19:35 -07:00
|
|
|
|
2015-06-06 16:12:32 -05:00
|
|
|
//[self.onePasswordButton setHidden:![[OnePasswordExtension sharedExtension] isAppExtensionAvailable]];
|
2013-10-11 17:46:09 -07:00
|
|
|
|
2012-06-13 14:11:36 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2015-11-04 16:11:39 -08:00
|
|
|
[self updateControls];
|
|
|
|
[self rearrangeViews];
|
2012-06-13 12:19:35 -07:00
|
|
|
}
|
2015-11-04 16:11:39 -08:00
|
|
|
|
2010-10-31 23:02:13 -04:00
|
|
|
[super viewDidLoad];
|
|
|
|
}
|
|
|
|
|
2015-11-04 16:11:39 -08:00
|
|
|
- (CGFloat)xForWidth:(CGFloat)width {
|
|
|
|
return (self.view.bounds.size.width / 2) - (width / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rearrangeViews {
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
CGSize viewSize = self.view.bounds.size;
|
|
|
|
CGFloat viewWidth = viewSize.width;
|
|
|
|
CGFloat yOffset = 0;
|
|
|
|
CGFloat xOffset = isOnSignUpScreen ? -viewWidth : 0;
|
|
|
|
|
|
|
|
if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) {
|
|
|
|
yOffset = viewSize.height / 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.buttonsView.frame = CGRectMake([self xForWidth:518], 15 + yOffset, 518, 66);
|
|
|
|
self.logInView.frame = CGRectMake([self xForWidth:500] + xOffset, 75 + yOffset, 500, 300);
|
|
|
|
self.signUpView.frame = CGRectMake([self xForWidth:500] + viewWidth + xOffset, 75 + yOffset, 500, 300);
|
|
|
|
self.errorLabel.frame = CGRectMake([self xForWidth:self.errorLabel.frame.size.width], 75 + yOffset, self.errorLabel.frame.size.width, self.errorLabel.frame.size.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-13 12:19:35 -07:00
|
|
|
- (void)viewDidUnload {
|
|
|
|
[self setSignUpView:nil];
|
|
|
|
[self setLogInView:nil];
|
|
|
|
[self setSignUpUsernameInput:nil];
|
|
|
|
[self setSignUpPasswordInput:nil];
|
|
|
|
[self setSelectSignUpButton:nil];
|
|
|
|
[self setSelectLoginButton:nil];
|
|
|
|
[super viewDidUnload];
|
|
|
|
}
|
|
|
|
|
2011-08-13 23:00:51 -07:00
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
2016-03-27 21:48:30 -07:00
|
|
|
[self showError:nil];
|
2011-08-13 23:00:51 -07:00
|
|
|
[super viewWillAppear:animated];
|
2012-08-02 18:00:48 -07:00
|
|
|
[usernameInput becomeFirstResponder];
|
2011-08-13 23:00:51 -07:00
|
|
|
}
|
|
|
|
|
2012-06-07 11:42:29 -07:00
|
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
|
|
|
// Return YES for supported orientations
|
2012-08-02 18:00:48 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
2012-06-07 11:42:29 -07:00
|
|
|
}
|
|
|
|
|
2011-08-13 23:00:51 -07:00
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
2012-06-13 17:22:17 -07:00
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
2011-08-13 23:00:51 -07:00
|
|
|
[super viewDidAppear:animated];
|
|
|
|
}
|
|
|
|
|
2011-10-03 23:20:17 -07:00
|
|
|
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
|
|
// Releases the view if it doesn't have a superview.
|
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
|
|
|
|
// Release any cached data, images, etc that aren't in use.
|
|
|
|
}
|
|
|
|
|
2012-06-13 12:19:35 -07:00
|
|
|
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
|
2015-11-04 16:11:39 -08:00
|
|
|
[self rearrangeViews];
|
2012-06-13 12:19:35 -07:00
|
|
|
}
|
|
|
|
|
2016-03-27 21:48:30 -07:00
|
|
|
- (void)showError:(NSString *)error {
|
|
|
|
BOOL hasError = error.length > 0;
|
|
|
|
|
|
|
|
if (hasError) {
|
|
|
|
self.errorLabel.text = error;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.errorLabel.hidden = !hasError;
|
|
|
|
self.forgotPasswordButton.hidden = !hasError;
|
|
|
|
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
self.loginOptionalLabel.hidden = hasError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-06 16:12:32 -05:00
|
|
|
- (IBAction)findLoginFrom1Password:(id)sender {
|
|
|
|
[[OnePasswordExtension sharedExtension] findLoginForURLString:@"https://www.newsblur.com" forViewController:self sender:sender completion:^(NSDictionary *loginDictionary, NSError *error) {
|
|
|
|
if (loginDictionary.count == 0) {
|
|
|
|
if (error.code != AppExtensionErrorCodeCancelledByUser) {
|
|
|
|
NSLog(@"Error invoking 1Password App Extension for find login: %@", error);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.usernameInput.text = loginDictionary[AppExtensionUsernameKey];
|
|
|
|
[passwordInput becomeFirstResponder];
|
|
|
|
self.passwordInput.text = loginDictionary[AppExtensionPasswordKey];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2011-10-03 23:20:17 -07:00
|
|
|
#pragma mark -
|
2012-10-02 11:17:47 -07:00
|
|
|
#pragma mark Login
|
2011-10-03 23:20:17 -07:00
|
|
|
|
2010-10-31 23:02:13 -04:00
|
|
|
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
|
2012-06-13 14:11:36 -07:00
|
|
|
[textField resignFirstResponder];
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
if(textField == usernameInput) {
|
|
|
|
[passwordInput becomeFirstResponder];
|
|
|
|
} else if (textField == passwordInput) {
|
|
|
|
[self checkPassword];
|
|
|
|
} else if (textField == signUpUsernameInput){
|
|
|
|
[signUpPasswordInput becomeFirstResponder];
|
|
|
|
} else if (textField == signUpPasswordInput) {
|
|
|
|
[emailInput becomeFirstResponder];
|
|
|
|
} else if (textField == emailInput) {
|
|
|
|
[self registerAccount];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(textField == usernameInput) {
|
|
|
|
[passwordInput becomeFirstResponder];
|
|
|
|
} else if (textField == passwordInput && [self.loginControl selectedSegmentIndex] == 0) {
|
|
|
|
[self checkPassword];
|
|
|
|
} else if (textField == passwordInput && [self.loginControl selectedSegmentIndex] == 1) {
|
|
|
|
[emailInput becomeFirstResponder];
|
|
|
|
} else if (textField == emailInput) {
|
|
|
|
[self registerAccount];
|
|
|
|
}
|
|
|
|
|
2010-10-31 23:02:13 -04:00
|
|
|
}
|
2012-06-13 14:11:36 -07:00
|
|
|
return YES;
|
2010-10-31 23:02:13 -04:00
|
|
|
}
|
|
|
|
|
2010-11-10 21:54:40 -05:00
|
|
|
- (void)checkPassword {
|
2016-03-27 21:48:30 -07:00
|
|
|
[self showError:nil];
|
2012-06-13 17:22:17 -07:00
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
|
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
|
|
HUD.labelText = @"Authenticating";
|
|
|
|
|
2013-06-20 19:25:57 -07:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"%@/api/login",
|
2016-01-21 22:11:37 -08:00
|
|
|
self.appDelegate.url];
|
2010-11-11 23:48:27 -05:00
|
|
|
[[NSHTTPCookieStorage sharedHTTPCookieStorage]
|
|
|
|
setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
|
2010-11-15 19:40:17 -05:00
|
|
|
|
2017-03-09 20:29:30 -08:00
|
|
|
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
|
|
|
[params setObject:[usernameInput text] forKey:@"username"];
|
|
|
|
[params setObject:[passwordInput text] forKey:@"password"];
|
|
|
|
[params setObject:@"login" forKey:@"submit"];
|
|
|
|
[params setObject:@"1" forKey:@"api"];
|
|
|
|
|
2017-04-03 12:49:01 -07:00
|
|
|
[appDelegate.networkManager POST:urlString parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
2017-03-09 20:29:30 -08:00
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
|
|
|
|
|
int code = [[responseObject valueForKey:@"code"] intValue];
|
|
|
|
if (code == -1) {
|
|
|
|
NSDictionary *errors = [responseObject valueForKey:@"errors"];
|
|
|
|
if ([errors valueForKey:@"username"]) {
|
|
|
|
[self showError:[[errors valueForKey:@"username"] firstObject]];
|
|
|
|
} else if ([errors valueForKey:@"__all__"]) {
|
|
|
|
[self showError:[[errors valueForKey:@"__all__"] firstObject]];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
[self.passwordInput setText:@""];
|
|
|
|
[self.signUpPasswordInput setText:@""];
|
|
|
|
[appDelegate reloadFeedsView:YES];
|
|
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
}
|
|
|
|
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
|
|
|
[self requestFailed:error];
|
|
|
|
}];
|
2010-11-10 21:54:40 -05:00
|
|
|
}
|
|
|
|
|
2011-10-03 23:20:17 -07:00
|
|
|
|
|
|
|
- (void)registerAccount {
|
2012-06-13 17:22:17 -07:00
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
|
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
|
|
HUD.labelText = @"Registering...";
|
2016-03-27 21:48:30 -07:00
|
|
|
[self showError:nil];
|
2013-06-18 21:23:20 -04:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"%@/api/signup",
|
2016-01-21 22:11:37 -08:00
|
|
|
self.appDelegate.url];
|
2011-10-03 23:20:17 -07:00
|
|
|
[[NSHTTPCookieStorage sharedHTTPCookieStorage]
|
|
|
|
setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
|
2017-03-09 20:29:30 -08:00
|
|
|
|
|
|
|
NSMutableDictionary *params = [NSMutableDictionary dictionary];
|
2012-06-13 14:11:36 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2017-03-09 20:29:30 -08:00
|
|
|
[params setObject:[signUpUsernameInput text] forKey:@"username"];
|
|
|
|
[params setObject:[signUpPasswordInput text] forKey:@"password"];
|
2012-06-13 14:11:36 -07:00
|
|
|
} else {
|
2017-03-09 20:29:30 -08:00
|
|
|
[params setObject:[usernameInput text] forKey:@"username"];
|
|
|
|
[params setObject:[passwordInput text] forKey:@"password"];
|
2012-06-13 14:11:36 -07:00
|
|
|
}
|
2017-03-09 20:29:30 -08:00
|
|
|
[params setObject:[emailInput text] forKey:@"email"];
|
|
|
|
[params setObject:@"login" forKey:@"submit"];
|
|
|
|
[params setObject:@"1" forKey:@"api"];
|
2012-06-13 14:11:36 -07:00
|
|
|
|
2017-04-03 12:49:01 -07:00
|
|
|
[appDelegate.networkManager POST:urlString parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
2017-03-09 20:29:30 -08:00
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
|
|
|
|
|
int code = [[responseObject valueForKey:@"code"] intValue];
|
|
|
|
if (code == -1) {
|
|
|
|
NSDictionary *errors = [responseObject valueForKey:@"errors"];
|
|
|
|
if ([errors valueForKey:@"email"]) {
|
|
|
|
[self showError:[[errors valueForKey:@"email"] objectAtIndex:0]];
|
|
|
|
} else if ([errors valueForKey:@"username"]) {
|
|
|
|
[self showError:[[errors valueForKey:@"username"] objectAtIndex:0]];
|
|
|
|
} else if ([errors valueForKey:@"__all__"]) {
|
|
|
|
[self showError:[[errors valueForKey:@"__all__"] objectAtIndex:0]];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
[self.passwordInput setText:@""];
|
|
|
|
[self.signUpPasswordInput setText:@""];
|
|
|
|
// [appDelegate showFirstTimeUser];
|
|
|
|
[appDelegate reloadFeedsView:YES];
|
|
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
2011-10-03 23:20:17 -07:00
|
|
|
}
|
2017-03-09 20:29:30 -08:00
|
|
|
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
|
|
|
[self requestFailed:error];
|
|
|
|
}];
|
|
|
|
|
2011-10-03 23:20:17 -07:00
|
|
|
}
|
|
|
|
|
2017-03-09 20:29:30 -08:00
|
|
|
- (void)requestFailed:(NSError *)error {
|
2011-07-24 20:34:54 -07:00
|
|
|
NSLog(@"Error: %@", error);
|
2013-03-06 14:29:40 -08:00
|
|
|
[appDelegate informError:error];
|
2014-10-01 16:11:44 -07:00
|
|
|
|
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
2010-11-10 21:54:40 -05:00
|
|
|
}
|
|
|
|
|
2016-03-27 21:48:30 -07:00
|
|
|
- (IBAction)forgotPassword:(id)sender {
|
2018-04-06 09:35:14 -04:00
|
|
|
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/folder_rss/forgot_password", appDelegate.url]];
|
2017-09-27 12:19:58 -07:00
|
|
|
SFSafariViewController *safariViewController = [[SFSafariViewController alloc] initWithURL:url];
|
2016-03-27 21:48:30 -07:00
|
|
|
[self presentViewController:safariViewController animated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
2012-06-12 18:01:14 -07:00
|
|
|
#pragma mark -
|
2012-06-13 14:11:36 -07:00
|
|
|
#pragma mark iPad: Sign Up/Login Toggle
|
2010-10-31 23:02:13 -04:00
|
|
|
|
2015-11-04 16:11:39 -08:00
|
|
|
- (void)updateControls {
|
|
|
|
self.selectSignUpButton.selected = isOnSignUpScreen;
|
|
|
|
self.selectLoginButton.selected = !isOnSignUpScreen;
|
2016-03-27 21:48:30 -07:00
|
|
|
|
|
|
|
[self showError:nil];
|
2015-11-04 16:11:39 -08:00
|
|
|
|
|
|
|
self.signUpUsernameInput.enabled = isOnSignUpScreen;
|
|
|
|
self.signUpPasswordInput.enabled = isOnSignUpScreen;
|
|
|
|
self.emailInput.enabled = isOnSignUpScreen;
|
|
|
|
self.usernameInput.enabled = !isOnSignUpScreen;
|
|
|
|
self.passwordInput.enabled = !isOnSignUpScreen;
|
|
|
|
}
|
|
|
|
|
2012-06-13 12:19:35 -07:00
|
|
|
- (IBAction)selectSignUp {
|
2012-06-15 09:42:09 -07:00
|
|
|
isOnSignUpScreen = YES;
|
2015-11-04 16:11:39 -08:00
|
|
|
|
|
|
|
[self updateControls];
|
|
|
|
|
|
|
|
[UIView animateWithDuration:0.35 animations:^{
|
|
|
|
[self rearrangeViews];
|
|
|
|
}];
|
2012-06-13 14:11:36 -07:00
|
|
|
|
2012-08-14 17:20:45 -07:00
|
|
|
[self.signUpUsernameInput becomeFirstResponder];
|
|
|
|
|
2012-06-13 12:19:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)selectLogin {
|
2012-06-15 09:42:09 -07:00
|
|
|
isOnSignUpScreen = NO;
|
2015-11-04 16:11:39 -08:00
|
|
|
|
|
|
|
[self updateControls];
|
|
|
|
|
|
|
|
[UIView animateWithDuration:0.35 animations:^{
|
|
|
|
[self rearrangeViews];
|
|
|
|
}];
|
2012-08-14 17:20:45 -07:00
|
|
|
|
|
|
|
[self.usernameInput becomeFirstResponder];
|
2012-06-13 12:19:35 -07:00
|
|
|
}
|
|
|
|
|
2012-06-13 17:22:17 -07:00
|
|
|
- (IBAction)tapLoginButton {
|
|
|
|
[self.view endEditing:YES];
|
|
|
|
[self checkPassword];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)tapSignUpButton {
|
|
|
|
[self.view endEditing:YES];
|
|
|
|
[self registerAccount];
|
|
|
|
}
|
|
|
|
|
2012-06-13 14:11:36 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark iPhone: Sign Up/Login Toggle
|
|
|
|
|
|
|
|
- (IBAction)selectLoginSignup {
|
|
|
|
[self animateLoop];
|
|
|
|
}
|
|
|
|
|
2011-10-03 23:20:17 -07:00
|
|
|
- (void)animateLoop {
|
2014-09-24 11:49:14 -07:00
|
|
|
CGFloat width = CGRectGetWidth(self.view.frame);
|
|
|
|
CGFloat margin = 20;
|
2011-10-03 23:20:17 -07:00
|
|
|
if ([self.loginControl selectedSegmentIndex] == 0) {
|
|
|
|
[UIView animateWithDuration:0.5 animations:^{
|
|
|
|
// Login
|
2014-09-24 11:49:14 -07:00
|
|
|
usernameInput.frame = CGRectMake(20, 67, width-margin*2, 31);
|
2011-10-03 23:20:17 -07:00
|
|
|
usernameOrEmailLabel.alpha = 1.0;
|
2013-10-02 14:29:19 -07:00
|
|
|
usernameLabel.alpha = 0.0;
|
2011-10-03 23:20:17 -07:00
|
|
|
|
2014-09-24 11:49:14 -07:00
|
|
|
passwordInput.frame = CGRectMake(20, 129, width-margin*2, 31);
|
2012-06-13 14:11:36 -07:00
|
|
|
passwordLabel.frame = CGRectMake(21, 106, 212, 22);
|
2014-09-24 11:49:14 -07:00
|
|
|
passwordOptionalLabel.frame = CGRectMake(width-margin-101, 112, 101, 16);
|
2011-10-03 23:20:17 -07:00
|
|
|
|
|
|
|
emailInput.alpha = 0.0;
|
|
|
|
emailLabel.alpha = 0.0;
|
2015-06-06 16:12:32 -05:00
|
|
|
|
|
|
|
onePasswordButton.frame = CGRectMake(20+ passwordInput.frame.size.width - 31, 129, 31, 31);
|
|
|
|
onePasswordButton.alpha = 1.0;
|
2011-10-03 23:20:17 -07:00
|
|
|
}];
|
|
|
|
|
|
|
|
passwordInput.returnKeyType = UIReturnKeyGo;
|
|
|
|
usernameInput.keyboardType = UIKeyboardTypeEmailAddress;
|
|
|
|
[usernameInput resignFirstResponder];
|
|
|
|
[usernameInput becomeFirstResponder];
|
|
|
|
} else {
|
|
|
|
[UIView animateWithDuration:0.5 animations:^{
|
|
|
|
// Signup
|
2014-09-24 11:49:14 -07:00
|
|
|
usernameInput.frame = CGRectMake(20, 67, width/2-margin*2, 31);
|
2011-10-03 23:20:17 -07:00
|
|
|
usernameOrEmailLabel.alpha = 0.0;
|
2013-10-02 14:29:19 -07:00
|
|
|
usernameLabel.alpha = 1.0;
|
2011-10-03 23:20:17 -07:00
|
|
|
|
2014-09-24 11:49:14 -07:00
|
|
|
passwordInput.frame = CGRectMake(width/2+margin, 67, width/2-margin*2, 31);
|
|
|
|
passwordLabel.frame = CGRectMake(width/2+margin, 44, 212, 22);
|
|
|
|
passwordOptionalLabel.frame = CGRectMake(width-margin-101, 50, 101, 16);
|
2011-10-03 23:20:17 -07:00
|
|
|
|
|
|
|
emailInput.alpha = 1.0;
|
|
|
|
emailLabel.alpha = 1.0;
|
2015-06-06 16:12:32 -05:00
|
|
|
|
|
|
|
onePasswordButton.frame = CGRectMake(width/2+margin + passwordInput.frame.size.width - 31, 67, 31, 31);
|
|
|
|
onePasswordButton.alpha = 0.0; // Don't want to deal with registration yet.
|
2012-06-13 14:11:36 -07:00
|
|
|
}];
|
2011-10-03 23:20:17 -07:00
|
|
|
passwordInput.returnKeyType = UIReturnKeyNext;
|
|
|
|
usernameInput.keyboardType = UIKeyboardTypeAlphabet;
|
|
|
|
[usernameInput resignFirstResponder];
|
|
|
|
[usernameInput becomeFirstResponder];
|
|
|
|
}
|
2016-03-27 21:48:30 -07:00
|
|
|
|
|
|
|
self.forgotPasswordButton.hidden = YES;
|
2011-10-03 23:20:17 -07:00
|
|
|
}
|
2010-10-31 23:02:13 -04:00
|
|
|
|
|
|
|
@end
|