Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jleandroperez committed Mar 1, 2021
2 parents 7b30b26 + 696dca6 commit dadba86
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 31 deletions.
3 changes: 2 additions & 1 deletion Simperium-OSX/SPAuthenticationTextField.h
Expand Up @@ -13,7 +13,8 @@
@property (assign) id delegate;
@property (strong) NSTextField *textField;

- (id)initWithFrame:(NSRect)frame secure:(BOOL)secure;
- (instancetype)initWithFrame:(NSRect)frame secure:(BOOL)secure;

- (void)setPlaceholderString:(NSString *)string;
- (NSString *)stringValue;
- (void)setStringValue:(NSString *)string;
Expand Down
67 changes: 38 additions & 29 deletions Simperium-OSX/SPAuthenticationTextField.m
Expand Up @@ -55,12 +55,11 @@ - (BOOL)becomeFirstResponder {



#pragma mark ====================================================================================
#pragma mark SPAuthenticationTextField
#pragma mark ====================================================================================
#pragma mark - SPAuthenticationTextField

@interface SPAuthenticationTextField()
@property (nonatomic, assign) BOOL isWindowFistResponder;
@property (nonatomic, assign) BOOL secure;
@end

@implementation SPAuthenticationTextField
Expand All @@ -72,34 +71,44 @@ - (void)dealloc {
- (instancetype)initWithFrame:(NSRect)frame secure:(BOOL)secure {
self = [super initWithFrame:frame];
if (self) {
// Center the textField vertically
int paddingX = 10;
int fontSize = 20;
CGFloat fieldHeight = [[SPAuthenticationConfiguration sharedInstance] regularFontHeightForSize:fontSize];
CGFloat fieldY = (self.frame.size.height - fieldHeight) / 2;
CGRect textFrame = NSMakeRect(paddingX, fieldY, frame.size.width-paddingX*2, fieldHeight);

Class textFieldClass = secure ? [SPSecureTextField class] : [SPTextField class];
_textField = [[textFieldClass alloc] initWithFrame:textFrame];
NSFont *font = [NSFont fontWithName:[SPAuthenticationConfiguration sharedInstance].regularFontName size:fontSize];
[_textField setFont:font];
[_textField setTextColor:[NSColor colorWithCalibratedWhite:0.1 alpha:1.0]];
[_textField setDrawsBackground:NO];
[_textField setBezeled:NO];
[_textField setBordered:NO];
[_textField setFocusRingType:NSFocusRingTypeNone];
[[_textField cell] setWraps:NO];
[[_textField cell] setScrollable:YES];
[self addSubview:_textField];

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(handleTextFieldDidBeginEditing:) name:SPTextFieldDidBecomeFirstResponder object:_textField];
[nc addObserver:self selector:@selector(handleTextFieldDidFinishEditing:) name:NSControlTextDidEndEditingNotification object:_textField];
[self setupInterface:secure];
}

return self;
}

- (void)awakeFromNib {
[super awakeFromNib];
[self setupInterface:self.secure];
}

- (void)setupInterface:(BOOL)secure {
// Center the textField vertically
NSRect frame = self.frame;
CGFloat paddingX = 10;
CGFloat fontSize = 20;
CGFloat fieldHeight = [[SPAuthenticationConfiguration sharedInstance] regularFontHeightForSize:fontSize];
CGFloat fieldY = (self.frame.size.height - fieldHeight) / 2;
CGRect textFrame = NSMakeRect(paddingX, fieldY, frame.size.width-paddingX*2, fieldHeight);

Class textFieldClass = secure ? [SPSecureTextField class] : [SPTextField class];
_textField = [[textFieldClass alloc] initWithFrame:textFrame];
NSFont *font = [NSFont fontWithName:[SPAuthenticationConfiguration sharedInstance].regularFontName size:fontSize];
[_textField setFont:font];
[_textField setTextColor:[NSColor colorWithCalibratedWhite:0.1 alpha:1.0]];
[_textField setDrawsBackground:NO];
[_textField setBezeled:NO];
[_textField setBordered:NO];
[_textField setFocusRingType:NSFocusRingTypeNone];
[[_textField cell] setWraps:NO];
[[_textField cell] setScrollable:YES];
[self addSubview:_textField];

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(handleTextFieldDidBeginEditing:) name:SPTextFieldDidBecomeFirstResponder object:_textField];
[nc addObserver:self selector:@selector(handleTextFieldDidFinishEditing:) name:NSControlTextDidEndEditingNotification object:_textField];
}

- (void)setStringValue:(NSString *)string {
_textField.stringValue = string;
}
Expand Down Expand Up @@ -128,11 +137,11 @@ - (void)setEnabled:(BOOL)enabled {
- (void)drawRect:(NSRect)dirtyRect {
NSBezierPath *betterBounds = [NSBezierPath bezierPathWithRect:self.bounds];
[betterBounds addClip];

if (self.isWindowFistResponder) {
[[NSColor colorWithCalibratedWhite:0.9 alpha:1.0] setFill];
[betterBounds fill];

} else {
[[NSColor colorWithCalibratedWhite:250.f/255.f alpha:1.0] setFill];
[betterBounds fill];
Expand Down
3 changes: 3 additions & 0 deletions Simperium/SPAuthenticator.h
Expand Up @@ -43,6 +43,9 @@ NS_ASSUME_NONNULL_BEGIN

- (BOOL)authenticateIfNecessary;

- (void)authenticateWithUsername:(NSString *)username
token:(NSString *)token;

- (void)authenticateWithUsername:(NSString *)username
password:(NSString *)password
success:(SuccessBlockType)successHandler
Expand Down
13 changes: 13 additions & 0 deletions Simperium/SPAuthenticator.m
Expand Up @@ -117,6 +117,19 @@ - (BOOL)authenticateIfNecessary {

#pragma mark - Authentication

- (void)authenticateWithUsername:(NSString *)username
token:(NSString *)token {
NSParameterAssert(username);
NSParameterAssert(token);

SPUser *user = [[SPUser alloc] initWithEmail:username token:token];
self.simperium.user = user;

[self saveCredentialsForUser:user];
[self notifySignupDidSucceed];
[self notifyAuthenticationDidSucceed];
}

- (void)authenticateWithUsername:(NSString *)username
password:(NSString *)password
success:(SuccessBlockType)successHandler
Expand Down
2 changes: 1 addition & 1 deletion Simperium/SPEnvironment.m
Expand Up @@ -30,7 +30,7 @@
#endif

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

/// SSL Pinning
///
Expand Down

0 comments on commit dadba86

Please sign in to comment.