Skip to content

Commit

Permalink
Merge pull request #483 from Simperium/develop
Browse files Browse the repository at this point in the history
Simperium Mark 0.8.0
  • Loading branch information
jleandroperez committed May 10, 2015
2 parents 14003a9 + b13e455 commit 59c974c
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 44 deletions.
13 changes: 13 additions & 0 deletions Simperium-OSX/Simperium-OSX/SPAuthenticationWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ - (instancetype)init {
self.usernameField = [[SPAuthenticationTextField alloc] initWithFrame:NSMakeRect(SPAuthenticationFieldPaddingX, markerY - SPAuthenticationRowSize, SPAuthenticationFieldWidth, SPAuthenticationFieldHeight) secure:NO];

[self.usernameField setPlaceholderString:NSLocalizedString(@"Email Address", @"Placeholder text for login field")];

SPAuthenticationConfiguration *authConfig = [SPAuthenticationConfiguration sharedInstance];
if (_signingIn && authConfig.previousUsernameEnabled && authConfig.previousUsernameLogged) {
// Get previous username, to display as last used username in authentication view
[self.usernameField setStringValue:authConfig.previousUsernameLogged];
}
self.usernameField.delegate = self;
[authView addSubview:self.usernameField];

Expand Down Expand Up @@ -212,6 +218,13 @@ - (NSButton *)toggleButtonWithText:(NSString *)text frame:(CGRect)frame {

- (IBAction)forgotPassword:(id)sender {
NSString *forgotPasswordURL = [[SPAuthenticationConfiguration sharedInstance] forgotPasswordURL];

// Post the email already entered in the Username Field. This allows us to prefill the Forgot Password Form
if (self.usernameField.stringValue.length) {
NSString *parameters = [NSString stringWithFormat:@"?email=%@", self.usernameField.stringValue];
forgotPasswordURL = [forgotPasswordURL stringByAppendingString:parameters];
}

[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:forgotPasswordURL]];
}

Expand Down
2 changes: 1 addition & 1 deletion Simperium.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Simperium"
s.version = "0.7.9"
s.version = "0.8.0"
s.summary = "Simperium libraries."
s.description = "Simperium is a simple way for developers to move data as it changes, instantly and automatically."
s.homepage = "https://github.com/Simperium/simperium-ios"
Expand Down
9 changes: 8 additions & 1 deletion Simperium/JSONKit+Simperium.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ + (NSData *)sp_JSONDataFromObject:(id)object error:(NSError **)error
}

NSError *theError = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:object options:SPJSONWritingOptions error:&theError];
NSData *data = nil;

@try {
data = [NSJSONSerialization dataWithJSONObject:object options:SPJSONWritingOptions error:&theError];
}
@catch (NSException *exception) {
NSLog(@"Simperium JSON Parsing Exception: %@", exception.reason);
}

