From 5e41093f7e38029b3a46e9f7dda7f3ce0403799a Mon Sep 17 00:00:00 2001 From: "emre.kartal" Date: Thu, 12 Oct 2023 08:47:03 +0200 Subject: [PATCH] add more display errors --- .../allin/Screens/CreationBetScreen.swift | 5 +++ .../allin/allin/Screens/RegisterScreen.swift | 33 ++++++++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Sources/allin/allin/Screens/CreationBetScreen.swift b/Sources/allin/allin/Screens/CreationBetScreen.swift index f2f6b22..b7b85df 100644 --- a/Sources/allin/allin/Screens/CreationBetScreen.swift +++ b/Sources/allin/allin/Screens/CreationBetScreen.swift @@ -255,6 +255,11 @@ struct CreationBet: View { ) .frame(width: 250, height: 38) .foregroundColor(.black) + .onChange(of: response) { newValue in + if newValue.count > 20 { + response = String(newValue.prefix(20)) + } + } Button(action: { diff --git a/Sources/allin/allin/Screens/RegisterScreen.swift b/Sources/allin/allin/Screens/RegisterScreen.swift index daebb85..5628870 100644 --- a/Sources/allin/allin/Screens/RegisterScreen.swift +++ b/Sources/allin/allin/Screens/RegisterScreen.swift @@ -65,6 +65,11 @@ struct Register: View { .stroke(AllinColor.StrokeGrayColor, lineWidth: 1) ) .padding(.bottom, 8) + .onChange(of: username) { newValue in + if newValue.count > 25 { + username = String(newValue.prefix(25)) + } + } } VStack { @@ -84,6 +89,11 @@ struct Register: View { .stroke(AllinColor.StrokeGrayColor, lineWidth: 1) ) .padding(.bottom, 8) + .onChange(of: email) { newValue in + if newValue.count > 50 { + email = String(newValue.prefix(50)) + } + } } VStack { @@ -201,29 +211,35 @@ struct Register: View { func register(email: String, username: String, password: String, confirmPassword: String) { cleanError() - if (password != confirmPassword) { + if password != confirmPassword { errorPassword = true errorPasswordMessage = "Les mots de passes doivent être identiques." return } - if (username.isEmpty) { + if username.isEmpty { errorUsername = true errorUsernameMessage = "Le pseudo ne peut pas être vide." return } - if (email.isEmpty) { + if email.isEmpty { errorMail = true errorMailMessage = "Le mail ne peut pas être vide." return } - if (password.isEmpty || confirmPassword.isEmpty) { + if password.isEmpty || confirmPassword.isEmpty { errorPassword = true errorPasswordMessage = "Veuillez renseigner le mot de passe sur les deux champs." return } + if isValidEmail(email: email) { + errorMail = true + errorMailMessage = "L'adresse e-mail n'est pas valide." + return + } + let api = AuthService() api.register(email: email, password: password, username: username) { statusCode in DispatchQueue.main.async { @@ -236,6 +252,15 @@ struct Register: View { } } + func isValidEmail(email: String) -> Bool + { + if(email.range(of:"^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$", options: .regularExpression) != nil) { + return false + } else { + return true + } + } + func cleanError() { errorPassword = false errorMail = false