Move the login logic to the model and add redirection on success