Commit 6764045b authored by shigemi miura's avatar shigemi miura

ログインエラー追加

・期間 ・QR
parent 22287f71
......@@ -1238,7 +1238,7 @@
CODE_SIGN_ENTITLEMENTS = Sailassist/Sailassist.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 18;
CURRENT_PROJECT_VERSION = 19;
DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\"";
DEVELOPMENT_TEAM = D2DC7QNNJ8;
ENABLE_PREVIEWS = YES;
......@@ -1284,7 +1284,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Sailassist/Sailassist.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 18;
CURRENT_PROJECT_VERSION = 19;
DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\"";
DEVELOPMENT_TEAM = D2DC7QNNJ8;
ENABLE_PREVIEWS = YES;
......@@ -1468,7 +1468,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Sailassist/Sailassist.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 18;
CURRENT_PROJECT_VERSION = 19;
DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\"";
DEVELOPMENT_TEAM = D2DC7QNNJ8;
ENABLE_PREVIEWS = YES;
......
......@@ -28,6 +28,7 @@ class LoginViewParam: ObservableObject{
@Published var password: String = ""
@Published var deviceid: String = ""
@Published var userName: String = ""
@Published var qrCode: Bool = false
}
let TimerInterval = 60.0
......@@ -130,7 +131,7 @@ struct LoginView: View {
)
case .Expired:
return Alert(title: Text("Error"),
message: Text("Expired."),
message: Text("This account is expired."),
dismissButton: .default(Text("OK"), action: {viewMode = .SelectType})
)
}
......@@ -152,19 +153,23 @@ struct LoginView: View {
}
}
/**
* QRコードでのログイン
*/
func LoginCheckQR() -> () {
isProgressView = true
loginViewParam.shipId = Preferences.Id
loginViewParam.password = Preferences.Password
loginViewParam.deviceid = Preferences.DeviceId
// loginViewParam.userName = Preferences.UserName
loginViewParam.qrCode = true
viewMode = .InputUserName
isProgressView = false
// let login = ReqLogin(Id: Preferences.Id, Password: Preferences.Password, DeviceId: Preferences.DeviceId, UserName: Preferences.UserName)
// sessionLogin.RequestLogin(login, completion: responseQrLogin)
}
/**
* Autoログイン
*/
func LoginCheck() -> () {
let lastUnixTime = Preferences.lastLoginDate_Int64 ?? 0
let lastDate = DateTextLib.UnixTime2Date(lastUnixTime)
......@@ -179,68 +184,6 @@ struct LoginView: View {
}
}
func responseQrLogin(result: Result<Data, APIError>) {
print(debug: "calld")
switch result {
case .success(let resultData):
let serverSession = ServerSession()
let resjson = serverSession.fromJSON(resultData: resultData, resltType: ResLogin.self)
if let res = resjson {
SharingData.my.id = res.id
SharingData.my.shipId = res.shipId
SharingData.my.shipName = res.shipName
SharingData.my.imo = res.imo
SharingData.my.mmsi = res.mmsi
SharingData.my.isFuelSwitchTask = res.enableFuelSwitchTask
Preferences.shipId = res.shipId
let notificationTags = NotificationTags()
notificationTags.addTags()
}
Preferences.lastLoginDate_Int64 = DateTextLib.Date2UnixTime(date: Date())
viewMode = .InputUserName
let ecaArea = EcaArea()
ecaArea.start()
timer = Timer.scheduledTimer(withTimeInterval: TimerInterval, repeats: true) { _ in
print(debug: "called timer")
let eca = EcaTask()
eca.start()
let message = GetMessage()
message.start()
let route = MonitoringRoute()
route.start()
let ecaList = GetEcaList()
ecaList.start()
let pushHistory = GetPushHistory()
pushHistory.start()
}
timer?.fire()
case .failure(let errorCode):
print(debug: errorCode)
switch errorCode {
case .clientError:
alertType = .ClientError
case .serverError:
alertType = .QrFailure
default:
alertType = .QrFailure
}
isLogin = false
isAlert = true
break
}
isProgressView = false
}
func responseLogin(result: Result<Data, APIError>) {
print(debug: "calld")
switch result {
......@@ -292,7 +235,17 @@ struct LoginView: View {
case .clientError:
alertType = .ClientError
case .serverError:
alertType = .loginFailure
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
if let expiry = dateFormatter.date(from: Preferences.Expiry) {
if Date() < expiry {
alertType = .loginFailure
} else {
alertType = .Expired
}
} else {
alertType = .loginFailure
}
default:
alertType = .loginFailure
}
......
......@@ -64,6 +64,7 @@ struct InputIdPassWordView: View {
Button(action: {
if param.shipId.isEmpty || param.password.isEmpty {
param.qrCode = false
isIdPassWordEmpty = true
} else {
viewMode = .InputUserName
......
......@@ -141,10 +141,28 @@ struct InputUserNameView: View {
case .failure(let errorCode):
print(debug: errorCode)
switch errorCode {
case .clientError:
alertType = .ClientError
case .serverError:
if param.qrCode {
alertType = .QrFailure
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
if let expiry = dateFormatter.date(from: Preferences.Expiry) {
if Date() > expiry {
alertType = .Expired
}
}
} else {
alertType = .loginFailure
}
default:
alertType = .loginFailure
}
isProgressView = false
isLogin = false
isAlert = true
alertType = .loginFailure
break
}
}
......
......@@ -23,12 +23,14 @@ class ScannerViewModel: ObservableObject {
Preferences.Id = resjson.id
Preferences.Password = resjson.pass
Preferences.Expiry = resjson.exp
Preferences.lastLoginDate_Int64 = DateTextLib.Date2UnixTime(date: Date())
} catch {
print(debug: "decodeエラー")
Preferences.Id = ""
Preferences.Password = ""
Preferences.Expiry = ""
}
isShowing = false
......
......@@ -53,6 +53,7 @@ class Preferences{
@AppStorage(wrappedValue:"", PreferencesKey.TypeString.Password.rawValue) static var Password: String
@AppStorage(wrappedValue:"", PreferencesKey.TypeString.DeviceId.rawValue) static var DeviceId: String
@AppStorage(wrappedValue:"", PreferencesKey.TypeString.UserName.rawValue) static var UserName: String
@AppStorage(wrappedValue:"", PreferencesKey.TypeString.UserName.rawValue) static var Expiry: String
@AppStorage(wrappedValue:0, PreferencesKey.TypeInt.shipId.rawValue) static var shipId: Int
@AppStorage(wrappedValue:0, PreferencesKey.TypeInt.LocationType.rawValue) static var LocationType: Int
......
......@@ -16,6 +16,7 @@ class PreferencesKey{
case Password
case UserName
case DeviceId
case Expiry
//Manual類Version
case ECDISBasic
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment