Commit 46f51bee authored by shigemi miura's avatar shigemi miura

Ship IDとPassword入力ルート作成

parent e43c5064
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
D5AE351A2AEBA66A00059889 /* ReqLogin.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5AE35182AEBA66A00059889 /* ReqLogin.swift */; }; D5AE351A2AEBA66A00059889 /* ReqLogin.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5AE35182AEBA66A00059889 /* ReqLogin.swift */; };
D5AE351B2AEBA66A00059889 /* ResLogin.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5AE35192AEBA66A00059889 /* ResLogin.swift */; }; D5AE351B2AEBA66A00059889 /* ResLogin.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5AE35192AEBA66A00059889 /* ResLogin.swift */; };
D5AE351D2AEBA6FC00059889 /* SessionLogin.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5AE351C2AEBA6FC00059889 /* SessionLogin.swift */; }; D5AE351D2AEBA6FC00059889 /* SessionLogin.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5AE351C2AEBA6FC00059889 /* SessionLogin.swift */; };
D5EA864A2AF213C90032E810 /* LocationCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5EA86492AF213C90032E810 /* LocationCalculation.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
...@@ -152,6 +153,7 @@ ...@@ -152,6 +153,7 @@
D5AE35182AEBA66A00059889 /* ReqLogin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ReqLogin.swift; path = Sailassist/Json/ReqLogin.swift; sourceTree = SOURCE_ROOT; }; D5AE35182AEBA66A00059889 /* ReqLogin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ReqLogin.swift; path = Sailassist/Json/ReqLogin.swift; sourceTree = SOURCE_ROOT; };
D5AE35192AEBA66A00059889 /* ResLogin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ResLogin.swift; path = Sailassist/Json/ResLogin.swift; sourceTree = SOURCE_ROOT; }; D5AE35192AEBA66A00059889 /* ResLogin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ResLogin.swift; path = Sailassist/Json/ResLogin.swift; sourceTree = SOURCE_ROOT; };
D5AE351C2AEBA6FC00059889 /* SessionLogin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SessionLogin.swift; path = Sailassist/ServerSession/SessionLogin.swift; sourceTree = SOURCE_ROOT; }; D5AE351C2AEBA6FC00059889 /* SessionLogin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SessionLogin.swift; path = Sailassist/ServerSession/SessionLogin.swift; sourceTree = SOURCE_ROOT; };
D5EA86492AF213C90032E810 /* LocationCalculation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LocationCalculation.swift; path = ../../../../Sailassist_login/Seilassist/Sailassist/Location/LocationCalculation.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
...@@ -208,6 +210,7 @@ ...@@ -208,6 +210,7 @@
020B98122AD8C3140029DE4C /* SailAssist */ = { 020B98122AD8C3140029DE4C /* SailAssist */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
D5EA86482AF2139D0032E810 /* Location */,
D52D213B2AEBB78E00324D58 /* ECA */, D52D213B2AEBB78E00324D58 /* ECA */,
D52D21382AEBABE700324D58 /* Http */, D52D21382AEBABE700324D58 /* Http */,
D5AE35172AEBA64800059889 /* Json */, D5AE35172AEBA64800059889 /* Json */,
...@@ -467,6 +470,14 @@ ...@@ -467,6 +470,14 @@
path = Json; path = Json;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
D5EA86482AF2139D0032E810 /* Location */ = {
isa = PBXGroup;
children = (
D5EA86492AF213C90032E810 /* LocationCalculation.swift */,
);
path = Location;
sourceTree = "<group>";
};
/* End PBXGroup section */ /* End PBXGroup section */
/* Begin PBXNativeTarget section */ /* Begin PBXNativeTarget section */
...@@ -602,6 +613,7 @@ ...@@ -602,6 +613,7 @@
02CD06912AE6536B005F8D8F /* LayerEnum.swift in Sources */, 02CD06912AE6536B005F8D8F /* LayerEnum.swift in Sources */,
020B98532AD919180029DE4C /* LoginTypeSelectView.swift in Sources */, 020B98532AD919180029DE4C /* LoginTypeSelectView.swift in Sources */,
D52D213F2AEBB7D700324D58 /* RegisteredEca.swift in Sources */, D52D213F2AEBB7D700324D58 /* RegisteredEca.swift in Sources */,
D5EA864A2AF213C90032E810 /* LocationCalculation.swift in Sources */,
02CD06952AE895F5005F8D8F /* APIError.swift in Sources */, 02CD06952AE895F5005F8D8F /* APIError.swift in Sources */,
02CE4DC82ADF97E8002E79BC /* View+Extensions.swift in Sources */, 02CE4DC82ADF97E8002E79BC /* View+Extensions.swift in Sources */,
020B98412AD8C3810029DE4C /* LoginView.swift in Sources */, 020B98412AD8C3810029DE4C /* LoginView.swift in Sources */,
...@@ -800,7 +812,7 @@ ...@@ -800,7 +812,7 @@
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\"";
DEVELOPMENT_TEAM = 886VZM9928; DEVELOPMENT_TEAM = D2DC7QNNJ8;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Sailassist/Info.plist; INFOPLIST_FILE = Sailassist/Info.plist;
...@@ -832,7 +844,7 @@ ...@@ -832,7 +844,7 @@
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\"";
DEVELOPMENT_TEAM = 886VZM9928; DEVELOPMENT_TEAM = D2DC7QNNJ8;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Sailassist/Info.plist; INFOPLIST_FILE = Sailassist/Info.plist;
......
This diff is collapsed.
...@@ -55,7 +55,7 @@ struct LoginView: View { ...@@ -55,7 +55,7 @@ struct LoginView: View {
case .InputIdPassword: case .InputIdPassword:
InputIdPassWordView(viewMode: $viewMode, param: $loginViewParam) InputIdPassWordView(viewMode: $viewMode, param: $loginViewParam)
case .InputUserName: case .InputUserName:
InputUserNameView(isLogin: $isLogin, param: $loginViewParam) InputUserNameView(isLogin: $isLogin, param: $loginViewParam, viewMode: $viewMode)
} }
Spacer() Spacer()
......
...@@ -11,6 +11,8 @@ import Combine ...@@ -11,6 +11,8 @@ import Combine
struct InputIdPassWordView: View { struct InputIdPassWordView: View {
@Binding var viewMode : LoginViewMode @Binding var viewMode : LoginViewMode
@Binding var param : LoginViewParam @Binding var param : LoginViewParam
@State private var isUserNmaeEmpty = false
@State private var isIdPassWordEmpty = false
let itemHPadding: Double = 16 let itemHPadding: Double = 16
let dialogBottomPadding: Double = 32 let dialogBottomPadding: Double = 32
...@@ -74,10 +76,11 @@ struct InputIdPassWordView: View { ...@@ -74,10 +76,11 @@ struct InputIdPassWordView: View {
.frame(height: 40) .frame(height: 40)
Button(action: { Button(action: {
let sessionLogin = SessionLogin.OnlyOne if param.shipId.isEmpty || param.password.isEmpty {
let login = ReqLogin(Id: param.shipId, Password: param.password) isIdPassWordEmpty = true
sessionLogin.RequestLogin(login) } else {
viewMode = .InputUserName viewMode = .InputUserName
}
}, label: { }, label: {
Text("Sign In") Text("Sign In")
.frame(height: 60) .frame(height: 60)
...@@ -85,6 +88,11 @@ struct InputIdPassWordView: View { ...@@ -85,6 +88,11 @@ struct InputIdPassWordView: View {
.foregroundColor(.buttonText) .foregroundColor(.buttonText)
.background(.primaryActiveIcon) .background(.primaryActiveIcon)
}) })
.alert(isPresented: $isIdPassWordEmpty, content: {
Alert(title: Text("error"),
message: Text("Ship Id or Password not entered.")
)
})
} }
.padding(EdgeInsets(top: 26, leading: 20, bottom: 40, trailing: 20)) .padding(EdgeInsets(top: 26, leading: 20, bottom: 40, trailing: 20))
.background(ColorSet.BackgroundSecondary.color) .background(ColorSet.BackgroundSecondary.color)
......
...@@ -8,29 +8,37 @@ ...@@ -8,29 +8,37 @@
import SwiftUI import SwiftUI
struct InputUserNameView: View { struct InputUserNameView: View {
@ObservedObject var sessionLogin: SessionLogin = SessionLogin()
@Binding var isLogin: Bool @Binding var isLogin: Bool
@Binding var param: LoginViewParam @Binding var param: LoginViewParam
@Binding var viewMode : LoginViewMode
@State private var isAlert = false
@State private var alertType: AlertType = .userNameEmpty
let itemHPadding: Double = 16 let itemHPadding: Double = 16
let dialogBottomPadding: Double = 32 let dialogBottomPadding: Double = 32
let textFieldHeight: Double = 40 let textFieldHeight: Double = 40
let inputAreaHeight: Double = 150 let inputAreaHeight: Double = 150
let dialogHeight: CGFloat = 250 let dialogHeight: CGFloat = 250
let dialogWidth = UIScreen.main.bounds.width - 32 let dialogWidth = UIScreen.main.bounds.width - 32
enum AlertType {
case userNameEmpty
case loginFailure
}
var body: some View { var body: some View {
HStack { HStack {
Spacer() Spacer()
.frame(width: itemHPadding) .frame(width: itemHPadding)
VStack{ VStack{
Spacer() Spacer()
VStack(alignment: .leading) { VStack(alignment: .leading) {
Text("JRC Ship") Text("JRC Ship")
.padding(.leading, 4) .padding(.leading, 4)
.bold() .bold()
.foregroundColor(.white) .foregroundColor(.white)
HStack{ HStack{
Image("account") Image("account")
.padding(.horizontal, 4) .padding(.horizontal, 4)
...@@ -39,28 +47,36 @@ struct InputUserNameView: View { ...@@ -39,28 +47,36 @@ struct InputUserNameView: View {
"", "",
text: $param.userName, text: $param.userName,
prompt: Text("Please set user name") prompt: Text("Please set user name")
.foregroundColor(.white) .foregroundColor(.white)
) )
.frame(height: textFieldHeight) .frame(height: textFieldHeight)
.padding(.trailing) .padding(.trailing)
.foregroundColor(.white) .foregroundColor(.white)
} }
Divider() Divider()
.frame(height: 2) .frame(height: 2)
.background(Color(.white)) .background(Color(.white))
} }
.frame(height: inputAreaHeight) .frame(height: inputAreaHeight)
Spacer() Spacer()
Button(action: { Button(action: {
// TODO: API通信 ログイン認証処理 if param.userName.isEmpty {
print("signin: id(\(param.shipId)), pass(\(param.password)), name(\(param.userName))") isAlert = true
isLogin = true alertType = .userNameEmpty
Preferences.lastLoginDate_Int64 = DateTextLib.Date2UnixTime(date: Date()) } else {
//TODO: API通信 ログイン認証処理
print(debug: "signin: id(\(param.shipId)), pass(\(param.password)), name(\(param.userName))")
isAlert = false
// param.shipId = "jrcetest01@gmail.com"
// param.password = "JRCEtest01_"
let login = ReqLogin(Id: param.shipId, Password: param.password)
sessionLogin.RequestLogin(login, completion: responseLogin)
}
}, label: { }, label: {
Text("Sign In") Text("Sign In")
.frame(height: 50) .frame(height: 50)
...@@ -68,21 +84,52 @@ struct InputUserNameView: View { ...@@ -68,21 +84,52 @@ struct InputUserNameView: View {
.foregroundColor(ColorSet.ButtonText.color) .foregroundColor(ColorSet.ButtonText.color)
.background(ColorSet.PrimaryActiveIcon.color) .background(ColorSet.PrimaryActiveIcon.color)
}) })
.alert(isPresented: $isAlert) {
switch alertType {
case .userNameEmpty:
return Alert(title: Text("error"),
message: Text("User Nmae not entered.")
)
case .loginFailure:
return Alert(title: Text("error"),
message: Text("Login failure."),
dismissButton: .default(Text("OK"), action: {viewMode = .SelectType})
)
}
}
Spacer() Spacer()
.frame(height: dialogBottomPadding) .frame(height: dialogBottomPadding)
} }
Spacer() Spacer()
.frame(width: itemHPadding) .frame(width: itemHPadding)
} }
.frame(width: dialogWidth, height: dialogHeight) .frame(width: dialogWidth, height: dialogHeight)
.background(ColorSet.BackgroundSecondary.color) .background(ColorSet.BackgroundSecondary.color)
} }
func responseLogin(result: Result<Data, APIError>) {
print(debug: "calld")
switch result {
case .success(let resultData):
let jsonstr = String(data: resultData, encoding: .utf8)!
Preferences.ShipId = param.shipId
Preferences.ShipPassword = param.password
Preferences.lastLoginDate_Int64 = DateTextLib.Date2UnixTime(date: Date())
isLogin = true
isAlert = false
case .failure(let errorCode):
param.shipId = ""
param.password = ""
isLogin = false
isAlert = true
alertType = .loginFailure
break
}
}
} }
#Preview { #Preview {
InputUserNameView(isLogin: .constant(false), param: .constant(LoginViewParam())) InputUserNameView(isLogin: .constant(false), param: .constant(LoginViewParam()), viewMode: .constant(.InputIdPassword))
} }
...@@ -23,8 +23,12 @@ class Preferences{ ...@@ -23,8 +23,12 @@ class Preferences{
} }
} }
@AppStorage("KEY") static var hogehoge: String = "" @AppStorage(wrappedValue:"", PreferencesKey.TypeString.ShipId.rawValue) static var ShipId: String
@AppStorage(wrappedValue:"", PreferencesKey.TypeString.ShipPassword.rawValue) static var ShipPassword: String
@AppStorage(wrappedValue:"", PreferencesKey.TypeString.Mmsi.rawValue) static var Mmsi: String
@AppStorage(wrappedValue:"", PreferencesKey.TypeString.ShipName.rawValue) static var ShipName: String
@AppStorage(wrappedValue:"", PreferencesKey.TypeString.GroupName.rawValue) static var GroupName: String
@AppStorage(wrappedValue:"", PreferencesKey.TypeString.UserName.rawValue) static var UserName: String
// func getPreferences(key) // func getPreferences(key)
} }
......
...@@ -5,17 +5,15 @@ ...@@ -5,17 +5,15 @@
// Created by 三浦薫巳 on 2023/10/26. // Created by 三浦薫巳 on 2023/10/26.
// //
import WebKit import Foundation
import SwiftUI
class SessionLogin : NSObject { class SessionLogin : ObservableObject {
@Published var status = false
// シングルトン宣言 // シングルトン宣言
static let OnlyOne = SessionLogin() static let OnlyOne = SessionLogin()
private var serverSession = ServerSession() private var serverSession = ServerSession()
override init() {
super.init()
}
private var Calling : Bool = false // 通信中 private var Calling : Bool = false // 通信中
/** /**
...@@ -23,7 +21,7 @@ class SessionLogin : NSObject { ...@@ -23,7 +21,7 @@ class SessionLogin : NSObject {
* - Parameters: * - Parameters:
* - login: ログイン情報 * - login: ログイン情報
*/ */
func RequestLogin(_ login : ReqLogin) { func RequestLogin(_ login : ReqLogin, completion: @escaping ((Result<Data, APIError>)) -> Void) {
print(debug: "calld") print(debug: "calld")
if Calling { if Calling {
return return
...@@ -38,27 +36,11 @@ class SessionLogin : NSObject { ...@@ -38,27 +36,11 @@ class SessionLogin : NSObject {
} }
if let postdata = serverSession.toJSON(login) { if let postdata = serverSession.toJSON(login) {
serverSession.postJson(req_url, postdata, completion: serverResponse) serverSession.postJson(req_url, postdata, completion: completion)
} }
else { else {
Calling = false Calling = false
return return
} }
} }
func serverResponse(result: Result<Data, APIError>) {
print(debug: "calld")
switch result {
case .success(let resultData):
let jsonstr = String(data: resultData, encoding: .utf8)!
if jsonstr == "Completed.\n\n" {
Calling = false
} else {
Calling = false
}
case .failure(let errorCode):
print(errorCode)
break
}
}
} }
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