Advertisement
Guest User

constraint

a guest
Mar 7th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.14 KB | None | 0 0
  1. override func viewDidLoad() {
  2. super.viewDidLoad()
  3. self.navigationController?.isNavigationBarHidden = false
  4. txtEmail.becomeFirstResponder()
  5. //bLogin.backgroundColor = UIColor.init(red: 0x00/255, green: 0x9f/255, blue: 0xf9/255, alpha: 1.0)
  6.  
  7. txtPassword.editConfig(image: "Password Filled_20.png", position: true)
  8. txtEmail.editConfig(image: "Message Filled_20.png", position: true)
  9. registerKeyboardListeners()
  10. }
  11. override func viewWillAppear(_ animated: Bool) {
  12. super.viewWillAppear(animated)
  13. originConstraintConstant = bottomConstraint.constant
  14. }
  15.  
  16. @IBAction func asd(_ sender: Any) {
  17.  
  18.  
  19. }
  20.  
  21.  
  22. override func viewDidDisappear(_ animated: Bool) {
  23. super.viewDidDisappear(animated)
  24. deregisterKeyboardListeners()
  25. }
  26.  
  27. func registerKeyboardListeners() {
  28. NotificationCenter.default.addObserver(self, selector: #selector(Tela2_Login.keyboardWillShow(notification:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
  29. NotificationCenter.default.addObserver(self, selector: #selector(Tela2_Login.keyboardWillHide(notification:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
  30. }
  31.  
  32. func deregisterKeyboardListeners(){
  33. NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: nil)
  34. NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil)
  35. }
  36.  
  37. func keyboardWillShow(notification: Notification) {
  38. let userInfo = notification.userInfo
  39. let keyboardSize = userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue
  40. bottomConstraint.constant = keyboardSize.cgRectValue.height + 11
  41. }
  42.  
  43. func keyboardWillHide(notification: Notification) {
  44. bottomConstraint.constant = originConstraintConstant
  45. }
  46.  
  47. override func didReceiveMemoryWarning() {
  48. super.didReceiveMemoryWarning()
  49. // Dispose of any resources that can be recreated.
  50. }
  51.  
  52. override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  53. self.view.endEditing(true)
  54. }
  55.  
  56. @IBAction func bLogin(_ sender: UIButtonRounded) {
  57. if (txtEmail.text == "") || (txtPassword.text == "") {
  58. let alert = UIAlertController(title: "Atenção", message: "Insira todos os campos!", preferredStyle: UIAlertControllerStyle.alert)
  59. alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
  60. self.present(alert, animated: true, completion: nil)
  61. } else {
  62. if let email = txtEmail.text , let pass = txtPassword.text {
  63. FIRAuth.auth()?.signIn(withEmail: email, password: pass, completion: {(user, error) in
  64. if user != nil {
  65. if let user = FIRAuth.auth()?.currentUser {
  66. self.databaseRef.child("Clients").child(user.uid).child("levelAcess").observe(.value, with: { (snapshot) in
  67. let level = snapshot.value as? String
  68. UserDefaults.standard.set(level, forKey: "levelAcess")
  69. UserDefaults.standard.synchronize()
  70. if level == "1" {
  71. self.setupProfileUser()
  72. } else {
  73. self.setupProfileAdm()
  74. }
  75.  
  76. })
  77. }
  78. } else {
  79. let alert = UIAlertController(title: "Login Incorreto", message: "Usuário inexistente. Verifique se o email e senha estão corretos!", preferredStyle: UIAlertControllerStyle.alert)
  80. alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
  81. self.present(alert, animated: true, completion: nil)
  82. }
  83. })
  84. }
  85. }
  86.  
  87. }
  88.  
  89.  
  90. @IBAction func bLoginFB(_ sender: UIButtonBorder) {
  91. appDelegate.handleLogout()
  92. }
  93.  
  94.  
  95. // MARK: - functions login
  96.  
  97. func setupProfileUser(){
  98. if FIRAuth.auth()?.currentUser?.uid == nil{
  99. appDelegate.handleLogout()
  100. } else {
  101.  
  102. let uid = FIRAuth.auth()?.currentUser?.uid
  103. // imgView.layer.cornerRadius = imgView.frame.size.width/2
  104. // imgView.clipsToBounds = true //carregar foto de perfil aqui
  105.  
  106. databaseRef.child("Clients").child(uid!).observeSingleEvent(of: .value, with: { (snapshot) in
  107. if let dict = snapshot.value as? [String: AnyObject]{
  108. //self.algumlabel.text = dict["username"] as? String carregar id e dados aqui
  109. if let profileImageURL = dict["pic"] as? String{
  110. let url = URL(string: profileImageURL)
  111. URLSession.shared.dataTask(with: url!, completionHandler: {(data,response,error)in
  112. if error != nil{
  113. print(error!)
  114. return
  115. }
  116. DispatchQueue.main.async {
  117. //self.imgView?.image = UIImage(data: data!) //carregar img aqui
  118. }
  119. }).resume()
  120. }
  121. }
  122. })
  123. self.appDelegate.handleLogin()
  124. }
  125. }
  126.  
  127. func setupProfileAdm(){
  128. if FIRAuth.auth()?.currentUser?.uid == nil{
  129. appDelegate.handleLogout()
  130. } else {
  131.  
  132. // let uid = FIRAuth.auth()?.currentUser?.uid
  133. // // imgView.layer.cornerRadius = imgView.frame.size.width/2
  134. // // imgView.clipsToBounds = true //carregar foto de perfil aqui
  135. //
  136. // databaseRef.child("Clients").child(uid!).observeSingleEvent(of: .value, with: { (snapshot) in
  137. // if let dict = snapshot.value as? [String: AnyObject]{
  138. // //self.algumlabel.text = dict["username"] as? String carregar id e dados aqui
  139. // if let profileImageURL = dict["pic"] as? String{
  140. // let url = URL(string: profileImageURL)
  141. // URLSession.shared.dataTask(with: url!, completionHandler: {(data,response,error)in
  142. // if error != nil{
  143. // print(error!)
  144. // return
  145. // }
  146. // DispatchQueue.main.async {
  147. // //self.imgView?.image = UIImage(data: data!) //carregar img aqui
  148. // }
  149. // }).resume()
  150. // }
  151. // }
  152. // })
  153. self.appDelegate.handleLogin()
  154. }
  155. }
  156.  
  157.  
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement