Skip to content

Commit

Permalink
Merge pull request #7 from TheNoim/qr-code-login
Browse files Browse the repository at this point in the history
Fix QR-Code login for schools with a space in the name
  • Loading branch information
TheNoim authored Oct 7, 2021
2 parents f9f80e4 + 18196b1 commit b63267d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
12 changes: 6 additions & 6 deletions Project SITNU.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
OTHER_SWIFT_FLAGS = "-Xfrontend -warn-long-function-bodies=100 -Xfrontend -warn-long-expression-type-checking=100";
PRODUCT_BUNDLE_IDENTIFIER = "io.noim.Project-SITNU.watchkitapp.watchkitextension";
PRODUCT_NAME = "${TARGET_NAME}";
Expand Down Expand Up @@ -895,7 +895,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
OTHER_SWIFT_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = "io.noim.Project-SITNU.watchkitapp.watchkitextension";
PRODUCT_NAME = "${TARGET_NAME}";
Expand All @@ -919,7 +919,7 @@
DEVELOPMENT_TEAM = P88CDRP8CR;
IBSC_MODULE = Watch_Extension;
INFOPLIST_FILE = Watch/Info.plist;
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
PRODUCT_BUNDLE_IDENTIFIER = "io.noim.Project-SITNU.watchkitapp";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = watchos;
Expand All @@ -941,7 +941,7 @@
DEVELOPMENT_TEAM = P88CDRP8CR;
IBSC_MODULE = Watch_Extension;
INFOPLIST_FILE = Watch/Info.plist;
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
PRODUCT_BUNDLE_IDENTIFIER = "io.noim.Project-SITNU.watchkitapp";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = watchos;
Expand Down Expand Up @@ -1087,7 +1087,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
PRODUCT_BUNDLE_IDENTIFIER = "io.noim.Project-SITNU";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -1116,7 +1116,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
PRODUCT_BUNDLE_IDENTIFIER = "io.noim.Project-SITNU";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
5 changes: 3 additions & 2 deletions Project SITNU/Views/SchoolSearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ struct SchoolSearchView: View {
}
NavigationLink(destination: CodeScannerView(codeTypes: [.qr], completion: { result in
if case let .success(code) = result {
print("Code: \(code)");
guard let url = URL(string: code) else {
let cleanedUrl = code.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!;
print("Code: \(cleanedUrl)");
guard let url = URL(string: cleanedUrl) else {
print("Failed");
return;
}
Expand Down
5 changes: 5 additions & 0 deletions Watch Extension/HostingController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ class HostingController: WKHostingController<AnyView>, WCSessionDelegate {

func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
let context: [String: Any] = session.receivedApplicationContext;
log.debug("activationDidCompleteWith: \(context)");
self.setContext(context);
}

func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
log.debug("didReceiveApplicationContext: \(applicationContext)");
self.setContext(applicationContext);
}

Expand Down Expand Up @@ -79,6 +81,9 @@ class HostingController: WKHostingController<AnyView>, WCSessionDelegate {
if WCSession.isSupported() && self.activated == false {
self.activated = true;
WCSession.default.activate();
log.debug("Call WCSession.default.activate()");
} else {
log.debug("Session not activated or not supported");
}
}

Expand Down
9 changes: 7 additions & 2 deletions WebUntis/Client/Authenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class UntisAuthenticator: Authenticator {
}

func refresh(_ credential: UntisCredentials, for session: Session, completion: @escaping (Swift.Result<UntisCredentials, Error>) -> Void) {
let configuration = URLSessionConfiguration.af.default;
configuration.httpShouldSetCookies = false;
let session = Session(configuration: configuration)
if credential.authType == AuthType.PASSWORD {
let login: Parameters = [
"id": "SITNU",
Expand All @@ -61,7 +64,8 @@ class UntisAuthenticator: Authenticator {
"client": "SITNU"
]
];
AF.request("https://\(credential.server)/WebUntis/jsonrpc.do?school=\(credential.school)", method: .post, parameters: login, encoding: JSONEncoding.default).responseJSON { response in
session.request("https://\(credential.server)/WebUntis/jsonrpc.do?school=\(credential.school)", method: .post, parameters: login, encoding: JSONEncoding.default).responseJSON { response in
let _ = session; // Keep reference
switch response.result {
case .failure(let error):
completion(.failure(UntisError.alamofire(error: error)));
Expand Down Expand Up @@ -136,7 +140,8 @@ class UntisAuthenticator: Authenticator {
]
]
];
AF.request("https://\(credential.server)/WebUntis/jsonrpc_intern.do?school=\(credential.school)&a=0&s=\(credential.server)&m=getUserData2017&v=i3.23.0", method: .post, parameters: login, encoding: JSONEncoding.default).responseJSON { response in
session.request("https://\(credential.server)/WebUntis/jsonrpc_intern.do?school=\(credential.school)&a=0&s=\(credential.server)&m=getUserData2017&v=i3.23.0", method: .post, parameters: login, encoding: JSONEncoding.default).responseJSON { response in
let _ = session; // Keep reference
switch response.result {
case .failure(let error):
completion(.failure(UntisError.alamofire(error: error)));
Expand Down

0 comments on commit b63267d

Please sign in to comment.