Skip to content

Commit

Permalink
EnterpriseConnection style optional
Browse files Browse the repository at this point in the history
Customised login/signup titles
  • Loading branch information
cocojoe committed Nov 24, 2016
1 parent 5d91c47 commit 93057a5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Lock/AuthCollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func oauth2Buttons(forConnections connections: [OAuth2Connection], customStyle:
return connections.map { connection -> AuthButton in
let style = customStyle[connection.name] ?? connection.style
let button = AuthButton(size: .Big)
button.title = login ? style.localizedLoginTitle.uppercaseString : style.localizedSignUpTitle.uppercaseString
button.title = login ? style.localizedLoginTitle().uppercaseString : style.localizedSignUpTitle().uppercaseString
button.normalColor = style.normalColor
button.highlightedColor = style.highlightedColor
button.titleColor = style.foregroundColor
Expand Down
10 changes: 5 additions & 5 deletions Lock/AuthStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ import UIKit
public class AuthStyle {

/// Name that will be used for titles. e.g. 'Login with Auth0'
public var name: String
let name: String
let image: LazyImage
let foregroundColor: UIColor
let normalColor: UIColor
let highlightedColor: UIColor

var localizedLoginTitle: String {
func localizedLoginTitle(title: String? = nil) -> String {
let format = "Log in with %@".i18n(key: "com.auth0.lock.strategy.login.title", comment: "Log in action format")
return String(format: format, self.name)
return String(format: format, title ?? self.name)
}

var localizedSignUpTitle: String {
func localizedSignUpTitle(title: String? = nil) -> String {
let format = "Sign up with %@".i18n(key: "com.auth0.lock.strategy.signup.title", comment: "Sign up action format")
return String(format: format, self.name)
return String(format: format, title ?? self.name)
}

/**
Expand Down
6 changes: 6 additions & 0 deletions Lock/Connections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,10 @@ public struct EnterpriseConnection : OAuth2Connection {
public let name: String
public let domains: [String]
public let style: AuthStyle

init(name: String, domains: [String], style: AuthStyle? = nil) {
self.name = name
self.domains = domains
self.style = style ?? AuthStyle(name: name)
}
}
3 changes: 1 addition & 2 deletions Lock/EnterpriseDomainPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ class EnterpriseDomainPresenter: Presentable, Loggable {
func EnterpriseButton(forConnections connections: [EnterpriseConnection], customStyle: [String: AuthStyle], isLogin login: Bool, onAction: () -> () ) -> AuthButton? {
guard let connection = connections.first where connections.count == 1 else { return nil }
let style = customStyle[connection.name] ?? connection.style
style.name = connection.domains.first!
let button = AuthButton(size: .Big)
button.title = login ? style.localizedLoginTitle.uppercaseString : style.localizedSignUpTitle.uppercaseString
button.title = style.localizedLoginTitle(connection.domains.first).uppercaseString
button.normalColor = style.normalColor
button.highlightedColor = style.highlightedColor
button.titleColor = style.foregroundColor
Expand Down
6 changes: 3 additions & 3 deletions LockTests/Models/AuthStyleSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ class AuthStyleSpec: QuickSpec {

it("should provide login title") {
let strategy = AuthStyle(name: "facebook")
expect(strategy.localizedLoginTitle) == "Log in with facebook"
expect(strategy.localizedLoginTitle()) == "Log in with facebook"
}

it("should provide signup title") {
let strategy = AuthStyle(name: "facebook")
expect(strategy.localizedSignUpTitle) == "Sign up with facebook"
expect(strategy.localizedSignUpTitle()) == "Sign up with facebook"
}

}
Expand Down Expand Up @@ -217,4 +217,4 @@ extension AuthStyle: Equatable, CustomStringConvertible {

public func ==(lhs: AuthStyle, rhs: AuthStyle) -> Bool {
return lhs.name == rhs.name && lhs.normalColor == rhs.normalColor && lhs.highlightedColor == rhs.highlightedColor && lhs.foregroundColor == rhs.foregroundColor && lhs.image.name == rhs.image.name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class EnterpriseActiveAuthPresenterSpec: QuickSpec {
options = LockOptions()
user = User()
messagePresenter = MockMessagePresenter()
connection = EnterpriseConnection(name: "TestAD", domains: ["test.com"], style: AuthStyle(name: "ad"))
connection = EnterpriseConnection(name: "TestAD", domains: ["test.com"])
interactor = EnterpriseActiveAuthInteractor(connection: connection, authentication: authentication, user: user, options: options, callback: {_ in})
presenter = EnterpriseActiveAuthPresenter(interactor: interactor)
presenter.messagePresenter = messagePresenter
Expand Down

0 comments on commit 93057a5

Please sign in to comment.