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

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
.bind(to: self.pinLabel.rx.isVisible)
.addDisposableTo(self.disposeBag)
passwordField.rx.text
.map({!$0!.isEmpty})
.shareReplay(1)
.bind(to: okButton.rx.isEnabled)
.addDisposableTo(self.disposeBag)
self.viewModel.observableState
.observeOn(MainScheduler.instance)
.subscribe(onNext: { [weak self] (state) in
......@@ -115,3 +109,4 @@ class LinkNewDeviceViewController: UIViewController, StoryboardBased, ViewModelB
self.explanationMessage.text = self.viewModel.explanationMessage
}
}
......@@ -170,6 +170,10 @@ class CreateAccountViewModel: Stateable, ViewModel {
lazy var passwordValidationState: Observable<PasswordValidationState> = {
return Observable.combineLatest(self.password.asObservable(), self.confirmPassword.asObservable())
{ (password: String, confirmPassword: String) -> PasswordValidationState in
if password.isEmpty && confirmPassword.isEmpty {
return .validated
}
if password.characters.count < 6 {
return .error(message: L10n.Createaccount.passwordCharactersNumberError)
}
......@@ -186,17 +190,19 @@ class CreateAccountViewModel: Stateable, ViewModel {
return Observable.combineLatest(self.passwordValidationState.asObservable(),
self.usernameValidationState.asObservable(),
self.registerUsername.asObservable(),
self.username.asObservable(),
self.createState,
resultSelector:
{ ( passwordValidationState: PasswordValidationState,
usernameValidationState: UsernameValidationState,
registerUsername: Bool,
username: String,
creationState: AccountCreationState) -> Bool in
var canAsk = true
if registerUsername {
canAsk = canAsk && usernameValidationState.isAvailable
canAsk = canAsk && usernameValidationState.isAvailable && !username.isEmpty
}
canAsk = canAsk && passwordValidationState.isValidated
......@@ -220,13 +226,10 @@ class CreateAccountViewModel: Stateable, ViewModel {
switch status {
case .lookingUp:
self?.usernameValidationState.value = .lookingForAvailibility(message: L10n.Createaccount.lookingForUsernameAvailability)
break
case .invalid:
self?.usernameValidationState.value = .invalid(message: L10n.Createaccount.invalidUsername)
break
case .alreadyTaken:
self?.usernameValidationState.value = .unavailable(message: L10n.Createaccount.usernameAlreadyTaken)
break
default:
self?.usernameValidationState.value = .available
}
......@@ -277,3 +280,4 @@ class CreateAccountViewModel: Stateable, ViewModel {
password: self.password.value)
}
}
......@@ -35,13 +35,9 @@ class LinkDeviceViewModel: Stateable, ViewModel {
}()
lazy var linkButtonEnabledState: Observable<Bool> = {
return Observable.combineLatest(self.password.asObservable(),
self.pin.asObservable()) {(password, pin) -> Bool in
if !password.isEmpty && !pin.isEmpty {
return true
}
return false
}
return self.pin.asObservable().map({ pin in
return !pin.isEmpty
})
}()
let pin = Variable<String>("")
......@@ -76,3 +72,4 @@ class LinkDeviceViewModel: Stateable, ViewModel {
password: self.password.value)
}
}
Markdown is supported
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