forked from soffes/cheddar-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CDISignUpViewController.m
129 lines (102 loc) · 4.54 KB
/
CDISignUpViewController.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// CDISignUpViewController.m
// Cheddar for iOS
//
// Created by Sam Soffes on 4/23/12.
// Copyright (c) 2012 Nothing Magical. All rights reserved.
//
#import "CDISignUpViewController.h"
#import "UIColor+CheddariOSAdditions.h"
#import "UIFont+CheddariOSAdditions.h"
#import "CDISignInViewController.h"
@interface CDISignUpViewController ()
@property (nonatomic, strong, readonly) UITextField *emailTextField;
@end
@implementation CDISignUpViewController
@synthesize emailTextField = _emailTextField;
- (UITextField *)emailTextField {
if (!_emailTextField) {
_emailTextField = [[UITextField alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [[self class] textFieldWith], 30.0f)];
_emailTextField.keyboardType = UIKeyboardTypeEmailAddress;
_emailTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
_emailTextField.autocorrectionType = UITextAutocorrectionTypeNo;
_emailTextField.textColor = [UIColor cheddarBlueColor];
_emailTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
_emailTextField.delegate = self;
_emailTextField.returnKeyType = UIReturnKeyNext;
_emailTextField.placeholder = @"Your email address";
_emailTextField.font = [UIFont cheddarFontOfSize:18.0f];
}
return _emailTextField;
}
#pragma mark - UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Cheddar";
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Sign Up" style:UIBarButtonItemStyleBordered target:nil action:nil];
// self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Sign Up" style:UIBarButtonItemStyleBordered target:self action:@selector(signUp:)];
UIButton *footer = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 34.0f)];
[footer setTitle:@"Already have an account? Sign In →" forState:UIControlStateNormal];
[footer setTitleColor:[UIColor cheddarBlueColor] forState:UIControlStateNormal];
[footer setTitleColor:[UIColor cheddarTextColor] forState:UIControlStateHighlighted];
[footer addTarget:self action:@selector(signIn:) forControlEvents:UIControlEventTouchUpInside];
footer.titleLabel.font = [UIFont cheddarFontOfSize:16.0f];
self.tableView.tableFooterView = footer;
}
#pragma mark - Actions
- (void)signIn:(id)sender {
[self.navigationController pushViewController:[[CDISignInViewController alloc] init] animated:YES];
}
- (void)signUp:(id)sender {
SSHUDView *hud = [[SSHUDView alloc] initWithTitle:@"Signing up..." loading:YES];
[hud show];
[[CDKHTTPClient sharedClient] signUpWithUsername:self.usernameTextField.text email:self.emailTextField.text password:self.passwordTextField.text success:^(AFJSONRequestOperation *operation, id responseObject) {
dispatch_async(dispatch_get_main_queue(), ^{
[hud completeAndDismissWithTitle:@"Signed Up!"];
[self.navigationController dismissModalViewControllerAnimated:YES];
});
} failure:^(AFJSONRequestOperation *operation, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[hud failAndDismissWithTitle:@"Failed"];
});
}];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *const cellIdentifier = @"cellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.textColor = [UIColor cheddarTextColor];
cell.textLabel.font = [UIFont cheddarFontOfSize:18.0f];
}
if (indexPath.row == 0) {
cell.textLabel.text = @"Username";
cell.accessoryView = self.usernameTextField;
self.usernameTextField.placeholder = @"Choose a username";
} else if (indexPath.row == 1) {
cell.textLabel.text = @"Email";
cell.accessoryView = self.emailTextField;
} else if (indexPath.row == 2) {
cell.textLabel.text = @"Password";
cell.accessoryView = self.passwordTextField;
self.passwordTextField.placeholder = @"Choose a password";
}
return cell;
}
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == self.usernameTextField) {
[self.emailTextField becomeFirstResponder];
} else if (textField == self.emailTextField) {
[self.passwordTextField becomeFirstResponder];
} else if (textField == self.passwordTextField) {
[self signUp:textField];
}
return NO;
}
@end