Skip to content

Commit

Permalink
Magic Links: Limit the code input text field on login to 6 chars (#1209)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliescheer authored Aug 12, 2024
2 parents ccc0b55 + d25347c commit 5ebddf2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Simplenote.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
BA5A65952C09164100F605A6 /* MockStorageSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5A65942C09164100F605A6 /* MockStorageSettings.swift */; };
BA5A65972C091D0600F605A6 /* CoreDataValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5A65962C091D0600F605A6 /* CoreDataValidator.swift */; };
BA5A65992C091E6000F605A6 /* MockStorageValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5A65982C091E6000F605A6 /* MockStorageValidator.swift */; };
BA5CB2822C5ACBBB00FF5B55 /* CharacterCountLimiter.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5CB2812C5ACBBB00FF5B55 /* CharacterCountLimiter.swift */; };
BA5F020626BB57F000581E92 /* NSAlert+Simplenote.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5F020426BB57F000581E92 /* NSAlert+Simplenote.swift */; };
BA71EC242BC88FD000F42CB1 /* CSSearchable+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA52005A2BC878F1003F1B75 /* CSSearchable+Helpers.swift */; };
BA71EC252BC88FFC00F42CB1 /* NSManagedObjectContext+Simplenote.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA52005C2BC88397003F1B75 /* NSManagedObjectContext+Simplenote.swift */; };
Expand Down Expand Up @@ -759,6 +760,7 @@
BA5A65942C09164100F605A6 /* MockStorageSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockStorageSettings.swift; sourceTree = "<group>"; };
BA5A65962C091D0600F605A6 /* CoreDataValidator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataValidator.swift; sourceTree = "<group>"; };
BA5A65982C091E6000F605A6 /* MockStorageValidator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockStorageValidator.swift; sourceTree = "<group>"; };
BA5CB2812C5ACBBB00FF5B55 /* CharacterCountLimiter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CharacterCountLimiter.swift; sourceTree = "<group>"; };
BA5F020426BB57F000581E92 /* NSAlert+Simplenote.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSAlert+Simplenote.swift"; sourceTree = "<group>"; };
BA8CF21B2BFD20770087F33D /* Intents.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Intents.framework; path = System/Library/Frameworks/Intents.framework; sourceTree = SDKROOT; };
BA938CED26AD055400BE5A1D /* AccountVerificationController+TestHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AccountVerificationController+TestHelpers.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1112,6 +1114,7 @@
376EE3EA202B748E00E3812E /* SPAboutTextField.swift */,
3700E97521C1E390004771C9 /* SPTextAttachment.swift */,
B57CB880244E421400BA7969 /* SPTextField.swift */,
BA5CB2812C5ACBBB00FF5B55 /* CharacterCountLimiter.swift */,
A667305325C9751B00090DE3 /* SearchMapView.swift */,
);
name = Views;
Expand Down Expand Up @@ -2047,6 +2050,7 @@
files = (
B58117C525B9D57F00927E0C /* AccountVerificationViewController.swift in Sources */,
B5AF76C824A3F00600B7D530 /* TagListState.swift in Sources */,
BA5CB2822C5ACBBB00FF5B55 /* CharacterCountLimiter.swift in Sources */,
B5469FD12587FCD9007ED7BE /* NSSortDescriptor+Simplenote.swift in Sources */,
B5D586D02C2396A900F3ADCC /* MagicLinkRequestedView.swift in Sources */,
466FFEA817CC10A800399652 /* main.m in Sources */,
Expand Down
1 change: 1 addition & 0 deletions Simplenote/AuthViewController+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extension AuthViewController {

codeTextField.placeholderString = Localization.codePlaceholder
codeTextField.delegate = self
codeTextField.textField.formatter = CharacterCountLimiter()

// Secondary Action
secondaryActionButton.contentTintColor = .simplenoteBrandColor
Expand Down
18 changes: 18 additions & 0 deletions Simplenote/CharacterCountLimiter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Foundation

class CharacterCountLimiter: Formatter {
var characterLimit: Int = 6

override func isPartialStringValid(_ partialString: String, newEditingString newString: AutoreleasingUnsafeMutablePointer<NSString?>?, errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) -> Bool {
partialString.count <= characterLimit
}

override func string(for obj: Any?) -> String? {
obj as? String
}

override func getObjectValue(_ obj: AutoreleasingUnsafeMutablePointer<AnyObject?>?, for string: String, errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) -> Bool {
obj?.pointee = string as AnyObject
return true
}
}

0 comments on commit 5ebddf2

Please sign in to comment.