Skip to content
Browse files

app can add new users true the register view

  • Loading branch information...
1 parent 3609e04 commit 796678e3f2babe54d645297f01d2b6cec9b90df0 Ernesto Vargas committed Feb 16, 2012
View
BIN ...odeproj/project.xcworkspace/xcuserdata/ernesto.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
View
6 Messagee.xcodeproj/xcuserdata/ernesto.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
@@ -9,11 +9,11 @@
continueAfterRunningActions = "No"
isPathRelative = "1"
filePath = "Messagee/LoginViewController.m"
- timestampString = "351127561.474596"
+ timestampString = "351134500.831038"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "222"
- endingLineNumber = "222"
+ startingLineNumber = "221"
+ endingLineNumber = "221"
landmarkName = "@implementation LoginViewController"
landmarkType = "3">
</FileBreakpoint>
View
5 Messagee/LoginViewController.m
@@ -88,11 +88,12 @@ - (void)viewWillAppear:(BOOL)animated
- (void)textFieldDidBeginEditing:(UITextField *)textFieldView {
currentTextField = textFieldView;
- UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard:)];
- [self.view addGestureRecognizer:gestureRecognizer];
+ //UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard:)];
+ //[self.view addGestureRecognizer:gestureRecognizer];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textFieldView {
+ [textFieldView resignFirstResponder];
return YES;
}
View
1 Messagee/MessageViewController.m
@@ -100,7 +100,6 @@ - (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {
- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
_statuses = objects;
[_tableView reloadData];
-
}
- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error {
View
10 Messagee/RegisterViewController.h
@@ -12,7 +12,15 @@
#import "UGClient.h"
@interface RegisterViewController : UIViewController <RKRequestDelegate> {
-
+ UITextField *currentTextField;
+ BOOL keyboardIsShown;
}
+@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
+@property (weak, nonatomic) IBOutlet UITextField *usernameField;
+@property (weak, nonatomic) IBOutlet UITextField *nameField;
+@property (weak, nonatomic) IBOutlet UITextField *emailField;
+@property (weak, nonatomic) IBOutlet UITextField *passwordField;
+@property (weak, nonatomic) IBOutlet UITextField *password2Field;
+
@end
View
157 Messagee/RegisterViewController.m
@@ -9,6 +9,12 @@
#import "RegisterViewController.h"
@implementation RegisterViewController
+@synthesize scrollView;
+@synthesize usernameField;
+@synthesize nameField;
+@synthesize emailField;
+@synthesize passwordField;
+@synthesize password2Field;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
@@ -46,42 +52,52 @@ - (void)viewDidLoad
- (void)viewDidUnload
{
+ [self setUsernameField:nil];
+ [self setNameField:nil];
+ [self setEmailField:nil];
+ [self setPasswordField:nil];
+ [self setPassword2Field:nil];
+ [self setScrollView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (IBAction)registerButton:(id)sender {
- // TODO: Terminate register process
-
- //NSMutableDictionary *rpcData = [[NSMutableDictionary alloc] init ];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[RKClient sharedClient].baseURL = [[UGClient sharedInstance] usergridApiUrl];
- [[RKClient sharedClient] setValue:[NSString stringWithFormat:@"Bearer %@", [[UGClient sharedInstance] clientCredentials]] forHTTPHeaderField:@"Authorization"];
-
- // User Params
- [params setObject:@"test5" forKey:@"username"];
- [params setObject:@"Test" forKey:@"name"];
- [params setObject:@"a@c.com" forKey:@"email"];
- [params setObject:@"123456" forKey:@"password"];
-
- // Post message params
- //[rpcData setobject:@"test4" forKey:@"username"];
- //[rpcData setObject:@"Ernesto M" forKey:@"name"];
- //[rpcData setObject:@"a@b.com" forKey:@"email"];
-
- // Parsing rpcData to JSON!
- id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:RKMIMETypeJSON];
- NSError *error = nil;
- NSString *json = [parser stringFromObject:params error:&error];
+ // TODO: Validate all fields
+ if(![nameField.text isEqualToString:@""]) {
+ // There's text in the box.
+ }
- if (!error){
- [[[RKClient sharedClient] post:@"users"
- params:[RKRequestSerialization serializationWithData:[json dataUsingEncoding:NSUTF8StringEncoding] MIMEType:RKMIMETypeJSON]
- delegate:self] send];
- }
+ if((passwordField.text == passwordField.text)&&(![passwordField.text isEqualToString:@""])) {
+ // User Params
+ [params setObject:[usernameField text] forKey:@"username"];
+ [params setObject:[nameField text] forKey:@"name"];
+ [params setObject:[nameField text] forKey:@"email"];
+ [params setObject:[passwordField text] forKey:@"password"];
+ [params setObject:[password2Field text] forKey:@"password"];
+
+ // Parsing rpcData to JSON!
+ id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:RKMIMETypeJSON];
+ NSError *error = nil;
+ NSString *json = [parser stringFromObject:params error:&error];
+
+ if (!error){
+ [[[RKClient sharedClient] post:@"users"
+ params:[RKRequestSerialization serializationWithData:[json dataUsingEncoding:NSUTF8StringEncoding] MIMEType:RKMIMETypeJSON]
+ delegate:self] send];
+ }
+ } else {
+ UIAlertView* alert = [[UIAlertView alloc]
+ initWithTitle:[NSString stringWithFormat:@"Validation Error"]
+ message:[NSString stringWithFormat:@"Passwords don't match"]
+ delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
+ [alert show];
+ }
}
- (IBAction)cancelRegisterButton:(id)sender {
@@ -99,21 +115,17 @@ - (void)request:(RKRequest *)request didSendBodyData:(NSInteger)bytesWritten tot
- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response {
if ([response isSuccessful]) {
- NSLog(@"User created");
- [self dismissModalViewControllerAnimated:YES];
- /*
- if ([[response parsedBody:nil] objectForKey:@"access_token"]) {
- //self.clientCredentials = [[response parsedBody:nil] objectForKey:@"access_token"];
- } else if ([[response parsedBody:nil] objectForKey:@"error"]) {
- UIAlertView* alert = [[UIAlertView alloc]
- initWithTitle:nil
- message:[[response parsedBody:nil] objectForKey:@"error_description"]
- delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
- [alert show];
+ if ([response statusCode]==200) {
+ [self dismissModalViewControllerAnimated:YES];
}
- */
+ } else if ([response statusCode]==400) {
+ UIAlertView* alert = [[UIAlertView alloc]
+ initWithTitle:@"Error"
+ message:[NSString stringWithFormat:@"%@", [[response parsedBody:nil] objectForKey:@"error_description"]]
+ delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
+ [alert show];
} else if ([response isError]) {
- NSLog(@"response %@", response.bodyAsString);
+ NSLog(@"response %@", response.bodyAsString);
UIAlertView* alert = [[UIAlertView alloc]
initWithTitle:@"Error"
message:[NSString stringWithFormat:@"Status code: %d", response.statusCode]
@@ -131,4 +143,73 @@ - (void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error {
[alert show];
}
+
+
+
+// Keyboard stuff
+- (void)viewDidLoad
+{
+ scrollView.frame = CGRectMake(0, 0, 320, 460);
+ [scrollView setContentSize:CGSizeMake(320, 460)];
+
+ [super viewDidLoad];
+}
+
+- (void)viewWillAppear:(BOOL)animated
+{
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:self.view.window];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
+ [super viewWillAppear:animated];
+}
+
+
+- (void)textFieldDidBeginEditing:(UITextField *)textFieldView {
+ currentTextField = textFieldView;
+ //UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard:)];
+ //[self.view addGestureRecognizer:gestureRecognizer];
+}
+
+- (BOOL)textFieldShouldReturn:(UITextField *)textFieldView {
+ [textFieldView resignFirstResponder];
+ return YES;
+}
+
+- (void)textFieldDidEndEditing:(UITextField *)textFieldView {
+ currentTextField = nil;
+ [textFieldView resignFirstResponder];
+}
+
+- (void)hideKeyboard:(UITapGestureRecognizer *)sender {
+ //[self.view removeGestureRecognizer:sender];
+}
+
+- (void)keyboardDidShow:(NSNotification *) notification {
+ if (keyboardIsShown) return;
+ NSDictionary* info = [notification userInfo];
+
+ NSValue *aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
+ CGRect keyboardRect = [self.view convertRect:[aValue CGRectValue] fromView:nil];
+
+ CGRect viewFrame = [scrollView frame];
+ viewFrame.size.height -= keyboardRect.size.height;
+ //viewFrame.size.height -= 25;
+ scrollView.frame = viewFrame;
+
+ CGRect textFieldRect = [currentTextField frame];
+ [scrollView scrollRectToVisible:textFieldRect animated:YES];
+ keyboardIsShown = YES;
+}
+
+- (void)keyboardDidHide:(NSNotification *) notification {
+ NSDictionary* info = [notification userInfo];
+
+ NSValue* aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
+ CGRect keyboardRect = [self.view convertRect:[aValue CGRectValue] fromView:nil];
+
+ CGRect viewFrame = [scrollView frame];
+ viewFrame.size.height += keyboardRect.size.height;
+
+ scrollView.frame = viewFrame;
+ keyboardIsShown = NO;
+}
@end
View
83 Messagee/en.lproj/MainStoryboard.storyboard
@@ -260,7 +260,7 @@
<rect key="frame" x="40" y="163" width="251" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="Helvetica" family="Helvetica" pointSize="18"/>
- <textInputTraits key="textInputTraits" autocorrectionType="no" returnKeyType="next"/>
+ <textInputTraits key="textInputTraits" autocorrectionType="no" returnKeyType="done"/>
<connections>
<outlet property="delegate" destination="r1M-Kr-TUQ" id="oBS-GN-4Go"/>
</connections>
@@ -343,16 +343,29 @@
<rect key="frame" x="0.0" y="20" width="320" height="460"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
+ <imageView userInteractionEnabled="NO" contentMode="scaleToFill" image="Background@2x.png" id="X6w-Np-VcZ">
+ <rect key="frame" x="0.0" y="0.0" width="320" height="460"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ </imageView>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="ZIs-u4-Gig">
<rect key="frame" x="0.0" y="0.0" width="320" height="460"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
- <imageView userInteractionEnabled="NO" contentMode="scaleToFill" image="Background@2x.png" id="X6w-Np-VcZ">
- <rect key="frame" x="0.0" y="0.0" width="320" height="460"/>
- <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ <imageView userInteractionEnabled="NO" contentMode="scaleToFill" image="usernameField@2x.png" id="3OZ-lL-VEP">
+ <rect key="frame" x="18" y="80" width="285" height="57"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
+ <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Username" minimumFontSize="17" id="sQj-0Y-3sJ">
+ <rect key="frame" x="25" y="87" width="265" height="44"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+ <fontDescription key="fontDescription" name="Helvetica" family="Helvetica" pointSize="18"/>
+ <textInputTraits key="textInputTraits" returnKeyType="done"/>
+ <connections>
+ <outlet property="delegate" destination="rmy-jc-pz9" id="JBb-Sz-gJ4"/>
+ </connections>
+ </textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="kSD-bK-IM6">
- <rect key="frame" x="18" y="345" width="135" height="57"/>
+ <rect key="frame" x="18" y="391" width="135" height="57"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="Helvetica-Bold" family="Helvetica" pointSize="18"/>
<state key="normal" title="Cancel" backgroundImage="register@2x.png">
@@ -367,7 +380,7 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="VQL-iN-o4P">
- <rect key="frame" x="167" y="345" width="135" height="57"/>
+ <rect key="frame" x="167" y="391" width="135" height="57"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="Helvetica-Bold" family="Helvetica" pointSize="18"/>
<state key="normal" title="Register" backgroundImage="login@2x.png">
@@ -382,40 +395,70 @@
</connections>
</button>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" image="loginFields@2x.png" id="dL2-kb-rUQ">
- <rect key="frame" x="18" y="215" width="285" height="115"/>
+ <rect key="frame" x="18" y="268" width="285" height="115"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" image="usernameField@2x.png" id="XmG-NF-KPB">
- <rect key="frame" x="18" y="145" width="285" height="57"/>
+ <rect key="frame" x="18" y="142" width="285" height="57"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" image="logo@2x.png" id="WAk-gC-wZk">
- <rect key="frame" x="74" y="63" width="167" height="25"/>
+ <rect key="frame" x="74" y="35" width="167" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
- <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Username" minimumFontSize="17" id="Yk1-R8-dmU">
- <rect key="frame" x="30" y="153" width="265" height="44"/>
+ <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Name" minimumFontSize="17" id="Yk1-R8-dmU">
+ <rect key="frame" x="28" y="149" width="265" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="Helvetica" family="Helvetica" pointSize="18"/>
- <textInputTraits key="textInputTraits"/>
+ <textInputTraits key="textInputTraits" returnKeyType="done"/>
+ <connections>
+ <outlet property="delegate" destination="rmy-jc-pz9" id="bf5-R3-Z1T"/>
+ </connections>
+ </textField>
+ <imageView userInteractionEnabled="NO" contentMode="scaleToFill" image="usernameField@2x.png" id="Elf-P6-ZRk">
+ <rect key="frame" x="18" y="204" width="285" height="57"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+ </imageView>
+ <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Email" minimumFontSize="17" id="8a9-F2-it3">
+ <rect key="frame" x="28" y="211" width="265" height="44"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+ <fontDescription key="fontDescription" name="Helvetica" family="Helvetica" pointSize="18"/>
+ <textInputTraits key="textInputTraits" returnKeyType="done"/>
+ <connections>
+ <outlet property="delegate" destination="rmy-jc-pz9" id="1gf-Uc-X21"/>
+ </connections>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Password" minimumFontSize="17" id="sez-8J-bQf">
- <rect key="frame" x="30" y="225" width="265" height="44"/>
+ <rect key="frame" x="28" y="278" width="265" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="Helvetica" family="Helvetica" pointSize="18"/>
- <textInputTraits key="textInputTraits"/>
+ <textInputTraits key="textInputTraits" secureTextEntry="YES"/>
+ <connections>
+ <outlet property="delegate" destination="rmy-jc-pz9" id="LSq-rs-kUi"/>
+ </connections>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Repeat password" minimumFontSize="17" id="OF3-uD-ddM">
- <rect key="frame" x="30" y="277" width="265" height="44"/>
+ <rect key="frame" x="28" y="330" width="265" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="Helvetica" family="Helvetica" pointSize="18"/>
- <textInputTraits key="textInputTraits"/>
+ <textInputTraits key="textInputTraits" returnKeyType="done" secureTextEntry="YES"/>
+ <connections>
+ <outlet property="delegate" destination="rmy-jc-pz9" id="hkl-RJ-4Av"/>
+ </connections>
</textField>
</subviews>
</scrollView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
+ <connections>
+ <outlet property="emailField" destination="8a9-F2-it3" id="flu-VM-hIp"/>
+ <outlet property="nameField" destination="Yk1-R8-dmU" id="C2G-66-450"/>
+ <outlet property="password2Field" destination="OF3-uD-ddM" id="ROI-vl-Dh3"/>
+ <outlet property="passwordField" destination="sez-8J-bQf" id="xCp-Rx-OEM"/>
+ <outlet property="scrollView" destination="ZIs-u4-Gig" id="sli-H1-ACO"/>
+ <outlet property="usernameField" destination="sQj-0Y-3sJ" id="lOd-98-q76"/>
+ </connections>
</viewController>
</objects>
<point key="canvasLocation" x="1023" y="-13"/>
@@ -560,6 +603,14 @@
</class>
<class className="RegisterViewController" superclassName="UIViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/RegisterViewController.h"/>
+ <relationships>
+ <relationship kind="outlet" name="emailField" candidateClass="UITextField"/>
+ <relationship kind="outlet" name="nameField" candidateClass="UITextField"/>
+ <relationship kind="outlet" name="password2Field" candidateClass="UITextField"/>
+ <relationship kind="outlet" name="passwordField" candidateClass="UITextField"/>
+ <relationship kind="outlet" name="scrollView" candidateClass="UIScrollView"/>
+ <relationship kind="outlet" name="usernameField" candidateClass="UITextField"/>
+ </relationships>
</class>
<class className="ServerViewController" superclassName="UIViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/ServerViewController.h"/>

0 comments on commit 796678e

Please sign in to comment.
Something went wrong with that request. Please try again.