|
@@ -86,6 +86,47 @@ class LoginHandler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+class FetchHandler {
|
|
|
+ static let sharedInstance = FetchHandler()
|
|
|
+
|
|
|
+ func matches(url: String) -> Bool {
|
|
|
+ do {
|
|
|
+ return try url.matches(of: Regex(#"(^\[\]$|param":"|"workRests"|<tr>|DOCTYPE|in\?username=|requestParams|\"newmessage\"|Sorry, Page Not Found|北师大实验中学--登录|404 Not Found|502 Bad Gateway)"#)).count != 0
|
|
|
+ } catch {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func getUrl(url: String) -> String {
|
|
|
+ var ret: String = url
|
|
|
+ print("PRE: \(ret)")
|
|
|
+ ret = ret
|
|
|
+ .replacing("dd.sdsz.com.cn", with: "debug.sdsz.icu:81")
|
|
|
+ .replacing(/^http:/, with: "https:")
|
|
|
+ .replacing("service=http%3A%2F%2Fdebug.sdsz.icu:81", with: "service=http%3A%2F%2Fdd.sdsz.com.cn")
|
|
|
+ print("AFTER: \(ret)")
|
|
|
+ return ret
|
|
|
+ }
|
|
|
+
|
|
|
+ func workFetch(url: String, action: @escaping (_: String) -> Void) {
|
|
|
+ if matches(url: url) {
|
|
|
+ action(url)
|
|
|
+ } else {
|
|
|
+ AF.request(getUrl(url: url), method: .get, parameters: nil, encoding: URLEncoding.default, headers: nil).responseString { res in
|
|
|
+ print(res)
|
|
|
+ if let resv = res.value {
|
|
|
+ self.workFetch(url: resv, action: action)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func fetchAny(url: String, action: @escaping (_: String) -> Void) {
|
|
|
+ let urlFull = "https://debug.sdsz.icu:81/\(url)"
|
|
|
+ workFetch(url: urlFull, action: action)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func doLogin(user: String, password: String, action: @escaping (_: Int) -> Void) {
|
|
|
LoginHandler().fetchLoginCookie { (cookie: String) in
|
|
|
let login = Login(user: user, pwd: password, cook: cookie)
|
|
@@ -101,8 +142,13 @@ func doLogin(user: String, password: String, action: @escaping (_: Int) -> Void)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+struct DecodableType: Decodable { let url: String }
|
|
|
+
|
|
|
func getUserInfo(userInfo: inout UserInfo) {
|
|
|
userInfo.name = "向量"
|
|
|
+ FetchHandler().fetchAny(url: "bxn-portal/portal/osforstudent/index") { res in
|
|
|
+ print(res)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
struct loginView: View {
|
|
@@ -117,7 +163,7 @@ struct loginView: View {
|
|
|
var body: some View {
|
|
|
VStack {
|
|
|
Form {
|
|
|
- Section {
|
|
|
+ List {
|
|
|
HStack {
|
|
|
Image(systemName: "person.fill").foregroundColor(Color(red: 0.7, green: 0.7, blue: 0.7))
|
|
|
TextField(text: $username, prompt: Text("数字校园号")) {
|
|
@@ -126,11 +172,12 @@ struct loginView: View {
|
|
|
.keyboardType(.numberPad)
|
|
|
}
|
|
|
HStack {
|
|
|
- Image(systemName: "lock.fill").foregroundColor(Color(red: 0.7, green: 0.7, blue: 0.7))
|
|
|
+ Image(systemName: "key.fill").foregroundColor(Color(red: 0.7, green: 0.7, blue: 0.7))
|
|
|
SecureField(text: $password, prompt: Text("密码")) {
|
|
|
Text("密码")
|
|
|
}.focused($isFocused)
|
|
|
}
|
|
|
+
|
|
|
}.onTapGesture {
|
|
|
isFocused = false
|
|
|
}
|
|
@@ -153,6 +200,8 @@ struct loginView: View {
|
|
|
Text(btnText)
|
|
|
if inProgress {
|
|
|
ProgressView()
|
|
|
+ } else {
|
|
|
+ Image(systemName: "chevron.right")
|
|
|
}
|
|
|
}
|
|
|
}.foregroundColor(btnColor).buttonStyle(.bordered)
|