File tree Expand file tree Collapse file tree 3 files changed +14
-3
lines changed
matrix-sdk-android/src/main/java/org/matrix/android/sdk
vector/src/main/java/im/vector/app/core/extensions Expand file tree Collapse file tree 3 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 16
16
17
17
package org.matrix.android.sdk.api.extensions
18
18
19
+ import java.util.regex.Pattern
20
+
21
+ const val emailPattern = " ^[a-zA-Z0-9_!#\$ %&'*+/=?`{|}~^-]+(?:\\ .[a-zA-Z0-9_!#\$ %&'*+/=?`{|}~^-]+)*@[a-zA-Z0-9-]+(?:\\ .[a-zA-Z0-9-]+)*\$ "
22
+ val emailAddress: Pattern = Pattern .compile(emailPattern)
23
+
19
24
fun CharSequence.ensurePrefix (prefix : CharSequence ): CharSequence {
20
25
return when {
21
26
startsWith(prefix) -> this
22
27
else -> " $prefix$this "
23
28
}
24
29
}
25
30
31
+ /* *
32
+ * Check if a CharSequence is an email.
33
+ */
34
+ fun CharSequence.isEmail () = emailAddress.matcher(this ).matches()
35
+
26
36
/* *
27
37
* Append a new line and then the provided string.
28
38
*/
Original file line number Diff line number Diff line change 16
16
17
17
package org.matrix.android.sdk.internal.auth.login
18
18
19
- import android.util.Patterns
20
19
import org.matrix.android.sdk.api.auth.LoginType
21
20
import org.matrix.android.sdk.api.auth.login.LoginProfileInfo
22
21
import org.matrix.android.sdk.api.auth.login.LoginWizard
23
22
import org.matrix.android.sdk.api.auth.registration.RegisterThreePid
23
+ import org.matrix.android.sdk.api.extensions.isEmail
24
24
import org.matrix.android.sdk.api.session.Session
25
25
import org.matrix.android.sdk.api.util.JsonDict
26
26
import org.matrix.android.sdk.internal.auth.AuthAPI
@@ -59,7 +59,7 @@ internal class DefaultLoginWizard(
59
59
initialDeviceName : String ,
60
60
deviceId : String?
61
61
): Session {
62
- val loginParams = if (Patterns . EMAIL_ADDRESS .matcher( login).matches ()) {
62
+ val loginParams = if (login.isEmail ()) {
63
63
PasswordLoginParams .thirdPartyIdentifier(
64
64
medium = ThreePidMedium .EMAIL ,
65
65
address = login,
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import com.google.i18n.phonenumbers.NumberParseException
21
21
import com.google.i18n.phonenumbers.PhoneNumberUtil
22
22
import org.matrix.android.sdk.api.MatrixPatterns
23
23
import org.matrix.android.sdk.api.extensions.ensurePrefix
24
+ import org.matrix.android.sdk.api.extensions.isEmail
24
25
25
26
fun Boolean.toOnOff () = if (this ) " ON" else " OFF"
26
27
@@ -29,7 +30,7 @@ inline fun <T> T.ooi(block: (T) -> Unit): T = also(block)
29
30
/* *
30
31
* Check if a CharSequence is an email.
31
32
*/
32
- fun CharSequence.isEmail () = Patterns . EMAIL_ADDRESS .matcher( this ).matches ()
33
+ fun CharSequence.isEmail () = this .isEmail ()
33
34
34
35
fun CharSequence.isMatrixId () = MatrixPatterns .isUserId(this .toString())
35
36
You can’t perform that action at this time.
0 commit comments