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

ログインエラー追加

・期間 ・QR
parent 22287f71
...@@ -1238,7 +1238,7 @@ ...@@ -1238,7 +1238,7 @@
CODE_SIGN_ENTITLEMENTS = Sailassist/Sailassist.entitlements; CODE_SIGN_ENTITLEMENTS = Sailassist/Sailassist.entitlements;
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 18; CURRENT_PROJECT_VERSION = 19;
DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\"";
DEVELOPMENT_TEAM = D2DC7QNNJ8; DEVELOPMENT_TEAM = D2DC7QNNJ8;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
...@@ -1284,7 +1284,7 @@ ...@@ -1284,7 +1284,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Sailassist/Sailassist.entitlements; CODE_SIGN_ENTITLEMENTS = Sailassist/Sailassist.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 18; CURRENT_PROJECT_VERSION = 19;
DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\"";
DEVELOPMENT_TEAM = D2DC7QNNJ8; DEVELOPMENT_TEAM = D2DC7QNNJ8;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
...@@ -1468,7 +1468,7 @@ ...@@ -1468,7 +1468,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Sailassist/Sailassist.entitlements; CODE_SIGN_ENTITLEMENTS = Sailassist/Sailassist.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 18; CURRENT_PROJECT_VERSION = 19;
DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\"";
DEVELOPMENT_TEAM = D2DC7QNNJ8; DEVELOPMENT_TEAM = D2DC7QNNJ8;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
......
...@@ -28,6 +28,7 @@ class LoginViewParam: ObservableObject{ ...@@ -28,6 +28,7 @@ class LoginViewParam: ObservableObject{
@Published var password: String = "" @Published var password: String = ""
@Published var deviceid: String = "" @Published var deviceid: String = ""
@Published var userName: String = "" @Published var userName: String = ""
@Published var qrCode: Bool = false
} }
let TimerInterval = 60.0 let TimerInterval = 60.0
...@@ -130,7 +131,7 @@ struct LoginView: View { ...@@ -130,7 +131,7 @@ struct LoginView: View {
) )
case .Expired: case .Expired:
return Alert(title: Text("Error"), return Alert(title: Text("Error"),
message: Text("Expired."), message: Text("This account is expired."),
dismissButton: .default(Text("OK"), action: {viewMode = .SelectType}) dismissButton: .default(Text("OK"), action: {viewMode = .SelectType})
) )
} }
...@@ -152,19 +153,23 @@ struct LoginView: View { ...@@ -152,19 +153,23 @@ struct LoginView: View {
} }
} }
/**
* QRコードでのログイン
*/
func LoginCheckQR() -> () { func LoginCheckQR() -> () {
isProgressView = true isProgressView = true
loginViewParam.shipId = Preferences.Id loginViewParam.shipId = Preferences.Id
loginViewParam.password = Preferences.Password loginViewParam.password = Preferences.Password
loginViewParam.deviceid = Preferences.DeviceId loginViewParam.deviceid = Preferences.DeviceId
// loginViewParam.userName = Preferences.UserName loginViewParam.qrCode = true
viewMode = .InputUserName viewMode = .InputUserName
isProgressView = false 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() -> () { func LoginCheck() -> () {
let lastUnixTime = Preferences.lastLoginDate_Int64 ?? 0 let lastUnixTime = Preferences.lastLoginDate_Int64 ?? 0
let lastDate = DateTextLib.UnixTime2Date(lastUnixTime) let lastDate = DateTextLib.UnixTime2Date(lastUnixTime)
...@@ -179,68 +184,6 @@ struct LoginView: View { ...@@ -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>) { func responseLogin(result: Result<Data, APIError>) {
print(debug: "calld") print(debug: "calld")
switch result { switch result {
...@@ -292,7 +235,17 @@ struct LoginView: View { ...@@ -292,7 +235,17 @@ struct LoginView: View {
case .clientError: case .clientError:
alertType = .ClientError alertType = .ClientError
case .serverError: case .serverError:
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 alertType = .loginFailure
}
default: default:
alertType = .loginFailure alertType = .loginFailure
} }
......
...@@ -64,6 +64,7 @@ struct InputIdPassWordView: View { ...@@ -64,6 +64,7 @@ struct InputIdPassWordView: View {
Button(action: { Button(action: {
if param.shipId.isEmpty || param.password.isEmpty { if param.shipId.isEmpty || param.password.isEmpty {
param.qrCode = false
isIdPassWordEmpty = true isIdPassWordEmpty = true
} else { } else {
viewMode = .InputUserName viewMode = .InputUserName
......
...@@ -141,10 +141,28 @@ struct InputUserNameView: View { ...@@ -141,10 +141,28 @@ struct InputUserNameView: View {
case .failure(let errorCode): case .failure(let errorCode):
print(debug: 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 isProgressView = false
isLogin = false isLogin = false
isAlert = true isAlert = true
alertType = .loginFailure
break break
} }
} }
......
...@@ -23,12 +23,14 @@ class ScannerViewModel: ObservableObject { ...@@ -23,12 +23,14 @@ class ScannerViewModel: ObservableObject {
Preferences.Id = resjson.id Preferences.Id = resjson.id
Preferences.Password = resjson.pass Preferences.Password = resjson.pass
Preferences.Expiry = resjson.exp
Preferences.lastLoginDate_Int64 = DateTextLib.Date2UnixTime(date: Date()) Preferences.lastLoginDate_Int64 = DateTextLib.Date2UnixTime(date: Date())
} catch { } catch {
print(debug: "decodeエラー") print(debug: "decodeエラー")
Preferences.Id = "" Preferences.Id = ""
Preferences.Password = "" Preferences.Password = ""
Preferences.Expiry = ""
} }
isShowing = false isShowing = false
......
...@@ -53,6 +53,7 @@ class Preferences{ ...@@ -53,6 +53,7 @@ class Preferences{
@AppStorage(wrappedValue:"", PreferencesKey.TypeString.Password.rawValue) static var Password: String @AppStorage(wrappedValue:"", PreferencesKey.TypeString.Password.rawValue) static var Password: String
@AppStorage(wrappedValue:"", PreferencesKey.TypeString.DeviceId.rawValue) static var DeviceId: 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 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.shipId.rawValue) static var shipId: Int
@AppStorage(wrappedValue:0, PreferencesKey.TypeInt.LocationType.rawValue) static var LocationType: Int @AppStorage(wrappedValue:0, PreferencesKey.TypeInt.LocationType.rawValue) static var LocationType: Int
......
...@@ -16,6 +16,7 @@ class PreferencesKey{ ...@@ -16,6 +16,7 @@ class PreferencesKey{
case Password case Password
case UserName case UserName
case DeviceId case DeviceId
case Expiry
//Manual類Version //Manual類Version
case ECDISBasic 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