From 9e53fc07208ada41e92562949ee424f4979489e1 Mon Sep 17 00:00:00 2001 From: Hernan Zalazar Date: Tue, 22 Sep 2015 17:09:42 -0300 Subject: [PATCH 01/10] Add Email subspec for 'email' connection --- Lock.podspec | 10 ++ Lock/Lock.xcodeproj/project.pbxproj | 96 +++++------ Lock/Lock/A0HomeViewController.m | 6 - Lock/Podfile | 2 +- Lock/Podfile.lock | 7 +- .../Email/A0EmailCodeViewController.xib | 122 ++++++++++++++ .../Email/A0EmailLockViewController.xib | 86 ++++++++++ .../Email/A0EmailSendCodeViewController.xib | 106 ++++++++++++ Pod/Classes/Core/A0APIClient.h | 27 ++- Pod/Classes/Core/A0APIClient.m | 37 ++++- Pod/Classes/Email/A0EmailLockViewController.h | 67 ++++++++ Pod/Classes/Email/A0EmailLockViewController.m | 156 ++++++++++++++++++ .../Email/A0Lock+A0EmailLockViewController.h | 45 +++++ .../Email/A0Lock+A0EmailLockViewController.m | 40 +++++ .../Email/Private/A0EmailCodeViewController.h | 35 ++++ .../Email/Private/A0EmailCodeViewController.m | 114 +++++++++++++ .../Private/A0EmailSendCodeViewController.h | 35 ++++ .../Private/A0EmailSendCodeViewController.m | 117 +++++++++++++ 18 files changed, 1049 insertions(+), 59 deletions(-) create mode 100644 Pod/Assets/Email/A0EmailCodeViewController.xib create mode 100644 Pod/Assets/Email/A0EmailLockViewController.xib create mode 100644 Pod/Assets/Email/A0EmailSendCodeViewController.xib create mode 100644 Pod/Classes/Email/A0EmailLockViewController.h create mode 100644 Pod/Classes/Email/A0EmailLockViewController.m create mode 100644 Pod/Classes/Email/A0Lock+A0EmailLockViewController.h create mode 100644 Pod/Classes/Email/A0Lock+A0EmailLockViewController.m create mode 100644 Pod/Classes/Email/Private/A0EmailCodeViewController.h create mode 100644 Pod/Classes/Email/Private/A0EmailCodeViewController.m create mode 100644 Pod/Classes/Email/Private/A0EmailSendCodeViewController.h create mode 100644 Pod/Classes/Email/Private/A0EmailSendCodeViewController.m diff --git a/Lock.podspec b/Lock.podspec index ad5653c15..e52bae796 100644 --- a/Lock.podspec +++ b/Lock.podspec @@ -89,6 +89,16 @@ Auth0 is a SaaS that helps you with Authentication and Authorization. You can us sms.resource_bundles = { 'Auth0.SMS' => ['Pod/Assets/SMS/*.plist', 'Pod/Assets/SMS/Images/*.png'] } end + s.subspec 'Email' do |email| + email.platform = :ios + email.public_header_files = 'Pod/Classes/Email/*.h' + email.private_header_files = 'Pod/Classes/Email/Private/*.h' + email.source_files = ['Pod/Classes/Email/*.{h,m}', 'Pod/Classes/Email/Private/*.{h,m}'] + email.resources = 'Pod/Assets/Email/*.xib' + email.dependency 'Lock/UI' + email.resource_bundles = { 'Auth0.Email' => ['Pod/Assets/Email/*.plist', 'Pod/Assets/Email/Images/*.png'] } + end + s.subspec '1Password' do |onepassword| onepassword.platform = :ios onepassword.public_header_files = 'Pod/Classes/1Password/*.h' diff --git a/Lock/Lock.xcodeproj/project.pbxproj b/Lock/Lock.xcodeproj/project.pbxproj index 4f35ee3d7..651033427 100644 --- a/Lock/Lock.xcodeproj/project.pbxproj +++ b/Lock/Lock.xcodeproj/project.pbxproj @@ -7,7 +7,7 @@ objects = { /* Begin PBXBuildFile section */ - 1963201521DC48EB2CE099C5 /* libPods-Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EBE03102F38F6B4C779E3AA7 /* libPods-Tests.a */; }; + 423EE20195902EA7B6FEE2A7 /* libPods-Lock.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E064118EC7AD3EEDE6297D57 /* libPods-Lock.a */; }; 5F0AA5BF1A78308100073120 /* A0APIClientSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F0AA5BE1A78308100073120 /* A0APIClientSpec.m */; }; 5F0ADBBC19E5FCB800EA7EAA /* A0SimpleConnectionDomainMatcherSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F0ADBBB19E5FCB800EA7EAA /* A0SimpleConnectionDomainMatcherSpec.m */; }; 5F12365C19675EA9006CE0D2 /* A0ApplicationSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F12365B19675EA9006CE0D2 /* A0ApplicationSpec.m */; }; @@ -64,7 +64,7 @@ 6003F5B1195388D20070C39A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; }; 6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; }; 6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5B8195388D20070C39A /* InfoPlist.strings */; }; - F59547DB5922E7296831F065 /* libPods-Lock.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7A0DF3DB1CF1B60C37EA055A /* libPods-Lock.a */; }; + D7A6FA1B79E21A9677691871 /* libPods-Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E9556E627A6C970326AA48DD /* libPods-Tests.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -78,9 +78,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 3C6006F47E64770EB84285B3 /* Pods-Lock.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Lock.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Lock/Pods-Lock.debug.xcconfig"; sourceTree = ""; }; - 3EA2B89CABCA670E8559CCE5 /* Pods-Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-Tests/Pods-Tests.release.xcconfig"; sourceTree = ""; }; - 4FE86D747F16255659237957 /* Pods-Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Tests/Pods-Tests.debug.xcconfig"; sourceTree = ""; }; + 572EFC8AFE63EBB3FDFFF57D /* Pods-Lock.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Lock.release.xcconfig"; path = "Pods/Target Support Files/Pods-Lock/Pods-Lock.release.xcconfig"; sourceTree = ""; }; 5F0935471A1AB4A600144E67 /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = CHANGELOG.md; path = ../CHANGELOG.md; sourceTree = ""; }; 5F0AA5BE1A78308100073120 /* A0APIClientSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = A0APIClientSpec.m; sourceTree = ""; }; 5F0ADBBB19E5FCB800EA7EAA /* A0SimpleConnectionDomainMatcherSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = A0SimpleConnectionDomainMatcherSpec.m; sourceTree = ""; }; @@ -158,10 +156,12 @@ 6003F5B9195388D20070C39A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 606FC2411953D9B200FFA9A0 /* Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Prefix.pch"; sourceTree = ""; }; 77F27E12879146B986D43383 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; - 7A0DF3DB1CF1B60C37EA055A /* libPods-Lock.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Lock.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 785CD5636CC4F0219AF83208 /* Pods-Lock.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Lock.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Lock/Pods-Lock.debug.xcconfig"; sourceTree = ""; }; + 936C8D67A8F69B5F417E3BDC /* Pods-Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Tests/Pods-Tests.debug.xcconfig"; sourceTree = ""; }; + 98764BA81EB282D5246EB984 /* Pods-Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-Tests/Pods-Tests.release.xcconfig"; sourceTree = ""; }; BD9DE0F8BCE04F059EE4B037 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; - EBE03102F38F6B4C779E3AA7 /* libPods-Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - F15FC091EBF7DE612A84F1B9 /* Pods-Lock.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Lock.release.xcconfig"; path = "Pods/Target Support Files/Pods-Lock/Pods-Lock.release.xcconfig"; sourceTree = ""; }; + E064118EC7AD3EEDE6297D57 /* libPods-Lock.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Lock.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + E9556E627A6C970326AA48DD /* libPods-Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -172,7 +172,7 @@ 6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */, 6003F592195388D20070C39A /* UIKit.framework in Frameworks */, 6003F58E195388D20070C39A /* Foundation.framework in Frameworks */, - F59547DB5922E7296831F065 /* libPods-Lock.a in Frameworks */, + 423EE20195902EA7B6FEE2A7 /* libPods-Lock.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -184,13 +184,24 @@ 6003F5B0195388D20070C39A /* XCTest.framework in Frameworks */, 6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */, 6003F5B1195388D20070C39A /* Foundation.framework in Frameworks */, - 1963201521DC48EB2CE099C5 /* libPods-Tests.a in Frameworks */, + D7A6FA1B79E21A9677691871 /* libPods-Tests.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 520E7E22D5D3081ABC792C8D /* Pods */ = { + isa = PBXGroup; + children = ( + 785CD5636CC4F0219AF83208 /* Pods-Lock.debug.xcconfig */, + 572EFC8AFE63EBB3FDFFF57D /* Pods-Lock.release.xcconfig */, + 936C8D67A8F69B5F417E3BDC /* Pods-Tests.debug.xcconfig */, + 98764BA81EB282D5246EB984 /* Pods-Tests.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; 5FC7EECD1A7957BE00C83B09 /* HttpResponses */ = { isa = PBXGroup; children = ( @@ -232,7 +243,7 @@ 6003F5B5195388D20070C39A /* Tests */, 6003F58C195388D20070C39A /* Frameworks */, 6003F58B195388D20070C39A /* Products */, - 7B3604C1D518EAC6C4063835 /* Pods */, + 520E7E22D5D3081ABC792C8D /* Pods */, ); sourceTree = ""; }; @@ -253,8 +264,8 @@ 6003F58F195388D20070C39A /* CoreGraphics.framework */, 6003F591195388D20070C39A /* UIKit.framework */, 6003F5AF195388D20070C39A /* XCTest.framework */, - 7A0DF3DB1CF1B60C37EA055A /* libPods-Lock.a */, - EBE03102F38F6B4C779E3AA7 /* libPods-Tests.a */, + E064118EC7AD3EEDE6297D57 /* libPods-Lock.a */, + E9556E627A6C970326AA48DD /* libPods-Tests.a */, ); name = Frameworks; sourceTree = ""; @@ -350,17 +361,6 @@ name = "Podspec Metadata"; sourceTree = ""; }; - 7B3604C1D518EAC6C4063835 /* Pods */ = { - isa = PBXGroup; - children = ( - 3C6006F47E64770EB84285B3 /* Pods-Lock.debug.xcconfig */, - F15FC091EBF7DE612A84F1B9 /* Pods-Lock.release.xcconfig */, - 4FE86D747F16255659237957 /* Pods-Tests.debug.xcconfig */, - 3EA2B89CABCA670E8559CCE5 /* Pods-Tests.release.xcconfig */, - ); - name = Pods; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -368,12 +368,12 @@ isa = PBXNativeTarget; buildConfigurationList = 6003F5BF195388D20070C39A /* Build configuration list for PBXNativeTarget "Lock" */; buildPhases = ( - 889853524F0724937B583D98 /* Check Pods Manifest.lock */, + 1EADCA37ECABABC8B829668C /* Check Pods Manifest.lock */, 6003F586195388D20070C39A /* Sources */, 6003F587195388D20070C39A /* Frameworks */, 6003F588195388D20070C39A /* Resources */, 5F3A9C531A0D14D400154DF2 /* Fabric */, - 5D12E253386738CBD5594591 /* Copy Pods Resources */, + CD65E3E69F22398DF0075556 /* Copy Pods Resources */, ); buildRules = ( ); @@ -388,11 +388,11 @@ isa = PBXNativeTarget; buildConfigurationList = 6003F5C2195388D20070C39A /* Build configuration list for PBXNativeTarget "Tests" */; buildPhases = ( - 9D1C7C43B0B16DFCE3DEB891 /* Check Pods Manifest.lock */, + 5C5F4498FABB452B05D4A5AE /* Check Pods Manifest.lock */, 6003F5AA195388D20070C39A /* Sources */, 6003F5AB195388D20070C39A /* Frameworks */, 6003F5AC195388D20070C39A /* Resources */, - 6BF3047585FCD1CA79716611 /* Copy Pods Resources */, + 25E124A9EFA46C40715EED08 /* Copy Pods Resources */, ); buildRules = ( ); @@ -479,78 +479,78 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 5D12E253386738CBD5594591 /* Copy Pods Resources */ = { + 1EADCA37ECABABC8B829668C /* Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Copy Pods Resources"; + name = "Check Pods Manifest.lock"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Lock/Pods-Lock-resources.sh\"\n"; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; - 5F3A9C531A0D14D400154DF2 /* Fabric */ = { + 25E124A9EFA46C40715EED08 /* Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = Fabric; + name = "Copy Pods Resources"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if [ ${CONFIGURATION} != \"Debug\" ]; then\n echo \"Running Fabric scripts\"\n source $SRCROOT/.fabric_key\n \"${PODS_ROOT}/Fabric/Fabric.framework/run\" $FABRIC_API_KEY $FABRIC_BUILD_SECRET\nelse\n echo \"Skipped Fabric scripts\"\nfi"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Tests/Pods-Tests-resources.sh\"\n"; + showEnvVarsInLog = 0; }; - 6BF3047585FCD1CA79716611 /* Copy Pods Resources */ = { + 5C5F4498FABB452B05D4A5AE /* Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Copy Pods Resources"; + name = "Check Pods Manifest.lock"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Tests/Pods-Tests-resources.sh\"\n"; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; - 889853524F0724937B583D98 /* Check Pods Manifest.lock */ = { + 5F3A9C531A0D14D400154DF2 /* Fabric */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Check Pods Manifest.lock"; + name = Fabric; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; - showEnvVarsInLog = 0; + shellScript = "if [ ${CONFIGURATION} != \"Debug\" ]; then\n echo \"Running Fabric scripts\"\n source $SRCROOT/.fabric_key\n \"${PODS_ROOT}/Fabric/Fabric.framework/run\" $FABRIC_API_KEY $FABRIC_BUILD_SECRET\nelse\n echo \"Skipped Fabric scripts\"\nfi"; }; - 9D1C7C43B0B16DFCE3DEB891 /* Check Pods Manifest.lock */ = { + CD65E3E69F22398DF0075556 /* Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Check Pods Manifest.lock"; + name = "Copy Pods Resources"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Lock/Pods-Lock-resources.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -724,7 +724,7 @@ }; 6003F5C0195388D20070C39A /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 3C6006F47E64770EB84285B3 /* Pods-Lock.debug.xcconfig */; + baseConfigurationReference = 785CD5636CC4F0219AF83208 /* Pods-Lock.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; @@ -751,7 +751,7 @@ }; 6003F5C1195388D20070C39A /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = F15FC091EBF7DE612A84F1B9 /* Pods-Lock.release.xcconfig */; + baseConfigurationReference = 572EFC8AFE63EBB3FDFFF57D /* Pods-Lock.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; @@ -781,7 +781,7 @@ }; 6003F5C3195388D20070C39A /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 4FE86D747F16255659237957 /* Pods-Tests.debug.xcconfig */; + baseConfigurationReference = 936C8D67A8F69B5F417E3BDC /* Pods-Tests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/Lock.app/Lock"; CLANG_ENABLE_MODULES = YES; @@ -806,7 +806,7 @@ }; 6003F5C4195388D20070C39A /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 3EA2B89CABCA670E8559CCE5 /* Pods-Tests.release.xcconfig */; + baseConfigurationReference = 98764BA81EB282D5246EB984 /* Pods-Tests.release.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/Lock.app/Lock"; CLANG_ENABLE_MODULES = YES; diff --git a/Lock/Lock/A0HomeViewController.m b/Lock/Lock/A0HomeViewController.m index 536ee23b7..88d5e9c27 100644 --- a/Lock/Lock/A0HomeViewController.m +++ b/Lock/Lock/A0HomeViewController.m @@ -29,10 +29,6 @@ #import #import "A0LockApplication.h" -#if __has_include() -#define TOUCH_ID 1 -#endif - #define kClientIdKey @"Auth0ClientId" #define kTenantKey @"Auth0Tenant" @@ -105,7 +101,6 @@ - (void)loginNative:(id)sender { - (void)loginTouchID:(id)sender { [self.keychain clearAll]; -#ifdef TOUCHID A0Lock *lock = [[A0LockApplication sharedInstance] lock]; A0TouchIDLockViewController *controller = [lock newTouchIDViewController]; @@ -122,7 +117,6 @@ - (void)loginTouchID:(id)sender { }]; }; [lock presentTouchIDController:controller fromController:self]; -#endif } - (void)loginSMS:(id)sender { diff --git a/Lock/Podfile b/Lock/Podfile index 094033c89..a9437014f 100644 --- a/Lock/Podfile +++ b/Lock/Podfile @@ -9,7 +9,7 @@ def pod_with_warnings end target 'Lock', :exclusive => true do - pod 'Lock', :path => '../', :subspecs => ['SMS', 'ReactiveCore', '1Password', 'Safari', 'WebView', 'TouchID'] + pod 'Lock', :path => '../', :subspecs => ['ReactiveCore', '1Password', 'Safari', 'WebView', 'TouchID', 'Email', 'SMS'] pod 'Lock-Facebook', '~> 2.0' pod 'Lock-Twitter', '~> 1.0' diff --git a/Lock/Podfile.lock b/Lock/Podfile.lock index 1b92b236c..b3c5dcb97 100644 --- a/Lock/Podfile.lock +++ b/Lock/Podfile.lock @@ -122,6 +122,10 @@ PODS: - CocoaLumberjack (~> 2.0) - libextobjc (~> 0.4) - Lock/Core + - Lock/Email (1.18.0): + - CocoaLumberjack (~> 2.0) + - libextobjc (~> 0.4) + - Lock/UI - Lock/ReactiveCore (1.18.0): - CocoaLumberjack (~> 2.0) - libextobjc (~> 0.4) @@ -199,6 +203,7 @@ DEPENDENCIES: - Lock-Facebook (~> 2.0) - Lock-Twitter (~> 1.0) - Lock/1Password (from `../`) + - Lock/Email (from `../`) - Lock/ReactiveCore (from `../`) - Lock/Safari (from `../`) - Lock/SMS (from `../`) @@ -229,7 +234,7 @@ SPEC CHECKSUMS: ISO8601DateFormatter: ab926648eebe497f4d167c0fd083992f959f1274 JWTDecode: c193d229af74dd72121515c976f930ccbed96a2a libextobjc: a650fc1bf489a3d3a9bc2e621efa3e1006fc5471 - Lock: 74df3917e300de2d2accddf4d8dfcc1c72e683cf + Lock: 9a2cdd8f3878c98bee4379fc47cff56f4b7a89ed Lock-Facebook: 36e982eb8221dd07fcc9770781e3fc6363be28d3 Lock-Twitter: 8168e4c3861f6cc6581d1b8d635f41e29a607cb3 LUKeychainAccess: 6479edb12cf06e11ff3336f796959eedbc58f714 diff --git a/Pod/Assets/Email/A0EmailCodeViewController.xib b/Pod/Assets/Email/A0EmailCodeViewController.xib new file mode 100644 index 000000000..48892e69a --- /dev/null +++ b/Pod/Assets/Email/A0EmailCodeViewController.xib @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pod/Assets/Email/A0EmailLockViewController.xib b/Pod/Assets/Email/A0EmailLockViewController.xib new file mode 100644 index 000000000..a295a48d2 --- /dev/null +++ b/Pod/Assets/Email/A0EmailLockViewController.xib @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pod/Assets/Email/A0EmailSendCodeViewController.xib b/Pod/Assets/Email/A0EmailSendCodeViewController.xib new file mode 100644 index 000000000..db8c93e54 --- /dev/null +++ b/Pod/Assets/Email/A0EmailSendCodeViewController.xib @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Pod/Classes/Core/A0APIClient.h b/Pod/Classes/Core/A0APIClient.h index 193c69498..3e0ee08e8 100644 --- a/Pod/Classes/Core/A0APIClient.h +++ b/Pod/Classes/Core/A0APIClient.h @@ -237,8 +237,8 @@ NS_ASSUME_NONNULL_BEGIN ///---------------------------------------- /** - * Perform login of a user with phone number & SMS code using `SMS` connection. - * If app info is available and it doesn't have a SMS connection, it will fail. + * Perform login of a user with phone number & SMS code using `sms` connection. + * If app info is available and it doesn't have a `sms` connection, it will fail. * * @param phoneNumber phone number where the user received the code and previously registered with. * @param passcode passcode received by SMS. @@ -255,6 +255,29 @@ NS_ASSUME_NONNULL_BEGIN success:(A0APIClientAuthenticationSuccess)success failure:(A0APIClientError)failure; +///---------------------------------------- +/// @name Email Authentication +///---------------------------------------- + +/** + * Perform login of a user with email address & code using `email` connection. + * If app info is available and it doesn't have a `email` connection, it will fail. + * + * @param email address where the user received the code and previously registered with. + * @param passcode passcode received by email. + * @param parameters optional parameters for Auth0 API. It can be nil + * @param success block called on successful login with it's token info and profile + * @param failure block called on failure with the reason as a parameter + * + * @return an instance of `NSURLSessionDataTask` + * @see A0AuthParameters + */ +- (NSURLSessionDataTask *)loginWithEmail:(NSString *)email + passcode:(NSString *)passcode + parameters:(nullable A0AuthParameters *)parameters + success:(A0APIClientAuthenticationSuccess)success + failure:(A0APIClientError)failure; + ///---------------------------------------- /// @name Social Authentication ///---------------------------------------- diff --git a/Pod/Classes/Core/A0APIClient.m b/Pod/Classes/Core/A0APIClient.m index 8db269443..cc456b833 100644 --- a/Pod/Classes/Core/A0APIClient.m +++ b/Pod/Classes/Core/A0APIClient.m @@ -299,7 +299,7 @@ - (NSURLSessionDataTask *)loginWithPhoneNumber:(NSString *)phoneNumber A0Connection *connection = strategy.connections.firstObject; if (!self.application || connection.name) { [defaultParameters addValuesFromParameters:parameters]; - A0LogVerbose(@"Starting Login with username & password %@", defaultParameters); + A0LogVerbose(@"Starting Login with phone & passcode %@", defaultParameters); if ([self checkForDatabaseConnectionIn:defaultParameters failure:failure]) { @weakify(self); NSDictionary *payload = [defaultParameters asAPIPayload]; @@ -318,6 +318,41 @@ - (NSURLSessionDataTask *)loginWithPhoneNumber:(NSString *)phoneNumber return nil; } +#pragma mark - Email Authentication + +- (NSURLSessionDataTask *)loginWithEmail:(NSString *)email + passcode:(NSString *)passcode + parameters:(A0AuthParameters *)parameters + success:(A0APIClientAuthenticationSuccess)success + failure:(A0APIClientError)failure { + A0AuthParameters *defaultParameters = [A0AuthParameters newWithDictionary:@{ + kEmailParamName: email, + kPasswordParamName: passcode, + kGrantTypeParamName: @"password", + kClientIdParamName: self.clientId, + kConnectionParamName: @"email", + }]; + A0Strategy *strategy = [self.application strategyByName:@"email"]; + A0Connection *connection = strategy.connections.firstObject; + if (!self.application || connection.name) { + [defaultParameters addValuesFromParameters:parameters]; + A0LogVerbose(@"Starting Login with email & passcode %@", defaultParameters); + @weakify(self); + NSDictionary *payload = [defaultParameters asAPIPayload]; + return [self.manager POST:[self.router loginPath] parameters:payload success:^(NSURLSessionDataTask *operation, id responseObject) { + @strongify(self); + A0LogDebug(@"Obtained JWT & accessToken from Auth0 API"); + [self fetchUserInfoWithTokenInfo:responseObject success:success failure:failure]; + } failure:[A0APIClient sanitizeFailureBlock:failure]]; + } else { + A0LogError(@"No email connection found in Auth0 app."); + if (failure) { + failure([A0Errors noConnectionNameFound]); + } + } + return nil; +} + #pragma mark - Social Authentication - (NSURLSessionDataTask *)authenticateWithSocialConnectionName:(NSString *)connectionName diff --git a/Pod/Classes/Email/A0EmailLockViewController.h b/Pod/Classes/Email/A0EmailLockViewController.h new file mode 100644 index 000000000..d64a5bac8 --- /dev/null +++ b/Pod/Classes/Email/A0EmailLockViewController.h @@ -0,0 +1,67 @@ +// A0EmailLockViewController.h +// +// Copyright (c) 2014 Auth0 (http://auth0.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import +#import + +@class A0AuthParameters, A0UserProfile, A0Token, A0Lock; + +@interface A0EmailLockViewController : A0ContainerViewController + +/** + * Initialize a new instance of the ViewController + * + * @param lock an instance of Lock configured for an Auth0 application + * @return an initialized instance. + * @see A0Lock + */ +- (instancetype)initWithLock:(A0Lock *)lock; + +/** + Allows the A0AuthenticationViewController to be dismissed by adding a button. Default is NO + */ +@property (assign, nonatomic) BOOL closable; + +/** + Block that is called on successful authentication. It has two parameters profile and token. + */ +@property (copy, nonatomic) void(^onAuthenticationBlock)(A0UserProfile *profile, A0Token *token); + +/** + Block that is called on when the user dismisses the Login screen. Only when closable property is `YES`. + */ +@property (copy, nonatomic) void(^onUserDismissBlock)(); + +/** + * Parameters to be sent to all Authentication request to Auth0 API. + * @see A0AuthParameters + */ +@property (strong, nonatomic) A0AuthParameters *authenticationParameters; + +/** + * Block that returns a signed JWT with `create:users` scope for API v2. It's required to send SMS code. + * For more info: https://api.auth0.com/docs/api/v2 + * @deprecated 1.14.0. Lock now use `/passwordless/start` endpoint instead of API v2. + */ +@property (copy, nonatomic) NSString *(^auth0APIToken)() DEPRECATED_MSG_ATTRIBUTE("a API v2 JWT is no longer necessary"); + +@end diff --git a/Pod/Classes/Email/A0EmailLockViewController.m b/Pod/Classes/Email/A0EmailLockViewController.m new file mode 100644 index 000000000..de514233e --- /dev/null +++ b/Pod/Classes/Email/A0EmailLockViewController.m @@ -0,0 +1,156 @@ +// A0EmailLockViewController.m +// +// Copyright (c) 2014 Auth0 (http://auth0.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "A0EmailLockViewController.h" +#import "A0Theme.h" +#import "A0EmailSendCodeViewController.h" +#import "A0AuthParameters.h" +#import "A0EmailCodeViewController.h" +#import "A0NavigationView.h" +#import "A0TitleView.h" +#import "A0Lock.h" +#import + +#define kEmailKey @"auth0-lock-email-email" + +@interface A0EmailLockViewController () + +@property (weak, nonatomic) IBOutlet UIButton *closeButton; + +@property (strong, nonatomic) A0Lock *lock; + +- (IBAction)close:(id)sender; + +@end + +@implementation A0EmailLockViewController + +AUTH0_DYNAMIC_LOGGER_METHODS + +- (instancetype)initWithLock:(A0Lock *)lock { + NSAssert(lock != nil, @"Must have a non-nil Lock instance"); + self = [self initWithNibName:NSStringFromClass(self.class) bundle:[NSBundle bundleForClass:self.class]]; + if (self) { + _lock = lock; + } + return self; +} + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) { + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + self.modalPresentationStyle = UIModalPresentationFormSheet; + } + _closable = NO; + _authenticationParameters = [A0AuthParameters newDefaultParams]; + } + return self; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + + NSAssert(self.navigationController != nil, @"Must be inside a UINavigationController"); + + self.navigationController.navigationBarHidden = YES; + + self.closeButton.enabled = self.closable; + self.closeButton.hidden = !self.closable; + + A0Theme *theme = [A0Theme sharedInstance]; + UIImage *image = [theme imageForKey:A0ThemeScreenBackgroundImageName]; + if (image) { + UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; + [self.view insertSubview:imageView atIndex:0]; + } + self.view.backgroundColor = [theme colorForKey:A0ThemeScreenBackgroundColor]; + self.titleView.iconImage = [theme imageForKey:A0ThemeIconImageName]; + self.closeButton.tintColor = [theme colorForKey:A0ThemeSecondaryButtonTextColor]; + + [self displayController:[self buildEmailSendCode]]; + UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard:)]; + [self.view addGestureRecognizer:tapRecognizer]; +} + +- (void)close:(id)sender { + A0LogVerbose(@"Dismissing SMS view controller on user's request."); + if (self.onUserDismissBlock) { + self.onUserDismissBlock(); + } + [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; +} + +- (void)hideKeyboard:(UIGestureRecognizer *)recognizer { + UIViewController *controller = self.childViewControllers.firstObject; + [controller hideKeyboard]; +} + +- (UIStatusBarStyle)preferredStatusBarStyle { + return [[A0Theme sharedInstance] statusBarStyle]; +} + +- (BOOL)prefersStatusBarHidden { + return [[A0Theme sharedInstance] statusBarHidden]; +} + +- (A0EmailSendCodeViewController *)buildEmailSendCode { + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + NSString *email = [defaults stringForKey:kEmailKey]; + A0EmailSendCodeViewController *controller = [[A0EmailSendCodeViewController alloc] init]; + @weakify(self); + controller.onRegisterBlock = ^(NSString *email){ + @strongify(self); + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + [defaults setObject:email forKey:kEmailKey]; + [defaults synchronize]; + [self displayController:[self buildEmailCodeWithEmail:email]]; + }; + controller.currentEmail = email; + controller.lock = self.lock; + [self.navigationView removeAll]; + if (email) { + [self.navigationView addButtonWithLocalizedTitle:A0LocalizedString(@"ALREADY HAVE A CODE?") actionBlock:^{ + @strongify(self); + [self displayController:[self buildEmailCodeWithEmail:email]]; + }]; + } + return controller; +} + +- (A0EmailCodeViewController *)buildEmailCodeWithEmail:(NSString *)email { + @weakify(self); + A0EmailCodeViewController *controller = [[A0EmailCodeViewController alloc] init]; + controller.email = email; + controller.parameters = self.authenticationParameters; + controller.onAuthenticationBlock = self.onAuthenticationBlock; + controller.lock = self.lock; + void(^showRegister)() = ^{ + @strongify(self); + [self displayController:[self buildEmailSendCode]]; + }; + [self.navigationView removeAll]; + [self.navigationView addButtonWithLocalizedTitle:A0LocalizedString(@"DIDN'T RECEIVE CODE?") actionBlock:showRegister]; + return controller; +} + +@end diff --git a/Pod/Classes/Email/A0Lock+A0EmailLockViewController.h b/Pod/Classes/Email/A0Lock+A0EmailLockViewController.h new file mode 100644 index 000000000..0c024649f --- /dev/null +++ b/Pod/Classes/Email/A0Lock+A0EmailLockViewController.h @@ -0,0 +1,45 @@ +// A0Lock+A0EmailLockViewController.h +// +// Copyright (c) 2015 Auth0 (http://auth0.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import +#import "A0Lock.h" + +@class A0EmailLockViewController; + +@interface A0Lock (A0EmailLockViewController) + +/** + * Creates a new instance of `A0EmailLockViewController` + * + * @return a new instance + */ +- (A0EmailLockViewController *)newEmailViewController; + +/** + * Presents a `A0EmailLockViewController` from a UIViewController. This method takes care of embedding the `A0EmailLockViewController` inside a `UINavigationController` + * + * @param smsController controller to present + * @param controller controller that will present the SMS VC. + */ +- (void)presentSMSController:(A0EmailLockViewController *)emailController fromController:(UIViewController *)controller; + +@end diff --git a/Pod/Classes/Email/A0Lock+A0EmailLockViewController.m b/Pod/Classes/Email/A0Lock+A0EmailLockViewController.m new file mode 100644 index 000000000..432b9cfb2 --- /dev/null +++ b/Pod/Classes/Email/A0Lock+A0EmailLockViewController.m @@ -0,0 +1,40 @@ +// A0Lock+A0EmailLockViewController.m +// +// Copyright (c) 2015 Auth0 (http://auth0.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "A0Lock+A0EmailLockViewController.h" +#import "A0EmailLockViewController.h" + +@implementation A0Lock (A0SMSLockViewController) + +- (A0EmailLockViewController *)newEmailViewController { + return [[A0EmailLockViewController alloc] initWithLock:self]; +} + +- (void)presentSMSController:(A0EmailLockViewController *)emailController fromController:(UIViewController *)controller { + UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:emailController]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + navController.modalPresentationStyle = UIModalPresentationFormSheet; + } + [controller presentViewController:navController animated:YES completion:nil]; +} + +@end diff --git a/Pod/Classes/Email/Private/A0EmailCodeViewController.h b/Pod/Classes/Email/Private/A0EmailCodeViewController.h new file mode 100644 index 000000000..3741b00c8 --- /dev/null +++ b/Pod/Classes/Email/Private/A0EmailCodeViewController.h @@ -0,0 +1,35 @@ +// A0EmailCodeViewController.h +// +// Copyright (c) 2014 Auth0 (http://auth0.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import +#import + +@class A0AuthParameters, A0UserProfile, A0Token, A0Lock; + +@interface A0EmailCodeViewController : UIViewController + +@property (copy, nonatomic) NSString *email; +@property (copy, nonatomic) A0AuthParameters *parameters; +@property (strong, nonatomic) A0Lock *lock; +@property (copy, nonatomic) void(^onAuthenticationBlock)(A0UserProfile *profile, A0Token *token); + +@end diff --git a/Pod/Classes/Email/Private/A0EmailCodeViewController.m b/Pod/Classes/Email/Private/A0EmailCodeViewController.m new file mode 100644 index 000000000..ef038509d --- /dev/null +++ b/Pod/Classes/Email/Private/A0EmailCodeViewController.m @@ -0,0 +1,114 @@ +// A0EmailCodeViewController.m +// +// Copyright (c) 2014 Auth0 (http://auth0.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "A0EmailCodeViewController.h" +#import "A0CredentialFieldView.h" +#import "A0ProgressButton.h" +#import "A0Theme.h" +#import "A0UIUtilities.h" +#import "A0APIClient.h" +#import "A0Errors.h" + +#import +#import "A0Lock.h" +#import "NSObject+A0APIClientProvider.h" +#import "NSError+A0APIError.h" + +@interface A0EmailCodeViewController () + +@property (weak, nonatomic) IBOutlet UIView *credentialBoxView; +@property (weak, nonatomic) IBOutlet A0CredentialFieldView *codeFieldView; +@property (weak, nonatomic) IBOutlet A0ProgressButton *loginButton; +@property (weak, nonatomic) IBOutlet UILabel *messageLabel; + +- (IBAction)login:(id)sender; + +@end + +@implementation A0EmailCodeViewController + +AUTH0_DYNAMIC_LOGGER_METHODS + +- (instancetype)init { + return [self initWithNibName:NSStringFromClass(self.class) bundle:[NSBundle bundleForClass:self.class]]; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + self.title = A0LocalizedString(@"Enter email code"); + A0Theme *theme = [A0Theme sharedInstance]; + [theme configureTextField:self.codeFieldView.textField]; + [theme configurePrimaryButton:self.loginButton]; + [theme configureLabel:self.messageLabel]; + [self.loginButton setTitle:A0LocalizedString(@"LOGIN") forState:UIControlStateNormal]; + NSString *message = [NSString stringWithFormat:A0LocalizedString(@"Please check your mail %@.\nYou’ve received a message from us with your passcode"), self.email]; + NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:message]; + if (self.email) { + NSRange phoneRange = [message rangeOfString:self.email]; + [attrString setAttributes:@{ + NSFontAttributeName: [UIFont boldSystemFontOfSize:self.messageLabel.font.pointSize], + } + range:phoneRange]; + } + self.messageLabel.attributedText = attrString; + [self.codeFieldView setFieldPlaceholderText:A0LocalizedString(@"Email Code")]; +} + +- (void)login:(id)sender { + A0LogVerbose(@"About to login with email %@", self.email); + [self.codeFieldView.textField resignFirstResponder]; + NSString *passcode = [self.codeFieldView.textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + BOOL valid = passcode.length > 0; + [self.codeFieldView setInvalid:!valid]; + if (passcode.length > 0) { + @weakify(self); + void(^failureBlock)(NSError *) = ^(NSError *error) { + @strongify(self); + [self.loginButton setInProgress:NO]; + NSString *title = [error a0_auth0ErrorWithCode:A0ErrorCodeNotConnectedToInternet] ? error.localizedDescription : A0LocalizedString(@"There was an error logging in"); + NSString *message = [error a0_auth0ErrorWithCode:A0ErrorCodeNotConnectedToInternet] ? error.localizedFailureReason : [A0Errors localizedStringForSMSLoginError:error]; + A0ShowAlertErrorView(title, message); + }; + [self.loginButton setInProgress:YES]; + A0APIClient *client = [self a0_apiClientFromProvider:self.lock]; + [client loginWithEmail:self.email + passcode:passcode + parameters:self.parameters + success:self.onAuthenticationBlock + failure:failureBlock]; + } else { + A0LogError(@"Must provide a non-empty passcode."); + A0ShowAlertErrorView(A0LocalizedString(@"There was an error logging in"), A0LocalizedString(@"You must enter a valid email code")); + } +} + +#pragma mark - A0KeyboardEnabledView + +- (CGRect)rectToKeepVisibleInView:(UIView *)view { + CGRect rect = [view convertRect:self.loginButton.frame fromView:self.loginButton.superview]; + return rect; +} + +- (void)hideKeyboard { + [self.codeFieldView.textField resignFirstResponder]; +} +@end diff --git a/Pod/Classes/Email/Private/A0EmailSendCodeViewController.h b/Pod/Classes/Email/Private/A0EmailSendCodeViewController.h new file mode 100644 index 000000000..e8ffe140e --- /dev/null +++ b/Pod/Classes/Email/Private/A0EmailSendCodeViewController.h @@ -0,0 +1,35 @@ +// A0EmailSendCodeViewController.h +// +// Copyright (c) 2014 Auth0 (http://auth0.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import +#import + +@class A0Lock; + +@interface A0EmailSendCodeViewController : UIViewController + +@property (copy, nonatomic) NSString *currentEmail; +@property (strong, nonatomic) A0Lock *lock; + +@property (copy, nonatomic) void(^onRegisterBlock)(NSString *email); + +@end diff --git a/Pod/Classes/Email/Private/A0EmailSendCodeViewController.m b/Pod/Classes/Email/Private/A0EmailSendCodeViewController.m new file mode 100644 index 000000000..c2df33fc5 --- /dev/null +++ b/Pod/Classes/Email/Private/A0EmailSendCodeViewController.m @@ -0,0 +1,117 @@ +// A0EmailSendCodeViewController.m +// +// Copyright (c) 2014 Auth0 (http://auth0.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "A0EmailSendCodeViewController.h" +#import "A0Theme.h" +#import "A0ProgressButton.h" +#import "A0CredentialFieldView.h" +#import "A0APIClient.h" +#import "A0RequestAccessTokenOperation.h" +#import "A0SendSMSOperation.h" +#import "A0UIUtilities.h" +#import "A0EmailValidator.h" +#import "A0Errors.h" +#import "A0Lock.h" +#import "NSError+A0APIError.h" + +#import + +@interface A0EmailSendCodeViewController () + +@property (weak, nonatomic) IBOutlet A0CredentialFieldView *emailFieldView; +@property (weak, nonatomic) IBOutlet A0ProgressButton *registerButton; +@property (weak, nonatomic) IBOutlet UILabel *messageLabel; + +@property (strong, nonatomic) A0EmailValidator *validator; + +- (IBAction)registerSMS:(id)sender; + +@end + +@implementation A0EmailSendCodeViewController + +AUTH0_DYNAMIC_LOGGER_METHODS + +- (instancetype)init { + return [self initWithNibName:NSStringFromClass(self.class) bundle:[NSBundle bundleForClass:self.class]]; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + + self.title = A0LocalizedString(@"Send Passcode"); + A0Theme *theme = [A0Theme sharedInstance]; + [theme configureTextField:self.emailFieldView.textField]; + [theme configurePrimaryButton:self.registerButton]; + [theme configureLabel:self.messageLabel]; + self.messageLabel.text = A0LocalizedString(@"Please enter your email"); + [self.emailFieldView setFieldPlaceholderText:A0LocalizedString(@"Email")]; + [self.registerButton setTitle:A0LocalizedString(@"SEND") forState:UIControlStateNormal]; + + self.emailFieldView.textField.text = self.currentEmail; + self.validator = [[A0EmailValidator alloc] initWithField:self.emailFieldView.textField]; +} + +- (void)registerSMS:(id)sender { + NSError *error = [self.validator validate]; + if (!error) { + [self.emailFieldView setInvalid:NO]; + [self.emailFieldView.textField resignFirstResponder]; + A0LogDebug(@"Registering email %@", self.emailFieldView.textField.text); + [self.registerButton setInProgress:YES]; + NSString *phoneNumber = self.emailFieldView.textField.text; + @weakify(self); + void(^onFailure)(NSError *) = ^(NSError *error) { + @strongify(self); + A0LogError(@"Failed to send SMS code with error %@", error); + NSString *title = [error a0_auth0ErrorWithCode:A0ErrorCodeNotConnectedToInternet] ? error.localizedDescription : A0LocalizedString(@"There was an error sending the email code"); + NSString *message = [error a0_auth0ErrorWithCode:A0ErrorCodeNotConnectedToInternet] ? error.localizedFailureReason : A0LocalizedString(@"Couldn't send the email with your login code. Please try again later."); + A0ShowAlertErrorView(title, message); + [self.registerButton setInProgress:NO]; + }; + A0LogDebug(@"About to send Email code to %@", phoneNumber); + A0APIClient *client = self.lock.apiClient; + [client startPasswordlessWithEmail:phoneNumber success:^{ + @strongify(self); + A0LogDebug(@"Email code sent to %@", phoneNumber); + [self.registerButton setInProgress:NO]; + if (self.onRegisterBlock) { + self.onRegisterBlock(phoneNumber); + } + } failure:onFailure]; + } else { + [self.emailFieldView setInvalid:YES]; + A0ShowAlertErrorView(error.localizedDescription, error.localizedFailureReason); + } +} + +#pragma mark - A0KeyboardEnabledView + +- (CGRect)rectToKeepVisibleInView:(UIView *)view { + CGRect rect = [view convertRect:self.registerButton.frame fromView:self.registerButton.superview]; + return rect; +} + +- (void)hideKeyboard { + [self.emailFieldView.textField resignFirstResponder]; +} +@end From a0ecf284cc11f986d951eed32af471f5bf89a4aa Mon Sep 17 00:00:00 2001 From: Hernan Zalazar Date: Tue, 22 Sep 2015 17:43:44 -0300 Subject: [PATCH 02/10] Whitelist FB hosts for iOS 9 --- Lock/Lock/Lock-Info.plist | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Lock/Lock/Lock-Info.plist b/Lock/Lock/Lock-Info.plist index b7d06a0ad..a509087c4 100644 --- a/Lock/Lock/Lock-Info.plist +++ b/Lock/Lock/Lock-Info.plist @@ -102,5 +102,32 @@ UIInterfaceOrientationPortrait + NSAppTransportSecurity + + NSExceptionDomains + + facebook.com + + NSIncludesSubdomains + + NSExceptionRequiresForwardSecrecy + + + fbcdn.net + + NSIncludesSubdomains + + NSExceptionRequiresForwardSecrecy + + + akamaihd.net + + NSIncludesSubdomains + + NSExceptionRequiresForwardSecrecy + + + + From 484f60ea3c393052ddda9c9a249c02aedd884a95 Mon Sep 17 00:00:00 2001 From: Hernan Zalazar Date: Tue, 22 Sep 2015 18:19:15 -0300 Subject: [PATCH 03/10] Fix name of a category method --- Pod/Classes/Email/A0Lock+A0EmailLockViewController.h | 2 +- Pod/Classes/Email/A0Lock+A0EmailLockViewController.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Pod/Classes/Email/A0Lock+A0EmailLockViewController.h b/Pod/Classes/Email/A0Lock+A0EmailLockViewController.h index 0c024649f..21bec36b3 100644 --- a/Pod/Classes/Email/A0Lock+A0EmailLockViewController.h +++ b/Pod/Classes/Email/A0Lock+A0EmailLockViewController.h @@ -40,6 +40,6 @@ * @param smsController controller to present * @param controller controller that will present the SMS VC. */ -- (void)presentSMSController:(A0EmailLockViewController *)emailController fromController:(UIViewController *)controller; +- (void)presentEmailController:(A0EmailLockViewController *)emailController fromController:(UIViewController *)controller; @end diff --git a/Pod/Classes/Email/A0Lock+A0EmailLockViewController.m b/Pod/Classes/Email/A0Lock+A0EmailLockViewController.m index 432b9cfb2..3e6fe9b22 100644 --- a/Pod/Classes/Email/A0Lock+A0EmailLockViewController.m +++ b/Pod/Classes/Email/A0Lock+A0EmailLockViewController.m @@ -29,7 +29,7 @@ - (A0EmailLockViewController *)newEmailViewController { return [[A0EmailLockViewController alloc] initWithLock:self]; } -- (void)presentSMSController:(A0EmailLockViewController *)emailController fromController:(UIViewController *)controller { +- (void)presentEmailController:(A0EmailLockViewController *)emailController fromController:(UIViewController *)controller { UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:emailController]; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { navController.modalPresentationStyle = UIModalPresentationFormSheet; From d065fbfd01dc822cf4b94f43a5c445c3ead256bb Mon Sep 17 00:00:00 2001 From: Hernan Zalazar Date: Tue, 22 Sep 2015 18:19:29 -0300 Subject: [PATCH 04/10] Make Lock test app for iOS 9+ --- Lock/Lock.xcodeproj/project.pbxproj | 4 ++-- Lock/Podfile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lock/Lock.xcodeproj/project.pbxproj b/Lock/Lock.xcodeproj/project.pbxproj index 651033427..2c9faab44 100644 --- a/Lock/Lock.xcodeproj/project.pbxproj +++ b/Lock/Lock.xcodeproj/project.pbxproj @@ -742,7 +742,7 @@ GCC_PREFIX_HEADER = "Lock/Lock-Prefix.pch"; GOOGLE_PLUS_CLIENT_ID = "856630117504-cman9rbv3t5diu2ksgkn4n3m4p0b84ti.apps.googleusercontent.com"; INFOPLIST_FILE = "Lock/Lock-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; PRODUCT_NAME = Lock; PROVISIONING_PROFILE = ""; WRAPPER_EXTENSION = app; @@ -772,7 +772,7 @@ ); GOOGLE_PLUS_CLIENT_ID = "856630117504-sc8oovbfg7tl5fhqrbocee292inbuebq.apps.googleusercontent.com"; INFOPLIST_FILE = "Lock/Lock-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; PRODUCT_NAME = Lock; PROVISIONING_PROFILE = ""; WRAPPER_EXTENSION = app; diff --git a/Lock/Podfile b/Lock/Podfile index a9437014f..bb1b3ce6b 100644 --- a/Lock/Podfile +++ b/Lock/Podfile @@ -1,6 +1,6 @@ source 'https://github.com/CocoaPods/Specs.git' -platform :ios, '7.0' +platform :ios, '9.0' def pod_with_warnings pod 'libextobjc', :inhibit_warnings => true #Ignore warnings for this lib From 39988ecec3797310f6839a04f0f68c505ca63859 Mon Sep 17 00:00:00 2001 From: Hernan Zalazar Date: Tue, 22 Sep 2015 19:28:21 -0300 Subject: [PATCH 05/10] Fix request to send email code --- .../Images.xcassets/AppIcon.appiconset/Contents.json | 10 ++++++++++ Pod/Classes/Core/A0APIClient.m | 2 +- Pod/Classes/Lock.h | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Lock/Lock/Images.xcassets/AppIcon.appiconset/Contents.json b/Lock/Lock/Images.xcassets/AppIcon.appiconset/Contents.json index 40f5867c1..60e46bdc4 100644 --- a/Lock/Lock/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/Lock/Lock/Images.xcassets/AppIcon.appiconset/Contents.json @@ -6,12 +6,22 @@ "filename" : "iPhone 6,5,4 @2x -58-1.png", "scale" : "2x" }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, { "size" : "40x40", "idiom" : "iphone", "filename" : "iPhone 6,5,4 @2x -80.png", "scale" : "2x" }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, { "size" : "60x60", "idiom" : "iphone", diff --git a/Pod/Classes/Core/A0APIClient.m b/Pod/Classes/Core/A0APIClient.m index cc456b833..613982ce8 100644 --- a/Pod/Classes/Core/A0APIClient.m +++ b/Pod/Classes/Core/A0APIClient.m @@ -326,7 +326,7 @@ - (NSURLSessionDataTask *)loginWithEmail:(NSString *)email success:(A0APIClientAuthenticationSuccess)success failure:(A0APIClientError)failure { A0AuthParameters *defaultParameters = [A0AuthParameters newWithDictionary:@{ - kEmailParamName: email, + kUsernameParamName: email, kPasswordParamName: passcode, kGrantTypeParamName: @"password", kClientIdParamName: self.clientId, diff --git a/Pod/Classes/Lock.h b/Pod/Classes/Lock.h index 1c3326a35..e914865f3 100644 --- a/Pod/Classes/Lock.h +++ b/Pod/Classes/Lock.h @@ -61,6 +61,11 @@ #import "A0SMSLockViewController.h" #endif +#if __has_include("A0EmailLockViewController.h") +#import "A0Lock+A0EmailLockViewController.h" +#import "A0EmailLockViewController.h" +#endif + #if __has_include("A0PasswordManager.h") #import "A0PasswordManager.h" #endif From 04cbf67696d7a966e4eed871669f71689b5f40a5 Mon Sep 17 00:00:00 2001 From: Hernan Zalazar Date: Tue, 22 Sep 2015 19:28:45 -0300 Subject: [PATCH 06/10] Fix title of screen to input email code --- Pod/Classes/Email/Private/A0EmailCodeViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pod/Classes/Email/Private/A0EmailCodeViewController.m b/Pod/Classes/Email/Private/A0EmailCodeViewController.m index ef038509d..91387d9fc 100644 --- a/Pod/Classes/Email/Private/A0EmailCodeViewController.m +++ b/Pod/Classes/Email/Private/A0EmailCodeViewController.m @@ -54,7 +54,7 @@ - (instancetype)init { - (void)viewDidLoad { [super viewDidLoad]; - self.title = A0LocalizedString(@"Enter email code"); + self.title = A0LocalizedString(@"Enter Email Code"); A0Theme *theme = [A0Theme sharedInstance]; [theme configureTextField:self.codeFieldView.textField]; [theme configurePrimaryButton:self.loginButton]; From 81e282d249f4496f5d7c9a8ca62c12af9b9e9d00 Mon Sep 17 00:00:00 2001 From: Hernan Zalazar Date: Tue, 22 Sep 2015 19:29:18 -0300 Subject: [PATCH 07/10] Show Email Lock in sample app --- Lock/Lock/A0HomeViewController.h | 1 + Lock/Lock/A0HomeViewController.m | 20 ++ Lock/Lock/Base.lproj/Main.storyboard | 250 +++++++----------- .../Email/A0EmailSendCodeViewController.xib | 9 +- .../SMS/A0SMSSendCodeViewController.xib | 8 +- .../UI/A0DatabaseLoginViewController.xib | 9 +- 6 files changed, 125 insertions(+), 172 deletions(-) diff --git a/Lock/Lock/A0HomeViewController.h b/Lock/Lock/A0HomeViewController.h index 0a9f221c6..e5039ceb0 100644 --- a/Lock/Lock/A0HomeViewController.h +++ b/Lock/Lock/A0HomeViewController.h @@ -30,5 +30,6 @@ - (IBAction)loginNative:(id)sender; - (IBAction)loginTouchID:(id)sender; - (IBAction)loginSMS:(id)sender; +- (IBAction)loginEmail:(id)sender; @end diff --git a/Lock/Lock/A0HomeViewController.m b/Lock/Lock/A0HomeViewController.m index 88d5e9c27..eff3c8f75 100644 --- a/Lock/Lock/A0HomeViewController.m +++ b/Lock/Lock/A0HomeViewController.m @@ -137,4 +137,24 @@ - (void)loginSMS:(id)sender { }; [lock presentSMSController:controller fromController:self]; } + +- (void)loginEmail:(id)sender { + [self.keychain clearAll]; + A0Lock *lock = [[A0LockApplication sharedInstance] lock]; + A0EmailLockViewController *controller = [lock newEmailViewController]; + controller.closable = YES; + @weakify(self); + controller.onAuthenticationBlock = ^(A0UserProfile *profile, A0Token *token) { + NSLog(@"SUCCESS %@", profile); + @strongify(self); + [self.keychain setString:token.idToken forKey:@"id_token"]; + [self.keychain setString:token.refreshToken forKey:@"refresh_token"]; + [self.keychain setData:[NSKeyedArchiver archivedDataWithRootObject:profile] forKey:@"profile"]; + [self dismissViewControllerAnimated:YES completion:^(){ + [self performSegueWithIdentifier:@"LoggedIn" sender:self]; + }]; + }; + [lock presentEmailController:controller fromController:self]; +} + @end diff --git a/Lock/Lock/Base.lproj/Main.storyboard b/Lock/Lock/Base.lproj/Main.storyboard index eb1f0b547..ed008c283 100644 --- a/Lock/Lock/Base.lproj/Main.storyboard +++ b/Lock/Lock/Base.lproj/Main.storyboard @@ -1,7 +1,8 @@ - + - + + @@ -16,48 +17,48 @@ - + - + - + - + @@ -109,7 +110,7 @@ - + - - - + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -313,7 +249,7 @@ - + @@ -328,7 +264,7 @@ - + @@ -471,7 +407,7 @@ - + - + @@ -537,7 +473,7 @@