Protecting against register account with same fingerprint
This commit is contained in:
parent
322a0b4cb4
commit
3881f37818
5 changed files with 41 additions and 16 deletions
|
@ -18,6 +18,7 @@ public extension Sdk {
|
||||||
case noPrivateKey
|
case noPrivateKey
|
||||||
case noSignatureValues
|
case noSignatureValues
|
||||||
case urlError
|
case urlError
|
||||||
|
case deviceExist
|
||||||
|
|
||||||
case wrongToken
|
case wrongToken
|
||||||
case wrongSymbol
|
case wrongSymbol
|
||||||
|
|
|
@ -292,6 +292,7 @@ public class Sdk {
|
||||||
case 200: return APIError.wrongToken
|
case 200: return APIError.wrongToken
|
||||||
case -1: return APIError.wrongSymbol //Ya, Vulcan returns -1 code
|
case -1: return APIError.wrongSymbol //Ya, Vulcan returns -1 code
|
||||||
case 203: return APIError.wrongPin
|
case 203: return APIError.wrongPin
|
||||||
|
case 205: return APIError.deviceExist
|
||||||
default: return nil
|
default: return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
// Created by Mikołaj on 25/10/2020.
|
// Created by Mikołaj on 25/10/2020.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import KeychainAccess
|
||||||
|
|
||||||
enum AvailableEndpoints: String, CaseIterable {
|
enum AvailableEndpoints: String, CaseIterable {
|
||||||
case vulcan = "Vulcan"
|
case vulcan = "Vulcan"
|
||||||
|
@ -22,7 +22,6 @@ open class Navigation: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LoginView: View {
|
struct LoginView: View {
|
||||||
|
|
||||||
@StateObject var vulcan: VulcanStore = VulcanStore.shared
|
@StateObject var vulcan: VulcanStore = VulcanStore.shared
|
||||||
|
|
||||||
@State private var token: String = ""
|
@State private var token: String = ""
|
||||||
|
@ -35,6 +34,7 @@ struct LoginView: View {
|
||||||
@State private var loginStatus: String = ""
|
@State private var loginStatus: String = ""
|
||||||
@State private var willMoveToNextScreen = false
|
@State private var willMoveToNextScreen = false
|
||||||
@State private var success = false
|
@State private var success = false
|
||||||
|
@State private var showingAlert = false
|
||||||
|
|
||||||
let cellHeight: CGFloat = 55
|
let cellHeight: CGFloat = 55
|
||||||
let cornerRadius: CGFloat = 12
|
let cornerRadius: CGFloat = 12
|
||||||
|
@ -58,13 +58,30 @@ struct LoginView: View {
|
||||||
case "wrongPin":
|
case "wrongPin":
|
||||||
buttonValue = String(format: NSLocalizedString("\(error)", comment: "loginButton"))
|
buttonValue = String(format: NSLocalizedString("\(error)", comment: "loginButton"))
|
||||||
|
|
||||||
|
case "deviceExist":
|
||||||
|
showingAlert.toggle()
|
||||||
|
|
||||||
default:
|
default:
|
||||||
buttonValue = String(format: NSLocalizedString("invalidData", comment: "loginButton"))
|
buttonValue = String(format: NSLocalizedString("invalidData", comment: "loginButton"))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print("success")
|
print("success")
|
||||||
|
let keychain = Keychain()
|
||||||
|
let keyFingerprint = keychain["keyFingerprint"]
|
||||||
|
let allStudentsKeys = keychain["allStudentsKeys"]
|
||||||
|
|
||||||
|
let data = Data(allStudentsKeys!.utf8)
|
||||||
|
do {
|
||||||
|
let array = try JSONSerialization.jsonObject(with: data) as! [String]
|
||||||
|
if array.contains(keyFingerprint!) {
|
||||||
|
showingAlert.toggle()
|
||||||
|
} else {
|
||||||
success = true
|
success = true
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
print(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,9 +208,12 @@ struct LoginView: View {
|
||||||
.frame(maxWidth: .infinity)
|
.frame(maxWidth: .infinity)
|
||||||
.background(Color.accentColor.opacity(0.1))
|
.background(Color.accentColor.opacity(0.1))
|
||||||
.cornerRadius(cornerRadius)
|
.cornerRadius(cornerRadius)
|
||||||
}
|
|
||||||
.padding()
|
}.padding()
|
||||||
|
.alert(isPresented: $showingAlert) {
|
||||||
|
Alert(title: Text("Konto zarejestrowane"), message: Text("Konto zostało już zarejestrowane. Proszę zalogowaź się na inne konto."), dismissButton: .default(Text("OK")))}
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ struct AccountManagerView: View {
|
||||||
|
|
||||||
//parsing allStudentsKeys to array
|
//parsing allStudentsKeys to array
|
||||||
var allStudents: [String] = []
|
var allStudents: [String] = []
|
||||||
|
if(allStudentsKeys != "[]"){
|
||||||
let data = Data(allStudentsKeys.utf8)
|
let data = Data(allStudentsKeys.utf8)
|
||||||
do {
|
do {
|
||||||
let keys = try JSONSerialization.jsonObject(with: data) as! [String]
|
let keys = try JSONSerialization.jsonObject(with: data) as! [String]
|
||||||
|
@ -33,6 +34,7 @@ struct AccountManagerView: View {
|
||||||
} catch {
|
} catch {
|
||||||
print(error)
|
print(error)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return allStudents
|
return allStudents
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ struct ChooseStudentView: View {
|
||||||
allStudents.append(keyFingerprint!)
|
allStudents.append(keyFingerprint!)
|
||||||
keychain["allStudentsKeys"] = "\(allStudents)"
|
keychain["allStudentsKeys"] = "\(allStudents)"
|
||||||
|
|
||||||
|
|
||||||
//saving student
|
//saving student
|
||||||
keychain["student-\(String(describing: keyFingerprint!))"] = "\(json["Envelope"][i])"
|
keychain["student-\(String(describing: keyFingerprint!))"] = "\(json["Envelope"][i])"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue