-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlphabeticalVC.m
107 lines (90 loc) · 3.02 KB
/
AlphabeticalVC.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// AlphabeticalVC.m
// Calculator
//
// Created by Corey Allen Pett on 11/25/15.
// Copyright © 2015 Corey Allen Pett. All rights reserved.
//
#import "AlphabeticalVC.h"
#import "Settings.h"
#import <AudioToolbox/AudioToolbox.h>
@interface AlphabeticalVC () <UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *inputTextfield;
@property (weak, nonatomic) IBOutlet UILabel *instructionLabel;
@property (strong, nonatomic) Settings *settings;
@end
static int createPasswordCount = 0;
@implementation AlphabeticalVC
-(Settings *)settings
{
if(!_settings) _settings = [[Settings alloc] init];
return _settings;
}
- (void)viewDidLoad {
[super viewDidLoad];
if(self.changeLock){
[self.settings resetUserPassword];
}
[self.settings retrievePassword];
if(self.settings.isPasswordCreated){
self.instructionLabel.text = @"Enter Passcode";
}
else{
self.instructionLabel.text = @"Create Passcode";
createPasswordCount = 0;
}
self.inputTextfield.delegate = self;
[self.inputTextfield becomeFirstResponder];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
if(self.settings.isPasswordCreated && [self.settings unlockVault:self.inputTextfield.text]){
if(self.changeLock){
[self dismissViewControllerAnimated:YES completion:nil];
}
else{
[self performSegueWithIdentifier:@"UnlockAlphabeticalVault" sender:self];
}
}
else if(!self.settings.isPasswordCreated){
[self.settings createUserPassword:self.inputTextfield.text];
if (createPasswordCount == 0){
self.instructionLabel.text = @"Confirm Passcord";
self.inputTextfield.text = @"";
createPasswordCount++;
}
else if (createPasswordCount == 1 && self.settings.isPasswordCreated){
createPasswordCount++;
NSLog(@"Segue! password created");
if(self.changeLock){
[self dismissViewControllerAnimated:YES completion:nil];
}
else {
[self performSegueWithIdentifier:@"UnlockAlphabeticalVault" sender:self];
}
}
else {
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
NSLog(@"Incorrect");
self.instructionLabel.text = @"Create Passcode";
createPasswordCount = 0;
self.inputTextfield.text = @"";
self.settings.isPasswordCreated = NO;
self.settings.userPassword = nil;
}
}
return NO;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end