Skip to content

Commit d84c9f7

Browse files
authored
Merge pull request #267 from TaskarCenterAtUW/bug-2036-Incorrect-message-shown-on-wrong-password
Fixed incorrect message on wrong pwd issue
2 parents 0daea0b + 22a1573 commit d84c9f7

File tree

3 files changed

+35
-37
lines changed

3 files changed

+35
-37
lines changed

GoInfoGame/GoInfoGame.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,7 +2737,7 @@
27372737
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
27382738
CODE_SIGN_IDENTITY = "Apple Development";
27392739
CODE_SIGN_STYLE = Automatic;
2740-
CURRENT_PROJECT_VERSION = 35;
2740+
CURRENT_PROJECT_VERSION = 36;
27412741
DEVELOPMENT_TEAM = G8MQVE5WWW;
27422742
GENERATE_INFOPLIST_FILE = YES;
27432743
INFOPLIST_FILE = GoInfoGame/Info.plist;
@@ -2775,7 +2775,7 @@
27752775
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
27762776
CODE_SIGN_IDENTITY = "Apple Development";
27772777
CODE_SIGN_STYLE = Automatic;
2778-
CURRENT_PROJECT_VERSION = 35;
2778+
CURRENT_PROJECT_VERSION = 36;
27792779
DEVELOPMENT_TEAM = G8MQVE5WWW;
27802780
GENERATE_INFOPLIST_FILE = YES;
27812781
INFOPLIST_FILE = GoInfoGame/Info.plist;

GoInfoGame/GoInfoGame/Login/SessionManager.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ final class SessionManager: ObservableObject {
1818
var lastLoginPassword: String?
1919

2020
func performLogin(username: String, password: String, environment: APIEnvironment, completion: @escaping (Bool, String) -> Void) {
21-
let userName = KeychainManager.load(.username, for: environment) ?? username
22-
let postParams = ["username": userName, "password": password]
21+
let postParams = ["username": username, "password": password]
2322
guard let postBody = try? JSONSerialization.data(withJSONObject: postParams) else {
2423
completion(false, "Failed to serialize JSON")
2524
return

GoInfoGame/GoInfoGame/Network/ApiManager.swift

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ class ApiManager {
4848
var request = URLRequest(url: url, timeoutInterval: Double.infinity)
4949
request.httpMethod = endpoint.method
5050

51-
52-
5351
if let formData = endpoint.formData {
5452
let boundary = "Boundary-\(UUID().uuidString)"
5553
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
@@ -75,7 +73,7 @@ class ApiManager {
7573
do {
7674
let filename = param["filename"] as? String ?? "image.jpeg"
7775
let contentType = param["contentType"] as? String ?? "application/octet-stream" // Default content type
78-
76+
7977
// Append headers for file data
8078
body.append("Content-Disposition: form-data; name=\"\(paramName)\"; filename=\"\(filename)\"\r\n".data(using: .utf8)!)
8179
body.append("Content-Type: \(contentType)\r\n\r\n".data(using: .utf8)!)
@@ -95,14 +93,14 @@ class ApiManager {
9593
// Set the HTTP body
9694
request.httpBody = body
9795
} else if let httpBody = endpoint.body {
98-
request.httpBody = httpBody
99-
}
96+
request.httpBody = httpBody
97+
}
10098

10199
if let headers = endpoint.headers {
102-
for (key, value) in headers {
103-
request.setValue(value, forHTTPHeaderField: key)
104-
}
105-
}
100+
for (key, value) in headers {
101+
request.setValue(value, forHTTPHeaderField: key)
102+
}
103+
}
106104

107105
let task = URLSession.shared.dataTask(with: request) { [weak self] data, response, error in
108106
guard let self = self else {
@@ -116,8 +114,9 @@ class ApiManager {
116114
}
117115

118116
if let httpResponse = response as? HTTPURLResponse,
119-
httpResponse.statusCode == 401,
120-
request.url!.lastPathComponent.contains("refresh-token") == false {
117+
httpResponse.statusCode == 401,
118+
request.url!.lastPathComponent.contains("refresh-token") == false,
119+
request.url!.lastPathComponent.contains("authenticate") == false {
121120
print("Failed requests: \(String(describing: request.url))")
122121
TokenRefresher.shared.refreshToken { [weak self] status in
123122
if status {
@@ -172,35 +171,35 @@ class ApiManager {
172171
} else {
173172
completion(.failure(APIError.custom("Empty JSON")))
174173
}
175-
174+
176175
return
177176
}
178177
}
179178
else {
180-
if let response = response as? HTTPURLResponse {
181-
switch response.statusCode {
182-
case 409:
183-
let conflictError = NSError(domain: "goinfogame", code: 409, userInfo: [NSLocalizedDescriptionKey: "version mismatch"])
184-
completion(.failure(APIError.conflict))
185-
186-
case 200:
187-
do {
188-
if let decodedString = String(data: data, encoding: .utf8) {
189-
completion(.success(decodedString as! T))
190-
} else {
191-
completion(.failure(APIError.custom("Failed to decode string")))
192-
}
193-
} catch {
194-
print("Failed to decode the non JSON: \(error.localizedDescription)")
195-
completion(.failure(APIError.custom("Failed to decode non JSON")))
179+
if let response = response as? HTTPURLResponse {
180+
switch response.statusCode {
181+
case 409:
182+
let conflictError = NSError(domain: "goinfogame", code: 409, userInfo: [NSLocalizedDescriptionKey: "version mismatch"])
183+
completion(.failure(APIError.conflict))
184+
185+
case 200:
186+
do {
187+
if let decodedString = String(data: data, encoding: .utf8) {
188+
completion(.success(decodedString as! T))
189+
} else {
190+
completion(.failure(APIError.custom("Failed to decode string")))
196191
}
197-
198-
default:
199-
completion(.failure(APIError(statusCode: response.statusCode)))
192+
} catch {
193+
print("Failed to decode the non JSON: \(error.localizedDescription)")
194+
completion(.failure(APIError.custom("Failed to decode non JSON")))
200195
}
201-
} else {
202-
completion(.failure(APIError.custom("No valid HTTP response received")))
196+
197+
default:
198+
completion(.failure(APIError(statusCode: response.statusCode)))
203199
}
200+
} else {
201+
completion(.failure(APIError.custom("No valid HTTP response received")))
202+
}
204203
}
205204
}
206205
task.resume()

0 commit comments

Comments
 (0)