Commit 866c9797 authored by shigemi miura's avatar shigemi miura

QRコードでのログイン対応

画像ファイルの日本語削除
parent 6bbe751a
......@@ -12,7 +12,7 @@
"value" : "dark"
}
],
"filename" : "h1_signinのコピー.svg",
"filename" : "h1_signin_Dark.svg",
"idiom" : "universal",
"scale" : "1x"
},
......
......@@ -12,7 +12,7 @@
"value" : "dark"
}
],
"filename" : "logo_signinのコピー.svg",
"filename" : "logo_signin_Dark.svg",
"idiom" : "universal",
"scale" : "1x"
},
......
......@@ -12,7 +12,7 @@
"value" : "dark"
}
],
"filename" : "passwordのコピー.svg",
"filename" : "password_Dark.svg",
"idiom" : "universal",
"scale" : "1x"
},
......
{
"images" : [
{
"filename" : "chatのコピー3.svg",
"filename" : "chat.svg",
"idiom" : "universal",
"scale" : "1x"
},
......@@ -12,7 +12,7 @@
"value" : "dark"
}
],
"filename" : "chatのコピー.svg",
"filename" : "chat_Dark.svg",
"idiom" : "universal",
"scale" : "1x"
},
......
{
"images" : [
{
"filename" : "chatのコピー2.svg",
"filename" : "chat.svg",
"idiom" : "universal",
"scale" : "1x"
},
......
{
"images" : [
{
"filename" : "navigation_menuのコピー3.svg",
"filename" : "navigation_menu.svg",
"idiom" : "universal",
"scale" : "1x"
},
......@@ -12,7 +12,7 @@
"value" : "dark"
}
],
"filename" : "navigation_menuのコピー.svg",
"filename" : "navigation_menu_Dark.svg",
"idiom" : "universal",
"scale" : "1x"
},
......
{
"images" : [
{
"filename" : "navigation_menuのコピー2.svg",
"filename" : "navigation_menu.svg",
"idiom" : "universal",
"scale" : "1x"
},
......
{
"images" : [
{
"filename" : "navigation_notificationのコピー3.svg",
"filename" : "navigation_notification.svg",
"idiom" : "universal",
"scale" : "1x"
},
......@@ -12,7 +12,7 @@
"value" : "dark"
}
],
"filename" : "navigation_notificationのコピー.svg",
"filename" : "navigation_notification_Dark.svg",
"idiom" : "universal",
"scale" : "1x"
},
......
{
"images" : [
{
"filename" : "navigation_notificationのコピー2.svg",
"filename" : "navigation_notification.svg",
"idiom" : "universal",
"scale" : "1x"
},
......
{
"images" : [
{
"filename" : "navigation_taskのコピー3.svg",
"filename" : "navigation_task.svg",
"idiom" : "universal",
"scale" : "1x"
},
......@@ -12,7 +12,7 @@
"value" : "dark"
}
],
"filename" : "navigation_taskのコピー.svg",
"filename" : "navigation_task_Dark.svg",
"idiom" : "universal",
"scale" : "1x"
},
......
{
"images" : [
{
"filename" : "navigation_taskのコピー2.svg",
"filename" : "navigation_task.svg",
"idiom" : "universal",
"scale" : "1x"
},
......
{
"images" : [
{
"filename" : "閉じる.svg",
"filename" : "close.svg",
"idiom" : "universal",
"scale" : "1x"
},
......
......@@ -9,10 +9,9 @@ import SwiftUI
struct ContentView: View {
@State var isLogin = false//ContentView.LoginCheck()
@EnvironmentObject private var sceneDelegate: SceneDelegate
var selectedTabModel = SelectedTabModel()
var body: some View {
NavigationStack{
MainTabView()
......@@ -33,15 +32,6 @@ struct ContentView: View {
LoginView(isLogin: $isLogin)
})
}
///ログイン認証が必要かチェック
private static func LoginCheck() -> Bool {
let lastUnixTime = Preferences.lastLoginDate_Int64 ?? 0
let lastDate = DateTextLib.UnixTime2Date(lastUnixTime)
let interval = Date.now.timeIntervalSince(lastDate)
return interval < 2592000
}
}
#Preview {
......
......@@ -8,25 +8,6 @@
import Foundation
import CoreLocation
//class RegisteredEca {
// var id: UInt32 = 0
// var isEnable: Bool = false //ECA有効
// var isRunning: Bool = false //ECA実行中
// var name: String = "" //ECA名称
// var swNotice: UInt32 = 6 //ECA通知[NM]
// var swStart: UInt32 = 5 //ECA開始[NM]
// var swFinish: UInt32 = 4 //ECA終了[NM]
// var datetime: String = "" //時刻(UTC ISO8601準拠)
// var color: String = "" //ライン色(ARGB)
// var width: UInt32 = 1 //ライン幅
// var points: [CLLocationCoordinate2D] = []
//
// init?( ecaName: String ) {
// self.name = ecaName
// }
//}
class RegisteredEca: ObservableObject {
@Published var id: UInt32 = 0
@Published var isEnable: Bool = false //ECA有効
......
......@@ -7,14 +7,21 @@
import Foundation
// TODO: サイトのアドレスを変更
#if DEBUG
//MARK: デバッグサーバー用
enum HttpRequestType : String {
case RegisterLogin = "https://ssv-canary-web.azurewebsites.net/applogin"
case SitePolicy = "https://www.google.co.jp/"
case CookiePolicy = "https://www.google.co.jp/2"
case PrivacyPolicy = "https://www.google.co.jp/3"
}
#else
//MARK: 運用サーバー用
enum HttpRequestType : String {
case RegisterLogin = "https://ssv-canary-web.azurewebsites.net/applogin"
case SitePolicy = "https://www.google.co.jp/"
case CookiePolicy = "https://www.google.co.jp/2"
case PrivacyPolicy = "https://www.google.co.jp/3"
}
#endif
......@@ -87,12 +87,12 @@ enum TextInputType{
return constraint
case .UserId:
var constraint = TextConstraint()
constraint.charSet = .Alphanumeric
constraint.textStructure = "^S[a-zA-Z]{1}[0-9]{8}$"
constraint.charSet = .FreeCharset
constraint.textStructure = "^[!-~]{30}$"
var lengthConst = LengthConstraint()
lengthConst.lcType = .OnlyEqual
lengthConst.lcEnableEmpty = false
lengthConst.lcSize.append(10)
lengthConst.lcSize.append(30)
constraint.length = lengthConst
return constraint
}
......
......@@ -16,6 +16,11 @@ enum LoginViewMode: String{
case InputUserName
}
enum AlertType: String {
case loginFailure
case Expired
}
class LoginViewParam: ObservableObject{
@Published var shipId: String = ""
@Published var password: String = ""
......@@ -23,11 +28,15 @@ class LoginViewParam: ObservableObject{
}
struct LoginView: View {
@Binding var isLogin: Bool
@State var isQrRead: Bool = false
@State var viewMode: LoginViewMode = .SelectType
@Binding var isLogin: Bool
@State var isProgressView = false
@State var isAlert = false
@State var alertType: AlertType = .loginFailure
@ObservedObject var scannerViewModel = ScannerViewModel()
@State var loginViewParam = LoginViewParam()
var sessionLogin = SessionLogin()
var body: some View {
ZStack{
......@@ -49,23 +58,31 @@ struct LoginView: View {
Spacer()
if !isProgressView {
switch viewMode{
case .SelectType:
LoginTypeSelectView(isQrRead: $scannerViewModel.isShowing, viewMode: $viewMode)
case .InputIdPassword:
InputIdPassWordView(viewMode: $viewMode, param: $loginViewParam)
case .InputUserName:
InputUserNameView(isLogin: $isLogin, param: $loginViewParam, viewMode: $viewMode)
InputUserNameView(isLogin: $isLogin, param: $loginViewParam, viewMode: $viewMode, isProgressView: $isProgressView, isAlert: $isAlert, alertType: $alertType)
}
} else {
Text("Login Check").padding()
ProgressView()
}
Spacer()
VStack(spacing: 40){
VStack(spacing: 30) {
// TODO: サイトのアドレスを変更
Link("Site policy", destination: URL(string: "https://www.google.co.jp/")!)
Link("Cookie policy", destination: URL(string: "https://www.google.co.jp/")!)
Link("Privacy policy", destination: URL(string: "https://www.google.co.jp/")!)
if !isProgressView {
Link("Site policy", destination: URL(string: HttpRequestType.SitePolicy.rawValue)!)
Link("Cookie policy", destination: URL(string: HttpRequestType.CookiePolicy.rawValue)!)
Link("Privacy policy", destination: URL(string: HttpRequestType.PrivacyPolicy.rawValue)!)
} else {
EmptyView()
}
}
.font(FontStyle.SupplementText.font)
.foregroundColor(ColorSet.Body.color)
......@@ -75,11 +92,64 @@ struct LoginView: View {
.foregroundColor(ColorSet.BodyDescriptiion.color)
}
.padding(.bottom, 30)
.alert(isPresented: $isAlert) {
switch alertType {
case .loginFailure:
return Alert(title: Text("error"),
message: Text("Login failure."),
dismissButton: .default(Text("OK"), action: {viewMode = .SelectType})
)
case .Expired:
return Alert(title: Text("error"),
message: Text("Expired."),
dismissButton: .default(Text("OK"), action: {viewMode = .SelectType})
)
}
}
}
}
.fullScreenCover(isPresented: $scannerViewModel.isShowing, content: {
.fullScreenCover(isPresented: $scannerViewModel.isShowing, onDismiss: {LoginCheckQR()}, content: {
QRReadView(viewMode: .constant(.SelectType), viewModel: scannerViewModel)
})
.onAppear() {
LoginCheck()
}
}
func LoginCheckQR() -> () {
loginViewParam.shipId = Preferences.ShipId
loginViewParam.password = Preferences.ShipPassword
viewMode = .InputUserName
}
func LoginCheck() -> () {
let lastUnixTime = Preferences.lastLoginDate_Int64 ?? 0
let lastDate = DateTextLib.UnixTime2Date(lastUnixTime)
let interval = Date.now.timeIntervalSince(lastDate)
if interval < 2592000 {
if Preferences.ShipId != "" && Preferences.ShipPassword != "" && Preferences.UserName != ""{
isProgressView = true
let login = ReqLogin(Id: Preferences.ShipId, Password: Preferences.ShipPassword)
sessionLogin.RequestLogin(login, completion: responseLogin)
}
}
}
func responseLogin(result: Result<Data, APIError>) {
print(debug: "calld")
switch result {
case .success(let resultData):
let jsonstr = String(data: resultData, encoding: .utf8)!
Preferences.lastLoginDate_Int64 = DateTextLib.Date2UnixTime(date: Date())
isLogin = true
case .failure(let errorCode):
isLogin = false
isAlert = true
alertType = .loginFailure
break
}
isProgressView = false
}
}
......
......@@ -12,8 +12,10 @@ struct InputUserNameView: View {
@Binding var isLogin: Bool
@Binding var param: LoginViewParam
@Binding var viewMode : LoginViewMode
@State private var isAlert = false
@State private var alertType: AlertType = .userNameEmpty
@Binding var isProgressView : Bool
@Binding var isAlert : Bool
@Binding var alertType: AlertType
@State private var isEmptyAlert = false
let itemHPadding: Double = 16
let dialogBottomPadding: Double = 32
let textFieldHeight: Double = 40
......@@ -21,11 +23,6 @@ struct InputUserNameView: View {
let dialogHeight: CGFloat = 250
let dialogWidth = UIScreen.main.bounds.width - 32
enum AlertType {
case userNameEmpty
case loginFailure
}
var body: some View {
HStack {
Spacer()
......@@ -60,20 +57,15 @@ struct InputUserNameView: View {
}
.frame(height: inputAreaHeight)
Spacer()
Button(action: {
if param.userName.isEmpty {
isAlert = true
alertType = .userNameEmpty
isEmptyAlert = true
} 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_"
isProgressView = true
let login = ReqLogin(Id: param.shipId, Password: param.password)
sessionLogin.RequestLogin(login, completion: responseLogin)
}
......@@ -84,19 +76,10 @@ struct InputUserNameView: View {
.foregroundColor(ColorSet.ButtonText.color)
.background(ColorSet.PrimaryActiveIcon.color)
})
.alert(isPresented: $isAlert) {
switch alertType {
case .userNameEmpty:
.alert(isPresented: $isEmptyAlert) {
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)
......@@ -113,15 +96,16 @@ struct InputUserNameView: View {
print(debug: "calld")
switch result {
case .success(let resultData):
let jsonstr = String(data: resultData, encoding: .utf8)!
let serverSession = ServerSession()
let resjson = serverSession.fromJSON(resultData: resultData, resltType: ResLogin.self)
Preferences.ShipId = param.shipId
Preferences.ShipPassword = param.password
Preferences.lastLoginDate_Int64 = DateTextLib.Date2UnixTime(date: Date())
isProgressView = false
isLogin = true
isAlert = false
case .failure(let errorCode):
param.shipId = ""
param.password = ""
isProgressView = false
isLogin = false
isAlert = true
alertType = .loginFailure
......@@ -131,5 +115,5 @@ struct InputUserNameView: View {
}
#Preview {
InputUserNameView(isLogin: .constant(false), param: .constant(LoginViewParam()), viewMode: .constant(.InputIdPassword))
InputUserNameView(isLogin: .constant(false), param: .constant(LoginViewParam()), viewMode: .constant(.InputIdPassword), isProgressView: .constant(false), isAlert: .constant(false), alertType: .constant(.loginFailure))
}
......@@ -17,7 +17,7 @@ struct LoginTypeSelectView: View{
Button(action: {
isQrRead = true
}, label: {
Text("QRを読み込む")
Text("Read the QR code")
.frame(maxWidth: .infinity)
.frame(height: 50)
.foregroundColor(ColorSet.ButtonText.color)
......@@ -29,7 +29,7 @@ struct LoginTypeSelectView: View{
print("change mode")
viewMode = .InputIdPassword
}, label: {
Text("Ship ID/Passwordを入力")
Text("Enter Ship ID / Password")
.underline()
.font(FontStyle.SupplementText.font)
.foregroundColor(ColorSet.ToggleBackGround.color)
......
......@@ -64,10 +64,11 @@ struct QrCodeScannerView: UIViewRepresentable {
uiView.layer.addSublayer(previewLayer)
uiView.previewLayer = previewLayer
DispatchQueue.global(qos: .background).async {
session.startRunning()
}
}
}
}
func makeUIView(context: UIViewRepresentableContext<QrCodeScannerView>) -> QrCodeScannerView.UIViewType {
......
......@@ -6,19 +6,30 @@
//
import Foundation
import SwiftUI
class ScannerViewModel: ObservableObject {
/// QRコードを読み取る時間間隔
let scanInterval: Double = 1.0
let scanInterval: Double = 1.0 /// QRコードを読み取る時間間隔
@Published var lastQrCode: String = "QRコード"
@Published var isShowing: Bool = false
/// QRコード読み取り時に実行される。
func onFoundQrCode(_ code: String) {
do {
self.lastQrCode = code
isShowing = false
let decoder = JSONDecoder()
let jsonData = self.lastQrCode.data(using: .utf8)!
let resjson: ReqLogin = try decoder.decode(ReqLogin.self, from: jsonData)
Preferences.ShipId = resjson.Id
Preferences.ShipPassword = resjson.Password
Preferences.lastLoginDate_Int64 = DateTextLib.Date2UnixTime(date: Date())
} catch {
print(debug: "decodeエラー")
Preferences.ShipId = ""
Preferences.ShipPassword = ""
}
isShowing = false
}
}
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