Skip to content

Commit

Permalink
Merge pull request #384 from auth0/feature-sso-style
Browse files Browse the repository at this point in the history
Change AD screens styling
  • Loading branch information
hzalaz authored Feb 3, 2017
2 parents 8ab2b5e + e7da027 commit 1b86bf0
Show file tree
Hide file tree
Showing 23 changed files with 271 additions and 275 deletions.
12 changes: 4 additions & 8 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
disabled_rules: # rule identifiers to exclude from running
- colon
- comma
- control_statement
- missing_docs
- force_cast
- variable_name
- cyclomatic_complexity
- function_body_length
- todo
Expand All @@ -17,8 +12,6 @@ included: # paths to include during linting. `--path` is ignored if present.
excluded: # paths to ignore during linting. Takes precedence over `included`.
- Carthage
- Pods
- Source/ExcludedFolder
- Source/ExcludedFile.swift

# configurable rules can be customized from this configuration file
# binary rules can set their severity level
Expand Down Expand Up @@ -46,9 +39,12 @@ type_name:
excluded: iPhone # excluded via string
variable_name:
min_length: # only min_length
error: 4 # only error
error: 3 # only error
excluded: # excluded via string array
- id
- URL
- GlobalAPIKey
- lhs
- rhs
- a0_orange
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit)
18 changes: 10 additions & 8 deletions App/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,19 @@ class ViewController: UIViewController {
actionButton(withTitle: "LOGIN WITH CDN") {
return Lock
.classic()
.withOptions {
applyDefaultOptions(&$0)
$0.loginAfterSignup = false
}
.withStyle {
$0.oauth2["slack"] = AuthStyle(
.allowedConnections(["contoso-ad", "fake-saml", "facebook", "google-oauth2"])
.withOptions {
applyDefaultOptions(&$0)
$0.loginAfterSignup = false
$0.enterpriseConnectionUsingActiveAuth = ["contoso-ad"]
}
.withStyle {
$0.oauth2["slack"] = AuthStyle(
name: "Slack",
color: UIColor ( red: 0.4118, green: 0.8078, blue: 0.6588, alpha: 1.0 ),
withImage: LazyImage(name: "ic_slack")
)
}
)
}
},
actionButton(withTitle: "LOGIN WITH CUSTOM STYLE") {
return Lock
Expand Down
8 changes: 4 additions & 4 deletions Lock.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/* Begin PBXBuildFile section */
5B011CDE1E13E16500543F12 /* NotificationStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B011CDD1E13E16500543F12 /* NotificationStatus.swift */; };
5B09717C1DC8F229003AA88F /* EnterpriseDomain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B09717B1DC8F229003AA88F /* EnterpriseDomain.swift */; };
5B09717C1DC8F229003AA88F /* HRDAuthenticatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B09717B1DC8F229003AA88F /* HRDAuthenticatable.swift */; };
5B09717E1DC8F292003AA88F /* EnterpriseActiveAuthInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B09717D1DC8F292003AA88F /* EnterpriseActiveAuthInteractor.swift */; };
5B0971801DC8F5C4003AA88F /* EnterpriseDomainPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B09717F1DC8F5C4003AA88F /* EnterpriseDomainPresenter.swift */; };
5B0971821DC8FAC5003AA88F /* EnterpriseDomainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5B0971811DC8FAC5003AA88F /* EnterpriseDomainView.swift */; };
Expand Down Expand Up @@ -203,7 +203,7 @@

