Commit 6bbe751a authored by sugita mamoru's avatar sugita mamoru

Merge commit '46f51bee' into develop

parents 7a2157ee 46f51bee
......@@ -61,6 +61,7 @@
D5AE351A2AEBA66A00059889 /* ReqLogin.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5AE35182AEBA66A00059889 /* ReqLogin.swift */; };
D5AE351B2AEBA66A00059889 /* ResLogin.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5AE35192AEBA66A00059889 /* ResLogin.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 */
/* Begin PBXContainerItemProxy section */
......@@ -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; };
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; };
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 */
/* Begin PBXFrameworksBuildPhase section */
......@@ -208,6 +210,7 @@
020B98122AD8C3140029DE4C /* SailAssist */ = {
isa = PBXGroup;
children = (
D5EA86482AF2139D0032E810 /* Location */,
D52D213B2AEBB78E00324D58 /* ECA */,
D52D21382AEBABE700324D58 /* Http */,
D5AE35172AEBA64800059889 /* Json */,
......@@ -467,6 +470,14 @@
path = Json;
sourceTree = "<group>";
};
D5EA86482AF2139D0032E810 /* Location */ = {
isa = PBXGroup;
children = (
D5EA86492AF213C90032E810 /* LocationCalculation.swift */,
);
path = Location;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
......@@ -602,6 +613,7 @@
02CD06912AE6536B005F8D8F /* LayerEnum.swift in Sources */,
020B98532AD919180029DE4C /* LoginTypeSelectView.swift in Sources */,
D52D213F2AEBB7D700324D58 /* RegisteredEca.swift in Sources */,
D5EA864A2AF213C90032E810 /* LocationCalculation.swift in Sources */,
02CD06952AE895F5005F8D8F /* APIError.swift in Sources */,
02CE4DC82ADF97E8002E79BC /* View+Extensions.swift in Sources */,
020B98412AD8C3810029DE4C /* LoginView.swift in Sources */,
......@@ -800,7 +812,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\"";
DEVELOPMENT_TEAM = 886VZM9928;
DEVELOPMENT_TEAM = D2DC7QNNJ8;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Sailassist/Info.plist;
......@@ -832,7 +844,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"Sailassist/Preview Content\"";
DEVELOPMENT_TEAM = 886VZM9928;
DEVELOPMENT_TEAM = D2DC7QNNJ8;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Sailassist/Info.plist;
......
This diff is collapsed.
......@@ -55,7 +55,7 @@ struct LoginView: View {
case .InputIdPassword:
InputIdPassWordView(viewMode: $viewMode, param: $loginViewParam)
case .InputUserName:
InputUserNameView(isLogin: $isLogin, param: $loginViewParam)
InputUserNameView(isLogin: $isLogin, param: $loginViewParam, viewMode: $viewMode)
}
Spacer()
......
......@@ -11,6 +11,8 @@ import Combine
struct InputIdPassWordView: View {
@Binding var viewMode : LoginViewMode
@Binding var param : LoginViewParam
@State private var isUserNmaeEmpty = false
@State private var isIdPassWordEmpty = false
let itemHPadding: Double = 16
let dialogBottomPadding: Double = 32
......@@ -74,10 +76,11 @@ struct InputIdPassWordView: View {
.frame(height: 40)
Button(action: {
let sessionLogin = SessionLogin.OnlyOne
let login = ReqLogin(Id: param.shipId, Password: param.password)
sessionLogin.RequestLogin(login)
if param.shipId.isEmpty || param.password.isEmpty {
isIdPassWordEmpty = true
} else {
viewMode = .InputUserName
}
}, label: {
Text("Sign In")
.frame(height: 60)
......@@ -85,6 +88,11 @@ struct InputIdPassWordView: View {
.foregroundColor(.buttonText)
.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))
.background(ColorSet.BackgroundSecondary.color)
......
......@@ -8,17 +8,25 @@
import SwiftUI
struct InputUserNameView: View {
@ObservedObject var sessionLogin: SessionLogin = SessionLogin()
@Binding var isLogin: Bool
@Binding var param: LoginViewParam
@Binding var viewMode : LoginViewMode
@State private var isAlert = false
@State private var alertType: AlertType = .userNameEmpty
let itemHPadding: Double = 16
let dialogBottomPadding: Double = 32
let textFieldHeight: Double = 40
let inputAreaHeight: Double = 150
let dialogHeight: CGFloat = 250
let dialogWidth = UIScreen.main.bounds.width - 32
var body: some View {
enum AlertType {
case userNameEmpty
case loginFailure
}
var body: some View {
HStack {
Spacer()
.frame(width: itemHPadding)
......@@ -57,10 +65,18 @@ struct InputUserNameView: View {
Spacer()
Button(action: {
// TODO: API通信 ログイン認証処理
print("signin: id(\(param.shipId)), pass(\(param.password)), name(\(param.userName))")
isLogin = true
Preferences.lastLoginDate_Int64 = DateTextLib.Date2UnixTime(date: Date())
if param.userName.isEmpty {
isAlert = true
alertType = .userNameEmpty
} 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: {
Text("Sign In")
.frame(height: 50)
......@@ -68,7 +84,20 @@ struct InputUserNameView: View {
.foregroundColor(ColorSet.ButtonText.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()
.frame(height: dialogBottomPadding)
}
......@@ -79,10 +108,28 @@ struct InputUserNameView: View {
.frame(width: dialogWidth, height: dialogHeight)
.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 {
InputUserNameView(isLogin: .constant(false), param: .constant(LoginViewParam()))
InputUserNameView(isLogin: .constant(false), param: .constant(LoginViewParam()), viewMode: .constant(.InputIdPassword))
}
......@@ -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)
}
......
......@@ -5,17 +5,15 @@
// 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()
private var serverSession = ServerSession()
override init() {
super.init()
}
private var Calling : Bool = false // 通信中
/**
......@@ -23,7 +21,7 @@ class SessionLogin : NSObject {
* - Parameters:
* - login: ログイン情報
*/
func RequestLogin(_ login : ReqLogin) {
func RequestLogin(_ login : ReqLogin, completion: @escaping ((Result<Data, APIError>)) -> Void) {
print(debug: "calld")
if Calling {
return
......@@ -38,27 +36,11 @@ class SessionLogin : NSObject {
}
if let postdata = serverSession.toJSON(login) {
serverSession.postJson(req_url, postdata, completion: serverResponse)
serverSession.postJson(req_url, postdata, completion: completion)
}
else {
Calling = false
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