This repository has been archived on 2026-05-26. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
avh-plan-ios/AvH Plan/LoginViewController.swift
T

42 lines
1.2 KiB
Swift
Raw Normal View History

2019-09-21 14:04:49 +02:00
//
// LoginViewController.swift
// AvH Plan
//
// Created by Deniz Duezgoeren on 21.09.19.
// Copyright © 2019 Deniz Duezgoeren. All rights reserved.
//
import UIKit
import WebKit
class LoginViewController: UIViewController, WKNavigationDelegate {
@IBOutlet weak var webView: WKWebView!
let prefs = UserDefaults.standard
override func viewDidLoad() {
super.viewDidLoad()
let request = URLRequest(url: URL(string: "https://307.joomla.schule.bremen.de/index.php/component/users/#top")!)
self.webView.load(request)
self.webView.navigationDelegate = self
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
self.webView.configuration.websiteDataStore.httpCookieStore.getAllCookies { cookies in
for cookie in cookies {
if cookie.name == "joomla_user_state" && cookie.value == "logged_in" {
self.success()
}
}
}
}
private func success() {
self.prefs.set(true, forKey: "logged_in")
if let s = storyboard?.instantiateViewController(withIdentifier: "FirstTime") as? UINavigationController {
self.present(s, animated: true)
}
}
}