1
0
mirror of https://github.com/etesync/android synced 2024-12-23 15:18:14 +00:00

Signup: add field validations.

We have centralised validation in the server, but it's not yet
exposed in etebase-java so we have to do it here too for now.
This commit is contained in:
Tom Hacohen 2020-10-07 13:49:43 +03:00
parent afe7f12a9d
commit 12d25a7785
2 changed files with 5 additions and 4 deletions

View File

@ -79,7 +79,7 @@ class SignupFragment(private val initialUsername: String?, private val initialPa
createAccount.setOnClickListener { createAccount.setOnClickListener {
val credentials = validateData() val credentials = validateData()
if (credentials != null) { if (credentials != null) {
SignupDoFragment(credentials).show(fragmentManager!!, null) SignupDoFragment(credentials).show(requireFragmentManager(), null)
} }
} }
@ -102,7 +102,8 @@ class SignupFragment(private val initialUsername: String?, private val initialPa
var valid = true var valid = true
val userName = editUserName.editText?.text.toString() val userName = editUserName.editText?.text.toString()
if (userName.isEmpty()) { // FIXME: this validation should only be done in the server, we are doing it here until the Java library supports field errors
if ((userName.length < 6) || (!userName.matches(Regex("""^[\w.-]+$""")))) {
editUserName.error = getString(R.string.login_username_error) editUserName.error = getString(R.string.login_username_error)
valid = false valid = false
} else { } else {
@ -118,7 +119,7 @@ class SignupFragment(private val initialUsername: String?, private val initialPa
} }
val password = editPassword.editText?.text.toString() val password = editPassword.editText?.text.toString()
if (password.isEmpty()) { if (password.length < 8) {
editPassword.error = getString(R.string.signup_password_restrictions) editPassword.error = getString(R.string.signup_password_restrictions)
valid = false valid = false
} else { } else {

View File

@ -230,7 +230,7 @@
<!-- AddAccountActivity --> <!-- AddAccountActivity -->
<string name="login_title">Add account</string> <string name="login_title">Add account</string>
<string name="login_username">Username</string> <string name="login_username">Username</string>
<string name="login_username_error">Valid username required</string> <string name="login_username_error">Username should be at least 6 characters long and consist of only letters, digits and ./-/_.</string>
<string name="login_email_address">Email</string> <string name="login_email_address">Email</string>
<string name="login_email_address_error">Valid email required</string> <string name="login_email_address_error">Valid email required</string>
<string name="login_password">Password</string> <string name="login_password">Password</string>