if (theError) {
if(error) {
*error = theError;
Expand Down
9 changes: 6 additions & 3 deletions Simperium/SPAuthenticationConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
@property (nonatomic, copy, readwrite) NSString *mediumFontName;
@property (nonatomic, copy, readwrite) NSString *logoImageName;

@property (nonatomic, assign, readwrite) NSString *forgotPasswordURL;
@property (nonatomic, assign, readwrite) NSString *termsOfServiceURL;
@property (nonatomic, strong, readwrite) NSString *forgotPasswordURL;
@property (nonatomic, strong, readwrite) NSString *termsOfServiceURL;

@property (nonatomic, assign, readwrite) BOOL previousUsernameEnabled;
@property (nonatomic, strong, readwrite) NSString *previousUsernameLogged;

#if !TARGET_OS_IPHONE
@property (nonatomic, strong) NSColor *controlColor;
@property (nonatomic, strong, readwrite) NSColor *controlColor;
#endif

+ (instancetype)sharedInstance;
Expand Down
26 changes: 19 additions & 7 deletions Simperium/SPAuthenticationConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
#pragma mark Constants
#pragma mark ====================================================================================

static NSString *SPAuthenticationDefaultRegularFontName = @"HelveticaNeue";
static NSString *SPAuthenticationDefaultMediumFontName = @"HelveticaNeue-Medium";
static NSString *SPAuthenticationTestString = @"Testyj";
static NSString *SPAuthenticationDefaultRegularFontName = @"HelveticaNeue";
static NSString *SPAuthenticationDefaultMediumFontName = @"HelveticaNeue-Medium";
static BOOL SPAuthenticationDefaultPreviousUsernameEnabled = NO;
static NSString *SPAuthenticationTestString = @"Testyj";
static NSString *SPAuthenticationPreviousUsernameKey = @"SPUsernamePrevious";


#pragma mark ====================================================================================
Expand All @@ -44,9 +46,10 @@ + (instancetype)sharedInstance
- (instancetype)init {
self = [super init];
if (self) {
_regularFontName = SPAuthenticationDefaultRegularFontName;
_mediumFontName = SPAuthenticationDefaultMediumFontName;
_termsOfServiceURL = SPTermsOfServiceURL;
_regularFontName = SPAuthenticationDefaultRegularFontName;
_mediumFontName = SPAuthenticationDefaultMediumFontName;
_termsOfServiceURL = SPTermsOfServiceURL;
_previousUsernameEnabled = SPAuthenticationDefaultPreviousUsernameEnabled;

#if !TARGET_OS_IPHONE
_controlColor = [NSColor colorWithCalibratedRed:65.f/255.f green:137.f/255.f blue:199.f/255.f alpha:1.0];
Expand All @@ -57,7 +60,7 @@ - (instancetype)init {
}


#pragma mark - Custom Setters
#pragma mark - Custom Properties

- (void)setForgotPasswordURL:(NSString *)forgotPasswordURL {
NSAssert(!forgotPasswordURL || forgotPasswordURL.sp_isValidUrl, @"Simperium: Invalid Forgot Password URL");
Expand All @@ -69,6 +72,15 @@ - (void)setTermsOfServiceURL:(NSString *)termsOfServiceURL {
_termsOfServiceURL = termsOfServiceURL;
}

- (void)setPreviousUsernameLogged:(NSString *)username {
[[NSUserDefaults standardUserDefaults] setObject:username forKey:SPAuthenticationPreviousUsernameKey];
[[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)previousUsernameLogged {
return [[NSUserDefaults standardUserDefaults] objectForKey:SPAuthenticationPreviousUsernameKey];
}


#pragma mark - Font Helpers

Expand Down
39 changes: 24 additions & 15 deletions Simperium/SPAuthenticationViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ - (void)viewDidLoad {
self.usernameField = [self textFieldWithPlaceholder:usernameText secure:NO];
_usernameField.keyboardType = UIKeyboardTypeEmailAddress;

if (_signingIn && configuration.previousUsernameEnabled && configuration.previousUsernameLogged) {
// Get previous username, to display as last used username in authentication view
_usernameField.text = configuration.previousUsernameLogged;
}

// Password Field
NSString *passwordText = NSLocalizedString(@"Password", @"Hint displayed in the password field");
self.passwordField = [self textFieldWithPlaceholder:passwordText secure:YES];
Expand Down Expand Up @@ -465,29 +470,25 @@ - (BOOL)validatePasswordConfirmation {
#pragma mark Login

- (void)performLogin {
self.actionButton.enabled = NO;
self.changeButton.enabled = NO;
self.cancelButton.enabled = NO;

[self.usernameField resignFirstResponder];
[self.passwordField resignFirstResponder];
[self.progressView setHidden: NO];
self.view.userInteractionEnabled = NO;
[self.view endEditing:YES];

[self.progressView setHidden:NO];
[self.progressView startAnimating];

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

[self.authenticator authenticateWithUsername:self.usernameField.text
password:self.passwordField.text
success:^{
[self.progressView setHidden: YES];
[self.progressView setHidden:YES];
[self.progressView stopAnimating];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
failure: ^(int responseCode, NSString *responseString){
self.actionButton.enabled = YES;
self.changeButton.enabled = YES;
self.cancelButton.enabled = YES;
self.view.userInteractionEnabled = YES;

[self.progressView setHidden: YES];
[self.progressView setHidden:YES];
[self.progressView stopAnimating];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

Expand Down Expand Up @@ -578,17 +579,25 @@ - (IBAction)termsAction:(id)sender {
}

- (IBAction)forgotPasswordAction:(id)sender {
NSString *forgotPasswordURL = [[SPAuthenticationConfiguration sharedInstance] forgotPasswordURL];
SPAuthenticationConfiguration *configuration = [SPAuthenticationConfiguration sharedInstance];
NSString *forgotPasswordURL = configuration.forgotPasswordURL;

// Post the email already entered in the Username Field. This allows us to prefill the Forgot Password Form
if (self.usernameField.text.length) {
NSString *parameters = [NSString stringWithFormat:@"?email=%@", self.usernameField.text];
forgotPasswordURL = [forgotPasswordURL stringByAppendingString:parameters];
}

[self showWebviewWithURL:forgotPasswordURL];
}

- (IBAction)changeAction:(id)sender {
_signingIn = !_signingIn;
NSArray *indexPaths = @[ [self confirmIndexPath] ];
if (_signingIn) {
[self.tableView deleteRowsAtIndexPaths: indexPaths withRowAnimation:UITableViewRowAnimationTop];
[self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop];
} else {
[self.tableView insertRowsAtIndexPaths: indexPaths withRowAnimation:UITableViewRowAnimationTop];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop];
}

[self.usernameField becomeFirstResponder];
Expand Down
2 changes: 1 addition & 1 deletion Simperium/SPEnvironment.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#endif

// TODO: Update this automatically via a script that looks at current git tag
NSString* const SPLibraryVersion = @"0.7.9";
NSString* const SPLibraryVersion = @"0.8.0";

// SSL Certificate Expiration: '2016-09-07 02:36:04 +0000' expressed as seconds since 1970
NSTimeInterval const SPCertificateExpiration = 1473215764;
Expand Down
12 changes: 8 additions & 4 deletions Simperium/SPPersistentMutableDictionary.m
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,10 @@ - (NSPersistentStoreCoordinator*)persistentStoreCoordinator {
BOOL success = [[NSFileManager defaultManager] createDirectoryAtURL:baseURL withIntermediateDirectories:YES attributes:nil error:&error];

if (!success) {
NSLog(@"%@ could not create baseURL %@: %@", NSStringFromClass([self class]), baseURL, error);
abort();
NSString *reason = [NSString stringWithFormat:@"Could not create baseURL %@. Error: %@", baseURL, error];
NSString *name = NSStringFromClass([self class]);
NSException *exception = [NSException exceptionWithName:name reason:reason userInfo:nil];
@throw exception;
}

// We've moved the store location to NSApplicationSupportDirectory. Let's move old folders, if needed
Expand All @@ -330,8 +332,10 @@ - (NSPersistentStoreCoordinator*)persistentStoreCoordinator {
// Try again
if (![psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])
{
NSLog(@"%@ Unresolved error %@: %@", NSStringFromClass([self class]), baseURL, error);
abort();
NSString *reason = [NSString stringWithFormat:@"Unresolved error %@: %@", baseURL, error];
NSString *name = NSStringFromClass([self class]);
NSException *exception = [NSException exceptionWithName:name reason:reason userInfo:nil];
@throw exception;
}
}

Expand Down
8 changes: 0 additions & 8 deletions Simperium/SPWebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,9 @@
//

#import "SPWebViewController.h"
#import "SPLogger.h"



#pragma mark ====================================================================================
#pragma mark Constants
#pragma mark ====================================================================================

static SPLogLevels logLevel = SPLogLevelsInfo;


#pragma mark ====================================================================================
#pragma mark Private
#pragma mark ====================================================================================
Expand Down
18 changes: 14 additions & 4 deletions Simperium/Simperium.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#import "JSONKit+Simperium.h"
#import "NSString+Simperium.h"
#import "SPLogger.h"
#import "SPAuthenticationConfiguration.h"



Expand Down Expand Up @@ -78,7 +79,6 @@ - (instancetype)initWithModel:(NSManagedObjectModel *)model
self.validatesObjects = YES;
self.authenticationEnabled = YES;
self.dynamicSchemaEnabled = YES;
self.authenticationEnabled = YES;
self.buckets = [NSMutableDictionary dictionary];

SPReachability *reachability = [SPReachability reachabilityForInternetConnection];
Expand Down Expand Up @@ -558,6 +558,12 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sende
dispatch_group_async(group, bucket.processorQueue, ^{ });
}

// Make sure that any pending OP's get process'ed
dispatch_group_enter(group);
[self.coreDataStorage commitPendingOperations:^{
dispatch_group_leave(group);
}];

// When the queues are empty, the changes are expected to be saved locally
dispatch_group_notify(group, dispatch_get_main_queue(), ^ {
[[NSApplication sharedApplication] replyToApplicationShouldTerminate:YES];
Expand Down Expand Up @@ -596,9 +602,6 @@ - (void)signOutAndRemoveLocalData:(BOOL)remove completion:(SimperiumSignoutCompl
[self.authenticator reset];
self.user = nil;

// We just logged out. Let's display SignIn fields next time!
self.shouldSignIn = YES;

// Reset the network manager and processors; any enqueued tasks will get skipped
self.logoutInProgress = YES;

Expand Down Expand Up @@ -745,6 +748,9 @@ - (NSUInteger)bytesReceived {

- (void)authenticationDidSucceedForUsername:(NSString *)username token:(NSString *)token {

// Save username as previous username, this username is used to display as last username in authentication views
[[SPAuthenticationConfiguration sharedInstance] setPreviousUsernameLogged:username];

// It's now safe to start the network managers
[self startNetworkManagers];

Expand Down Expand Up @@ -810,6 +816,10 @@ - (BOOL)isAuthVisible {
}

- (void)openAuthViewControllerAnimated:(BOOL)animated {
// Get previous username, if available the sign-in view should be set as default
SPAuthenticationConfiguration *configuration = [SPAuthenticationConfiguration sharedInstance];
self.shouldSignIn = configuration.previousUsernameEnabled && configuration.previousUsernameLogged;

#if TARGET_OS_IPHONE
if ([self isAuthVisible]) {
return;
Expand Down

0 comments on commit 59c974c

Please sign in to comment.