Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. //
  2. // ViewResults.swift
  3. // QuestionnaireApp
  4. //
  5. // Created by Adnan Hussain on 20/03/2019.
  6. // Copyright © 2019 Adnan Hussain. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import CoreData
  11.  
  12. class ViewResults: UIViewController {
  13.  
  14. //links username text field
  15. @IBOutlet weak var usernameTextField: UITextField!
  16. //links password text field
  17. @IBOutlet weak var passwordTextField: UITextField!
  18. //links "ok" button
  19. @IBOutlet weak var okBtn: UIButton!
  20.  
  21. override func viewDidLoad() {
  22. super.viewDidLoad()
  23. }
  24.  
  25. @IBAction func okButton(_ sender: Any) {
  26.  
  27. //user can only view results if the username = admin and password = hello
  28. if usernameTextField.text == "admin" && passwordTextField.text == "hello"
  29. {
  30. //alert pop up if login successful
  31. let alertController = UIAlertController(title: "Login Successful!", message:
  32. "Press Ok to view the results", preferredStyle: .alert)
  33. //takes user to results page if login is successful and user presses OK in alert
  34. alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in self.performSegue(withIdentifier: "results", sender: self) } ))
  35.  
  36.  
  37. self.present(alertController, animated: true, completion: nil)
  38. //debugging code outputs to console so I can check if login successful
  39. NSLog("Login successful")
  40. }
  41. else
  42. {
  43. //debugging code outputs to console so I can check if login failed
  44. NSLog("Login failed")
  45. //alert pop up if login fails
  46. let alertController = UIAlertController(title: "Incorrect Password!", message:
  47. "Please enter the correct password", preferredStyle: .alert)
  48. alertController.addAction(UIAlertAction(title: "Try Again", style: .default))
  49.  
  50. self.present(alertController, animated: true, completion: nil)
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement