add more display errors

auth_manage
Emre KARTAL 2 years ago
parent e0954cba47
commit 5e41093f7e

@ -255,6 +255,11 @@ struct CreationBet: View {
) )
.frame(width: 250, height: 38) .frame(width: 250, height: 38)
.foregroundColor(.black) .foregroundColor(.black)
.onChange(of: response) { newValue in
if newValue.count > 20 {
response = String(newValue.prefix(20))
}
}
Button(action: { Button(action: {

@ -65,6 +65,11 @@ struct Register: View {
.stroke(AllinColor.StrokeGrayColor, lineWidth: 1) .stroke(AllinColor.StrokeGrayColor, lineWidth: 1)
) )
.padding(.bottom, 8) .padding(.bottom, 8)
.onChange(of: username) { newValue in
if newValue.count > 25 {
username = String(newValue.prefix(25))
}
}
} }
VStack { VStack {
@ -84,6 +89,11 @@ struct Register: View {
.stroke(AllinColor.StrokeGrayColor, lineWidth: 1) .stroke(AllinColor.StrokeGrayColor, lineWidth: 1)
) )
.padding(.bottom, 8) .padding(.bottom, 8)
.onChange(of: email) { newValue in
if newValue.count > 50 {
email = String(newValue.prefix(50))
}
}
} }
VStack { VStack {
@ -201,29 +211,35 @@ struct Register: View {
func register(email: String, username: String, password: String, confirmPassword: String) { func register(email: String, username: String, password: String, confirmPassword: String) {
cleanError() cleanError()
if (password != confirmPassword) { if password != confirmPassword {
errorPassword = true errorPassword = true
errorPasswordMessage = "Les mots de passes doivent être identiques." errorPasswordMessage = "Les mots de passes doivent être identiques."
return return
} }
if (username.isEmpty) { if username.isEmpty {
errorUsername = true errorUsername = true
errorUsernameMessage = "Le pseudo ne peut pas être vide." errorUsernameMessage = "Le pseudo ne peut pas être vide."
return return
} }
if (email.isEmpty) { if email.isEmpty {
errorMail = true errorMail = true
errorMailMessage = "Le mail ne peut pas être vide." errorMailMessage = "Le mail ne peut pas être vide."
return return
} }
if (password.isEmpty || confirmPassword.isEmpty) { if password.isEmpty || confirmPassword.isEmpty {
errorPassword = true errorPassword = true
errorPasswordMessage = "Veuillez renseigner le mot de passe sur les deux champs." errorPasswordMessage = "Veuillez renseigner le mot de passe sur les deux champs."
return return
} }
if isValidEmail(email: email) {
errorMail = true
errorMailMessage = "L'adresse e-mail n'est pas valide."
return
}
let api = AuthService() let api = AuthService()
api.register(email: email, password: password, username: username) { statusCode in api.register(email: email, password: password, username: username) { statusCode in
DispatchQueue.main.async { 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() { func cleanError() {
errorPassword = false errorPassword = false
errorMail = false errorMail = false

Loading…
Cancel
Save