diff options
author | Vitaly Takmazov | 2016-08-28 21:03:22 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-08-28 21:03:22 +0300 |
commit | 188d8e4ea870d1a6c8edd5a9b323742804badeba (patch) | |
tree | 071067f7189a6474d49abb952b1b04b820985b7a /Juick/ViewControllers/LoginViewController.m | |
parent | a74588083c4950e9237dff7a84ccdd129b72c950 (diff) |
project cleanup
Diffstat (limited to 'Juick/ViewControllers/LoginViewController.m')
-rw-r--r-- | Juick/ViewControllers/LoginViewController.m | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/Juick/ViewControllers/LoginViewController.m b/Juick/ViewControllers/LoginViewController.m new file mode 100644 index 0000000..eedc6d3 --- /dev/null +++ b/Juick/ViewControllers/LoginViewController.m @@ -0,0 +1,92 @@ +// +// LoginViewController.m +// Juick +// +// Created by Vitaly on 30.01.14. +// Copyright (c) 2014 com.juick. All rights reserved. +// + +#import "LoginViewController.h" +#import "User.h" +#import "ColorScheme.h" + +@implementation LoginViewController + +- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self){ + [self initializeForm]; + } + return self; +} + +- (id)initWithCoder:(NSCoder *)aDecoder { + self = [super initWithCoder:aDecoder]; + if (self){ + [self initializeForm]; + } + return self; +} + +- (void)initializeForm { + self.title = @"Sign in"; + [self.view setBackgroundColor:[ColorScheme mainBackground]]; + + self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel + target:self action:@selector(cancelSignIn)]; + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave + target:self action:@selector(doneSignIn)]; + XLFormDescriptor *form = [XLFormDescriptor formDescriptorWithTitle:@"Sign in"]; + form.rowNavigationOptions = XLFormRowNavigationOptionEnabled; + XLFormSectionDescriptor *section = [XLFormSectionDescriptor formSection]; + [form addFormSection:section]; + XLFormRowDescriptor * usernameRow = [XLFormRowDescriptor + formRowDescriptorWithTag:@"com.juick.username" + rowType:XLFormRowDescriptorTypeText title:@"Username"]; + usernameRow.value = [[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"]; + [section addFormRow:usernameRow]; + XLFormRowDescriptor * passwordRow = [XLFormRowDescriptor + formRowDescriptorWithTag:@"com.juick.password" + rowType:XLFormRowDescriptorTypePassword title:@"Password"]; + passwordRow.value = [[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.password"]; + [section addFormRow:passwordRow]; + + self.form = form; +} + + +- (void) cancelSignIn { + CATransition* transition = [CATransition animation]; + transition.duration = 0.3; + transition.type = kCATransitionFade; + transition.subtype = kCATransitionFromTop; + + [self.navigationController.view.layer addAnimation:transition forKey:kCATransition]; + [self.navigationController popViewControllerAnimated:NO]; +} + +- (void) doneSignIn { + [User checkIsValid:^(BOOL success) { + if (success) { + CATransition* transition = [CATransition animation]; + transition.duration = 0.3; + transition.type = kCATransitionFade; + transition.subtype = kCATransitionFromTop; + + [self.navigationController.view.layer addAnimation:transition forKey:kCATransition]; + [self.navigationController popToRootViewControllerAnimated:NO]; + } else { + [User throwUnableToLogin]; + } + }]; + +} + +-(void) formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)formRow oldValue:(id)oldValue newValue:(id)newValue { + [super formRowDescriptorValueHasChanged:formRow oldValue:oldValue newValue:newValue]; + if ([newValue isKindOfClass:[NSString class]]) { + [[PDKeychainBindings sharedKeychainBindings] setObject:newValue forKey:formRow.tag]; + } +} + +@end |