Commit fea7a91b authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Kateryna Kostiuk
Browse files

accounts: allow passwordless account creation and device linking



- Allows the user to create an account, link to an existing
  account, and generate account link PINs  without supplying a
  password.

Change-Id: I41216d55bb44bab5f92fd096d483f639502e4a42
Reviewed-by: Kateryna Kostiuk's avatarKateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
parent dc09b926
...@@ -62,12 +62,6 @@ class LinkNewDeviceViewController: UIViewController, StoryboardBased, ViewModelB ...@@ -62,12 +62,6 @@ class LinkNewDeviceViewController: UIViewController, StoryboardBased, ViewModelB
.bind(to: self.pinLabel.rx.isVisible) .bind(to: self.pinLabel.rx.isVisible)
.addDisposableTo(self.disposeBag) .addDisposableTo(self.disposeBag)
passwordField.rx.text
.map({!$0!.isEmpty})
.shareReplay(1)
.bind(to: okButton.rx.isEnabled)
.addDisposableTo(self.disposeBag)
self.viewModel.observableState self.viewModel.observableState
.observeOn(MainScheduler.instance) .observeOn(MainScheduler.instance)
.subscribe(onNext: { [weak self] (state) in .subscribe(onNext: { [weak self] (state) in
...@@ -115,3 +109,4 @@ class LinkNewDeviceViewController: UIViewController, StoryboardBased, ViewModelB ...@@ -115,3 +109,4 @@ class LinkNewDeviceViewController: UIViewController, StoryboardBased, ViewModelB
self.explanationMessage.text = self.viewModel.explanationMessage self.explanationMessage.text = self.viewModel.explanationMessage
} }
} }
...@@ -170,6 +170,10 @@ class CreateAccountViewModel: Stateable, ViewModel { ...@@ -170,6 +170,10 @@ class CreateAccountViewModel: Stateable, ViewModel {
lazy var passwordValidationState: Observable<PasswordValidationState> = { lazy var passwordValidationState: Observable<PasswordValidationState> = {
return Observable.combineLatest(self.password.asObservable(), self.confirmPassword.asObservable()) return Observable.combineLatest(self.password.asObservable(), self.confirmPassword.asObservable())
{ (password: String, confirmPassword: String) -> PasswordValidationState in { (password: String, confirmPassword: String) -> PasswordValidationState in
if password.isEmpty && confirmPassword.isEmpty {
return .validated
}
if password.characters.count < 6 { if password.characters.count < 6 {
return .error(message: L10n.Createaccount.passwordCharactersNumberError) return .error(message: L10n.Createaccount.passwordCharactersNumberError)
} }
...@@ -186,17 +190,19 @@ class CreateAccountViewModel: Stateable, ViewModel { ...@@ -186,17 +190,19 @@ class CreateAccountViewModel: Stateable, ViewModel {
return Observable.combineLatest(self.passwordValidationState.asObservable(), return Observable.combineLatest(self.passwordValidationState.asObservable(),
self.usernameValidationState.asObservable(), self.usernameValidationState.asObservable(),
self.registerUsername.asObservable(), self.registerUsername.asObservable(),
self.username.asObservable(),
self.createState, self.createState,
resultSelector: resultSelector:
{ ( passwordValidationState: PasswordValidationState, { ( passwordValidationState: PasswordValidationState,
usernameValidationState: UsernameValidationState, usernameValidationState: UsernameValidationState,
registerUsername: Bool, registerUsername: Bool,
username: String,
creationState: AccountCreationState) -> Bool in creationState: AccountCreationState) -> Bool in
var canAsk = true var canAsk = true
if registerUsername { if registerUsername {
canAsk = canAsk && usernameValidationState.isAvailable canAsk = canAsk && usernameValidationState.isAvailable && !username.isEmpty
} }
canAsk = canAsk && passwordValidationState.isValidated canAsk = canAsk && passwordValidationState.isValidated
...@@ -220,13 +226,10 @@ class CreateAccountViewModel: Stateable, ViewModel { ...@@ -220,13 +226,10 @@ class CreateAccountViewModel: Stateable, ViewModel {
switch status { switch status {
case .lookingUp: case .lookingUp:
self?.usernameValidationState.value = .lookingForAvailibility(message: L10n.Createaccount.lookingForUsernameAvailability) self?.usernameValidationState.value = .lookingForAvailibility(message: L10n.Createaccount.lookingForUsernameAvailability)
break
case .invalid: case .invalid:
self?.usernameValidationState.value = .invalid(message: L10n.Createaccount.invalidUsername) self?.usernameValidationState.value = .invalid(message: L10n.Createaccount.invalidUsername)
break
case .alreadyTaken: case .alreadyTaken:
self?.usernameValidationState.value = .unavailable(message: L10n.Createaccount.usernameAlreadyTaken) self?.usernameValidationState.value = .unavailable(message: L10n.Createaccount.usernameAlreadyTaken)
break
default: default:
self?.usernameValidationState.value = .available self?.usernameValidationState.value = .available
} }
...@@ -277,3 +280,4 @@ class CreateAccountViewModel: Stateable, ViewModel { ...@@ -277,3 +280,4 @@ class CreateAccountViewModel: Stateable, ViewModel {
password: self.password.value) password: self.password.value)
} }
} }
...@@ -35,13 +35,9 @@ class LinkDeviceViewModel: Stateable, ViewModel { ...@@ -35,13 +35,9 @@ class LinkDeviceViewModel: Stateable, ViewModel {
}() }()
lazy var linkButtonEnabledState: Observable<Bool> = { lazy var linkButtonEnabledState: Observable<Bool> = {
return Observable.combineLatest(self.password.asObservable(), return self.pin.asObservable().map({ pin in
self.pin.asObservable()) {(password, pin) -> Bool in return !pin.isEmpty
if !password.isEmpty && !pin.isEmpty { })
return true
}
return false
}
}() }()
let pin = Variable<String>("") let pin = Variable<String>("")
...@@ -76,3 +72,4 @@ class LinkDeviceViewModel: Stateable, ViewModel { ...@@ -76,3 +72,4 @@ class LinkDeviceViewModel: Stateable, ViewModel {
password: self.password.value) password: self.password.value)
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment