Skip to content

Commit

Permalink
Merge pull request #529 from pennlabs/stale-request-login-fix
Browse files Browse the repository at this point in the history
FIX stale login request finally
  • Loading branch information
JHawk0224 authored Apr 6, 2024
2 parents d547528 + 5fe19f1 commit fa19a9f
Showing 1 changed file with 25 additions and 0 deletions.
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

0 comments on commit fa19a9f

Please sign in to comment.