Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import UIKit
  2. import Base
  3. import ReSwift
  4.  
  5. class LoginViewController: UIViewController {
  6.  
  7. @IBOutlet var usernameField: UITextField!
  8. @IBOutlet var passwordField: UITextField!
  9.  
  10. override func viewDidLoad() {
  11. super.viewDidLoad()
  12.  
  13. store.subscribe(self) {state in
  14. state.usersState
  15. }
  16. }
  17.  
  18. @IBAction func onLoginButton(_ sender: Any) {
  19. store.dispatch(AuthenticatePassword(username: usernameField.text!, password: passwordField.text!))
  20. }
  21.  
  22. @IBAction func onTwitterButton(_ sender: Any) {
  23. store.dispatch(AuthenticateTwitter())
  24. }
  25.  
  26. @IBAction func onFacebookButton(_ sender: Any) {
  27. store.dispatch(AuthenticateFacebook(from: self))
  28. }
  29. }
  30.  
  31. // MARK: - State management
  32. extension LoginViewController: StoreSubscriber {
  33. func newState(state: UsersState) {
  34. if let error = state.authState.error {
  35. presentError(error: error.type, viewController: self, completion: nil)
  36. }
  37. if let _ = state.getCurrentUser {
  38. self.dismiss(animated: true, completion: nil)
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement