Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX stale login request finally #529

Merged
merged 1 commit into from
Apr 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions PennMobile/Auth/PennLoginController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import PennMobileShared
class PennLoginController: UIViewController, WKUIDelegate, WKNavigationDelegate {

final private let loginURL = "https://weblogin.pennkey.upenn.edu/login"
final private let loginScreen = "https://weblogin.pennkey.upenn.edu/idp/profile/SAML2/Redirect/SSO?execution=e1"
open var urlStr: String {
return "https://weblogin.pennkey.upenn.edu/services/"
}
Expand All @@ -20,6 +21,7 @@ class PennLoginController: UIViewController, WKUIDelegate, WKNavigationDelegate
private var password: String?

final private var webView: WKWebView!
private var activityIndicator: UIActivityIndicatorView!

var shouldAutoNavigate: Bool = true
var shouldLoadCookies: Bool {
Expand Down Expand Up @@ -54,6 +56,18 @@ class PennLoginController: UIViewController, WKUIDelegate, WKNavigationDelegate
let myURL = URL(string: self.urlStr)
let myRequest = URLRequest(url: myURL!)
self.webView.load(myRequest)

activityIndicator = UIActivityIndicatorView(style: .large)
activityIndicator.hidesWhenStopped = true
activityIndicator.isHidden = true
self.view.addSubview(activityIndicator)
self.view.bringSubviewToFront(activityIndicator)
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
activityIndicator.center = view.center
view.bringSubviewToFront(activityIndicator)
}

func webView(
Expand All @@ -65,6 +79,13 @@ class PennLoginController: UIViewController, WKUIDelegate, WKNavigationDelegate
decisionHandler(.allow)
return
}

if navigationAction.navigationType == .formSubmitted,
webView.url?.absoluteString.contains(loginScreen) == true {
activityIndicator.startAnimating()
activityIndicator.isHidden = false
view.isUserInteractionEnabled = false
}

webView.configuration.websiteDataStore.httpCookieStore.getAllCookies { (cookies) in
cookies.forEach({ (cookie) in
Expand Down Expand Up @@ -104,6 +125,10 @@ class PennLoginController: UIViewController, WKUIDelegate, WKNavigationDelegate
decisionHandler(.allow)
return
}

activityIndicator.stopAnimating()
activityIndicator.isHidden = true
view.isUserInteractionEnabled = true

if self.isSuccessfulRedirect(url: url.absoluteString, hasReferer: true), response.statusCode == 200 {
self.handleSuccessfulNavigation(webView) { (policy) in
Expand Down