/* Begin PBXFileReference section */
5B011CDD1E13E16500543F12 /* NotificationStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotificationStatus.swift; sourceTree = "<group>"; };
5B09717B1DC8F229003AA88F /* EnterpriseDomain.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EnterpriseDomain.swift; path = Lock/EnterpriseDomain.swift; sourceTree = SOURCE_ROOT; };
5B09717B1DC8F229003AA88F /* HRDAuthenticatable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HRDAuthenticatable.swift; path = Lock/HRDAuthenticatable.swift; sourceTree = SOURCE_ROOT; };
5B09717D1DC8F292003AA88F /* EnterpriseActiveAuthInteractor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EnterpriseActiveAuthInteractor.swift; path = Lock/EnterpriseActiveAuthInteractor.swift; sourceTree = SOURCE_ROOT; };
5B09717F1DC8F5C4003AA88F /* EnterpriseDomainPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EnterpriseDomainPresenter.swift; path = Lock/EnterpriseDomainPresenter.swift; sourceTree = SOURCE_ROOT; };
5B0971811DC8FAC5003AA88F /* EnterpriseDomainView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EnterpriseDomainView.swift; path = Lock/EnterpriseDomainView.swift; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -424,7 +424,7 @@
5FBE5CBD1D3E5C7B0038536D /* MultifactorAuthenticatable.swift */,
5FBE5CBF1D3E5E0A0038536D /* MultifactorInteractor.swift */,
5F73CDD71D3093BF00D8D8D1 /* PasswordRecoverable.swift */,
5B09717B1DC8F229003AA88F /* EnterpriseDomain.swift */,
5B09717B1DC8F229003AA88F /* HRDAuthenticatable.swift */,
5F57DFD11D4FE59800C54DA8 /* OAuth2Authenticatable.swift */,
5F57DFD31D4FE64700C54DA8 /* Auth0OAuth2Interactor.swift */,
5F2496B21D665A5600A1C6E2 /* DatabaseUserCreator.swift */,
Expand Down Expand Up @@ -1000,7 +1000,7 @@
5FC434861D1DF769005188BC /* View.swift in Sources */,
5FDB41CE1D2C79FD00166B67 /* Operations.swift in Sources */,
5B55F3C91E24273D00B75CF5 /* UnrecoverableErrorView.swift in Sources */,
5B09717C1DC8F229003AA88F /* EnterpriseDomain.swift in Sources */,
5B09717C1DC8F229003AA88F /* HRDAuthenticatable.swift in Sources */,
5F51EE681D1C88FC0024BCD6 /* SignUpView.swift in Sources */,
5F57DFD41D4FE64700C54DA8 /* Auth0OAuth2Interactor.swift in Sources */,
5B4DE0151DD66DE1004C8AC2 /* EnterpriseDomainInteractor.swift in Sources */,
Expand Down
4 changes: 1 addition & 3 deletions Lock/DatabaseOnlyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,10 @@ class DatabaseOnlyView: UIView, DatabaseView {
func presentEnterprise() {
guard let form = self.form as? CredentialView else { return }

let ssoBar = InfoBarView()
let ssoBar = InfoBarView.ssoInfoBar
let viewCount = self.container?.subviews.count ?? 0
let spacer = strutView(withHeight: 125 - CGFloat(viewCount) * 25)

ssoBar.title = "SINGLE SIGN-ON ENABLED".i18n(key: "com.auth0.lock.enterprise.sso", comment: "SSO Header")
ssoBar.setIcon("ic_lock")
ssoBar.isHidden = false

self.container?.insertArrangedSubview(ssoBar, at: 0)
Expand Down
23 changes: 13 additions & 10 deletions Lock/DatabasePresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ class DatabasePresenter: Presentable, Loggable {
}
}

if let connection = self.enterpriseInteractor?.connection {
if let connection = self.enterpriseInteractor?.connection, let domain = self.enterpriseInteractor?.domain {
if self.options.enterpriseConnectionUsingActiveAuth.contains(connection.name) {
self.navigator.navigate(.enterpriseActiveAuth(connection: connection))
self.navigator.navigate(.enterpriseActiveAuth(connection: connection, domain: domain))
} else {
self.enterpriseInteractor?.login(errorHandler)
}
Expand Down Expand Up @@ -207,7 +207,7 @@ class DatabasePresenter: Presentable, Loggable {
self.messagePresenter?.hideCurrent()

self.logger.verbose("new value: \(input.text) for type: \(input.type)")
let attribute: UserAttribute?
let attribute: UserAttribute
switch input.type {
case .email:
attribute = .email
Expand All @@ -220,21 +220,24 @@ class DatabasePresenter: Presentable, Loggable {
case .custom(let name, _, _, _, _, _):
attribute = .custom(name: name)
default:
attribute = nil
return
}

guard let attr = attribute else { return }
do {
try self.authenticator.update(attr, value: input.text)
try self.authenticator.update(attribute, value: input.text)
input.showValid()

if self.enterpriseInteractor?.matchDomain(input.text) != nil, let mode = self.databaseView?.switcher?.selected, mode == .login {
try self.enterpriseInteractor?.updateEmail(input.text)
self.logger.verbose("Enterprise connection detected: \(self.enterpriseInteractor?.connection)")
guard
let mode = self.databaseView?.switcher?.selected,
mode == .login
else { return }
try? self.enterpriseInteractor?.updateEmail(input.text)
if let connection = self.enterpriseInteractor?.connection {
self.logger.verbose("Enterprise connection detected: \(connection)")
if self.databaseView?.ssoBar == nil { self.databaseView?.presentEnterprise() }
} else {
self.databaseView?.removeEnterprise()
}
input.showValid()
} catch let error as InputValidationError {
input.showError(error.localizedMessage(withConnection: self.database))
} catch {
Expand Down
7 changes: 4 additions & 3 deletions Lock/EnterpriseActiveAuthPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ class EnterpriseActiveAuthPresenter: Presentable, Loggable {
var interactor: EnterpriseActiveAuthInteractor
var customLogger: Logger?
let options: Options
let domain: String?

init(interactor: EnterpriseActiveAuthInteractor, options: Options) {
init(interactor: EnterpriseActiveAuthInteractor, options: Options, domain: String? = nil) {
self.interactor = interactor
self.options = options
self.domain = domain
}

var messagePresenter: MessagePresenter?
Expand All @@ -44,9 +46,8 @@ class EnterpriseActiveAuthPresenter: Presentable, Loggable {
identifier = username
}

let view = EnterpriseActiveAuthView(identifer: identifier, identifierAttribute: self.interactor.identifierAttribute)
let view = EnterpriseActiveAuthView(identifier: identifier, identifierAttribute: self.interactor.identifierAttribute, domain: self.domain)
let form = view.form
view.ssoBar?.title = self.interactor.connection.domains.first

view.form?.onValueChange = { input in
self.messagePresenter?.hideCurrent()
Expand Down
49 changes: 25 additions & 24 deletions Lock/EnterpriseActiveAuthView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,55 +25,42 @@ import UIKit
class EnterpriseActiveAuthView: UIView, View {

weak var form: Form?
weak var ssoBar: InfoBarView?
weak var primaryButton: PrimaryButton?

private weak var container: UIStackView?

init(identifer: String?, identifierAttribute:UserAttribute) {
init(identifier: String?, identifierAttribute: UserAttribute, domain: String? = nil) {
let primaryButton = PrimaryButton()
let credentialView = CredentialView()
let titleView = UILabel()
let container = UIStackView()
let ssoBar = InfoBarView()

self.primaryButton = primaryButton
self.form = credentialView

super.init(frame: CGRect.zero)

self.addSubview(ssoBar)
self.addSubview(primaryButton)
self.addSubview(container)
self.addSubview(primaryButton)

ssoBar.title = "Single Sign-On Enabled".i18n(key: "com.auth0.lock.enterprise.sso", comment: "SSO Header").uppercased()
ssoBar.setIcon("ic_lock")
self.ssoBar = ssoBar

container.alignment = .fill
container.axis = .vertical
container.distribution = .equalSpacing
container.spacing = 10

constraintEqual(anchor: ssoBar.topAnchor, toAnchor: self.topAnchor)
constraintEqual(anchor: ssoBar.leftAnchor, toAnchor: self.leftAnchor)
constraintEqual(anchor: ssoBar.rightAnchor, toAnchor: self.rightAnchor)
constraintEqual(anchor: ssoBar.bottomAnchor, toAnchor: container.topAnchor)
ssoBar.translatesAutoresizingMaskIntoConstraints = false

constraintEqual(anchor: container.topAnchor, toAnchor: ssoBar.bottomAnchor)
constraintEqual(anchor: container.leftAnchor, toAnchor: self.leftAnchor)
constraintEqual(anchor: container.topAnchor, toAnchor: self.topAnchor)
constraintEqual(anchor: container.rightAnchor, toAnchor: self.rightAnchor)
constraintEqual(anchor: container.bottomAnchor, toAnchor: primaryButton.topAnchor)
container.translatesAutoresizingMaskIntoConstraints = false

constraintEqual(anchor: primaryButton.topAnchor, toAnchor: container.bottomAnchor)
constraintEqual(anchor: primaryButton.leftAnchor, toAnchor: self.leftAnchor)
constraintEqual(anchor: primaryButton.rightAnchor, toAnchor: self.rightAnchor)
constraintEqual(anchor: primaryButton.bottomAnchor, toAnchor: self.bottomAnchor)
primaryButton.translatesAutoresizingMaskIntoConstraints = false

container.alignment = .fill
container.axis = .vertical
container.distribution = .equalSpacing
container.spacing = 10

primaryButton.title = "Log in".i18n(key: "com.auth0.lock.submit.login.title", comment: "Login Button title")
credentialView.identityField.text = identifer
credentialView.identityField.text = identifier
switch identifierAttribute {
case .username:
credentialView.identityField.type = .username
Expand All @@ -85,7 +72,21 @@ class EnterpriseActiveAuthView: UIView, View {
credentialView.identityField.nextField = credentialView.passwordField
credentialView.passwordField.returnKey = .done

container.addArrangedSubview(strutView())
if let domain = domain {
titleView.text = String(
format: "Please enter your corporate credentials at %1$@".i18n(key: "com.auth0.lock.enterprise.sso.message_at", comment: "enter corporate credentials of domain %@{email domain}"),
domain
)
} else {
titleView.text = "Please enter your corporate credentials".i18n(key: "com.auth0.lock.enterprise.sso.message", comment: "enter corporate credentials")
}

titleView.numberOfLines = 4
titleView.textAlignment = .center
titleView.font = regularSystemFont(size: 15)

container.addArrangedSubview(strutView(withHeight: 10))
container.addArrangedSubview(titleView)
container.addArrangedSubview(credentialView)
container.addArrangedSubview(strutView())
}
Expand Down
16 changes: 10 additions & 6 deletions Lock/EnterpriseDomainInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct EnterpriseDomainInteractor: HRDAuthenticatable {
var email: String? = nil
var validEmail: Bool = false
var connection: EnterpriseConnection? = nil
var domain: String? = nil

let connections: [EnterpriseConnection]
let emailValidator: InputValidator = EmailValidator()
Expand All @@ -42,21 +43,24 @@ struct EnterpriseDomainInteractor: HRDAuthenticatable {
}
}

func matchDomain(_ value: String?) -> EnterpriseConnection? {
guard let domain = value?.components(separatedBy: "@").last else { return nil }
func match(domain: String) -> EnterpriseConnection? {
return connections.filter { $0.domains.contains(domain) }.first
}

mutating func updateEmail(_ value: String?) throws {
validEmail = false
connection = nil
self.validEmail = false
self.connection = nil

email = value?.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
if let error = emailValidator.validate(value) {
throw error
}
validEmail = true
connection = matchDomain(value)
self.validEmail = true
self.connection = nil
if let domain = value?.components(separatedBy: "@").last {
self.connection = match(domain: domain)
self.domain = domain
}
}

func login(_ callback: @escaping (OAuth2AuthenticatableError?) -> ()) {
Expand Down
4 changes: 2 additions & 2 deletions Lock/EnterpriseDomainPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class EnterpriseDomainPresenter: Presentable, Loggable {
}

let action = { [weak form] (button: PrimaryButton) in
if let connection = self.interactor.connection, self.options.enterpriseConnectionUsingActiveAuth.contains(connection.name) {
guard self.navigator?.navigate(.enterpriseActiveAuth(connection: connection)) == nil else { return }
if let connection = self.interactor.connection, let domain = self.interactor.domain, self.options.enterpriseConnectionUsingActiveAuth.contains(connection.name) {
guard self.navigator?.navigate(.enterpriseActiveAuth(connection: connection, domain: domain)) == nil else { return }
}

self.messagePresenter?.hideCurrent()
Expand Down
4 changes: 1 addition & 3 deletions Lock/EnterpriseDomainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class EnterpriseDomainView: UIView, View {
let primaryButton = PrimaryButton()
let domainView = EnterpriseSingleInputView()
let container = UIStackView()
let ssoBar = InfoBarView()
let ssoBar = InfoBarView.ssoInfoBar

self.primaryButton = primaryButton
self.form = domainView
Expand All @@ -47,8 +47,6 @@ class EnterpriseDomainView: UIView, View {
self.addSubview(container)
self.addSubview(primaryButton)

ssoBar.title = "SINGLE SIGN-ON ENABLED".i18n(key: "com.auth0.lock.enterprise.sso", comment: "SSO Header")
ssoBar.setIcon("ic_lock")
ssoBar.isHidden = true
self.ssoBar = ssoBar
container.alignment = .fill
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// EnterpriseDomain.swift
// HRDAuthenticatable.swift
//
// Copyright (c) 2016 Auth0 (http://auth0.com)
//
Expand All @@ -25,6 +25,7 @@ import Foundation
protocol HRDAuthenticatable {
var email: String? { get }
var validEmail: Bool { get }
var domain: String? { get }

mutating func updateEmail(_ value: String?) throws

Expand Down
Loading

0 comments on commit 1b86bf0

Please sign in to comment.