Failed to log in by calling an unconfirmed segment?

I have an application in which a user can log in and log out (this is processed through a Parse server hosted using heroku using the Parse framework).

To log in, the user enters credentials, and if the server checks them, segue moves them to another view manager. The output signs the user out of the application and goes to the login screen. They work great.

If the initial login credentials are incorrect, a warning is displayed in which the user must try again and the user does not log in (obviously) and remains on the login screen.

There is a problem if the user logs in, logs out, and then enters the wrong credentials (in this order without closing the simulator). Incorrect credentials prompt; clicking "OK" closes the warning, the user is not logged in, but the view has moved to the exit screen (where the exit button ... this should be available only to registered users). No segue segue exists (neither encoded nor on the bulletin board) that takes the user from the entrance directly to the exit screen.

No action works, since many of them require a user ID, and there is no one, since none of them are logged in. I have no idea why the wrong login will move the VC this way, since there is no segue that can do this. There is one that makes this movement in the opposite direction (upon exiting the system), but not in this direction.

Does anyone have any ideas? Below is the corresponding registration code.

@IBAction func signInTapped(_ sender: UIButton) { UIApplication.shared.beginIgnoringInteractionEvents() PFUser.logInWithUsername(inBackground: userNameTextField.text!, password: passwordTextField.text!, block: { (user, error) in if user != nil{ self.performSegue(withIdentifier: "signInSegue", sender: self)//if the sign in works } else{ if let errorString = (error! as NSError).userInfo["error"] as? String{ let errorMessage = errorString self.displayAlert("Failed login", message: errorMessage)//this is the code run when the login fails, yet it somehow can sometimes segue to the other viewcontroller } } }) } 

Here is a step-by-step diagram of what is happening. The user starts from the login page and enters their credentials This selects the user (now logged in) in the <code> tabbarViewController </code> Then they go to another tab and the exit button appears. Pressing the exit button leads to a warning, by clicking yes, select the user (now log out) to the initial screen The user is now on the login screen. Entering incorrect information triggers a warning A warning appears. Pressing yes closes the warning, which should leave the user on the login screen. However, the re-exit screen appears again ... it is not encoded or set manually in the storyboard

  • The user runs on the login page and enters their credentials
  • This causes the user (now logged in) to go to tabbarViewController
  • Then they go to another tab and the exit button appears.
  • Pressing the exit button results in a warning, which, when pressed, gives the user (now logged out) a transition to the initial screen.
  • The user is now on the login screen. Entering incorrect information triggers a warning
  • A warning will appear. Clicking β€œyes” closes the warning, which should leave the user on the login screen. However, the re-exit screen appears again ... it is not encoded or set manually in the storyboard.

Random things that I think may make a difference: The initial session called on viewDidAppear first VC (login screen) after the application is turned on. It checks if the user is registered through

 if PFUser.current().username? != nil { //perform segue } 

This segue brings them to the map section of the tab bar (NOT on the exit page, as this happens with the problem).

EDIT: after β€œsegue” appears on the logout screen, the logon screen falls (as literally, it falls down the screen until it sees it, and the logout screen will be displayed when it is not like any segment in Appendix). In addition, when this transition occurs, only the viewDidAppear code is viewDidAppear , not the viewDidLoad code.

EDIT 2: I think the problem is with the hierarchy of views. Here is the code for the login function:

 PFUser.logInWithUsername(inBackground: userNameTextField.text!, password: passwordTextField.text!, block: { (user, error) in if user?.username != nil{ self.performSegue(withIdentifier: "signInSegue", sender: self) } else{ //if everything in this code block is commented, the issue does not occur if let errorString = (error! as NSError).userInfo["error"] as? String{ let errorMessage = errorString self.displayAlert("Failed login", message: errorMessage) } } }) 

If I comment on everything in the else part of the if statement, the problem does not occur. What I think is happening is that a warning is displayed, and clicking β€œok” closes the warning and sends the application back to the top (maybe I'm wrong in what I call) viewController, which somehow produces VC, I think a good way to fix this would be to add as self.present(homescreenVC) or something like this to the else code, but I don't know how to do it.

+5
source share
1 answer
 @IBAction func signInTapped(_ sender: UIButton) { UIApplication.shared.beginIgnoringInteractionEvents() PFUser.logInWithUsername(inBackground: userNameTextField.text!, password: passwordTextField.text!, block: { (user, error) in if error != nil { if let errorString = (error! as NSError).userInfo["error"] as? String{ let errorMessage = errorString self.displayAlert("Failed login", message: errorMessage) } } else { self.performSegue(withIdentifier: "signInSegue", sender: self) } }) } 
0
source

Source: https://habr.com/ru/post/1262265/


All Articles