Skip to content

Instantly share code, notes, and snippets.

@calebhicks
Created July 30, 2014 05:37
Show Gist options
  • Save calebhicks/32d3c7a414cc62dc8c78 to your computer and use it in GitHub Desktop.
Save calebhicks/32d3c7a414cc62dc8c78 to your computer and use it in GitHub Desktop.
Parse Login/Signup View Controller Sample
//
// WIAccountTableViewController.m
// Wired In
//
// Created by Caleb Hicks on 7/17/14.
// Copyright (c) 2014 We Are Wired In. All rights reserved.
//
#import "WIAccountTableViewController.h"
#import <Parse/Parse.h>
@interface WIAccountTableViewController () <UITextFieldDelegate, PFLogInViewControllerDelegate, PFSignUpViewControllerDelegate>
@property (weak, nonatomic) IBOutlet UITextField *usernameField;
@property (weak, nonatomic) IBOutlet UITextField *passwordField;
@end
@implementation WIAccountTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.usernameField.delegate = self;
self.passwordField.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)signUp:(id)sender {
PFUser *user = [PFUser user];
user.username = self.usernameField.text;
user.email = self.usernameField.text;
user.password = self.passwordField.text;
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if(!error){
[self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"syncViewController"]]
animated:YES];
}
else{
NSString *errorString = [error userInfo][@"error"];
NSLog(@"%@",errorString);
}
}];
}
- (IBAction)signIn:(id)sender {
PFUser *user = [PFUser user];
user.username = self.usernameField.text;
user.email = self.usernameField.text;
user.password = self.passwordField.text;
[PFUser logInWithUsernameInBackground:user.username password:user.password block:^(PFUser *user, NSError *error) {
if(!error){
[self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"syncViewController"]]
animated:YES];
}
else{
NSString *errorString = [error userInfo][@"error"];
NSLog(@"%@",errorString);
}
}];
}
- (IBAction)forgotPassword:(id)sender {
[PFUser requestPasswordResetForEmailInBackground:self.usernameField.text block:^(BOOL succeeded, NSError *error) {
if(!error){
//go to sync settings screen
}
else{
NSString *errorString = [error userInfo][@"error"];
NSLog(@"%@",errorString);
}
}];
}
- (IBAction)showSidebarMenu:(id)sender {
[self.sideMenuViewController presentLeftMenuViewController];
}
#pragma mark - TextField Delegate Methods
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
//#pragma mark - Table view data source
//
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//{
//#warning Potentially incomplete method implementation.
// // Return the number of sections.
// return 0;
//}
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
//{
//#warning Incomplete method implementation.
// // Return the number of rows in the section.
// return 0;
//}
/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
// Configure the cell...
return cell;
}
*/
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
/*
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment