Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- override func viewDidLoad() {
- super.viewDidLoad()
- self.navigationController?.isNavigationBarHidden = false
- txtEmail.becomeFirstResponder()
- //bLogin.backgroundColor = UIColor.init(red: 0x00/255, green: 0x9f/255, blue: 0xf9/255, alpha: 1.0)
- txtPassword.editConfig(image: "Password Filled_20.png", position: true)
- txtEmail.editConfig(image: "Message Filled_20.png", position: true)
- registerKeyboardListeners()
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- originConstraintConstant = bottomConstraint.constant
- }
- @IBAction func asd(_ sender: Any) {
- }
- override func viewDidDisappear(_ animated: Bool) {
- super.viewDidDisappear(animated)
- deregisterKeyboardListeners()
- }
- func registerKeyboardListeners() {
- NotificationCenter.default.addObserver(self, selector: #selector(Tela2_Login.keyboardWillShow(notification:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(Tela2_Login.keyboardWillHide(notification:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
- }
- func deregisterKeyboardListeners(){
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: nil)
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil)
- }
- func keyboardWillShow(notification: Notification) {
- let userInfo = notification.userInfo
- let keyboardSize = userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue
- bottomConstraint.constant = keyboardSize.cgRectValue.height + 11
- }
- func keyboardWillHide(notification: Notification) {
- bottomConstraint.constant = originConstraintConstant
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
- self.view.endEditing(true)
- }
- @IBAction func bLogin(_ sender: UIButtonRounded) {
- if (txtEmail.text == "") || (txtPassword.text == "") {
- let alert = UIAlertController(title: "Atenção", message: "Insira todos os campos!", preferredStyle: UIAlertControllerStyle.alert)
- alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
- self.present(alert, animated: true, completion: nil)
- } else {
- if let email = txtEmail.text , let pass = txtPassword.text {
- FIRAuth.auth()?.signIn(withEmail: email, password: pass, completion: {(user, error) in
- if user != nil {
- if let user = FIRAuth.auth()?.currentUser {
- self.databaseRef.child("Clients").child(user.uid).child("levelAcess").observe(.value, with: { (snapshot) in
- let level = snapshot.value as? String
- UserDefaults.standard.set(level, forKey: "levelAcess")
- UserDefaults.standard.synchronize()
- if level == "1" {
- self.setupProfileUser()
- } else {
- self.setupProfileAdm()
- }
- })
- }
- } else {
- let alert = UIAlertController(title: "Login Incorreto", message: "Usuário inexistente. Verifique se o email e senha estão corretos!", preferredStyle: UIAlertControllerStyle.alert)
- alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
- self.present(alert, animated: true, completion: nil)
- }
- })
- }
- }
- }
- @IBAction func bLoginFB(_ sender: UIButtonBorder) {
- appDelegate.handleLogout()
- }
- // MARK: - functions login
- func setupProfileUser(){
- if FIRAuth.auth()?.currentUser?.uid == nil{
- appDelegate.handleLogout()
- } else {
- let uid = FIRAuth.auth()?.currentUser?.uid
- // imgView.layer.cornerRadius = imgView.frame.size.width/2
- // imgView.clipsToBounds = true //carregar foto de perfil aqui
- databaseRef.child("Clients").child(uid!).observeSingleEvent(of: .value, with: { (snapshot) in
- if let dict = snapshot.value as? [String: AnyObject]{
- //self.algumlabel.text = dict["username"] as? String carregar id e dados aqui
- if let profileImageURL = dict["pic"] as? String{
- let url = URL(string: profileImageURL)
- URLSession.shared.dataTask(with: url!, completionHandler: {(data,response,error)in
- if error != nil{
- print(error!)
- return
- }
- DispatchQueue.main.async {
- //self.imgView?.image = UIImage(data: data!) //carregar img aqui
- }
- }).resume()
- }
- }
- })
- self.appDelegate.handleLogin()
- }
- }
- func setupProfileAdm(){
- if FIRAuth.auth()?.currentUser?.uid == nil{
- appDelegate.handleLogout()
- } else {
- // let uid = FIRAuth.auth()?.currentUser?.uid
- // // imgView.layer.cornerRadius = imgView.frame.size.width/2
- // // imgView.clipsToBounds = true //carregar foto de perfil aqui
- //
- // databaseRef.child("Clients").child(uid!).observeSingleEvent(of: .value, with: { (snapshot) in
- // if let dict = snapshot.value as? [String: AnyObject]{
- // //self.algumlabel.text = dict["username"] as? String carregar id e dados aqui
- // if let profileImageURL = dict["pic"] as? String{
- // let url = URL(string: profileImageURL)
- // URLSession.shared.dataTask(with: url!, completionHandler: {(data,response,error)in
- // if error != nil{
- // print(error!)
- // return
- // }
- // DispatchQueue.main.async {
- // //self.imgView?.image = UIImage(data: data!) //carregar img aqui
- // }
- // }).resume()
- // }
- // }
- // })
- self.appDelegate.handleLogin()
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement