Commit d0c5f749 by Paktalin

Changing registration procedure in progress

parent b8cead78
......@@ -25,7 +25,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -32,6 +32,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation 'com.android.support:multidex:1.0.3'
implementation 'org.apache.commons:commons-lang3:3.6'
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-database:16.0.1'
......
......@@ -24,21 +24,23 @@ class LogInActivity : AppCompatActivity() {
}
fun login() {
processUser {
processUser(resources.getString(R.string.toast_incorrect_username_password)) {
mLogIn(
{ removeProgressBar() },
{ startUserActivity() },
{ showToastFailure() },
email!!, password!!)
} }
}
}
private fun signUp() { processUser { mSignUp(this, email!!, password!!) } }
private fun signUp() { processUser(resources.getString(R.string.toast_username_characters)) { mSignUp(this, email!!, password!!) }
}
private fun processUser(authAction: () -> Unit) {
private fun processUser(invalidUsername:String, authAction: () -> Unit) {
email = etEmail!!.text.toString()
password = etPassword!!.text.toString()
if (fieldsNotEmpty(email!!, password!!, "Please, enter email and password", this)) {
if (validInput(email!!, password!!, this, invalidUsername)) {
addProgressBar()
authAction()
}
......
......@@ -6,13 +6,11 @@ import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.text.TextUtils
import android.view.Menu
import android.view.View
import android.widget.Toast
import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.ui.fragments.ProgressFragment
import kotlinx.android.synthetic.main.content_main.*
import kotlinx.android.synthetic.main.fragment_editable_word.view.*
import org.apache.commons.lang3.StringUtils.containsOnly
val progressFragment: Fragment = ProgressFragment()
......@@ -33,14 +31,22 @@ fun removeProgressBar(fragmentManager: FragmentManager) {
removeFragment(fragmentManager, progressFragment)
}
fun fieldsNotEmpty(text1: String, text2: String, toastMessage: String, context: Context): Boolean {
if (TextUtils.isEmpty(text1) || TextUtils.isEmpty(text2)) {
shortToast(context, toastMessage)
fun validInput(username: String, password: String, context: Context, invalidUsername:String): Boolean {
if(TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {
shortToast(context, context.resources.getString(R.string.toast_enter_username_password))
return false
}
else if (!appropriateCharacters(username)) {
shortToast(context, invalidUsername)
return false
}
return true
}
private fun appropriateCharacters(username: String): Boolean {
return containsOnly(username.toLowerCase(), "abcdefghijklmnopqrstuvwxyz0123456789-_.")
}
fun shortToast(context: Context, text: String) {
Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
}
......
......@@ -15,8 +15,8 @@ fun mDeleteUser(user: FirebaseUser) {
}
fun mLogIn(onComplete: () -> Unit, onSuccess: () -> Unit, onFailure: () -> Unit,
email: String, password: String) {
mAuth!!.signInWithEmailAndPassword(email, password)
username: String, password: String) {
mAuth!!.signInWithEmailAndPassword(email(username), password)
.addOnCompleteListener { onComplete() }
.addOnSuccessListener {
Log.d(TAG, "Successfully signed in")
......@@ -28,8 +28,8 @@ fun mLogIn(onComplete: () -> Unit, onSuccess: () -> Unit, onFailure: () -> Unit,
}
}
fun mSignUp(activity: LogInActivity, email: String, password: String) {
mAuth!!.createUserWithEmailAndPassword(email, password)
fun mSignUp(activity: LogInActivity, username: String, password: String) {
mAuth!!.createUserWithEmailAndPassword(email(username), password)
.addOnCompleteListener { removeProgressBar(activity.supportFragmentManager) }
.addOnSuccessListener {
Log.d(TAG, "Successfully signed up a new user")
......@@ -49,4 +49,9 @@ fun mUserLoggedIn(): Boolean {
fun mLogOut() {
mAuth!!.signOut()
Log.i(TAG, "User logged out")
}
private fun email(username: String): String {
val dummyDomain = "@wordbook.com"
return username.toLowerCase() + dummyDomain
}
\ No newline at end of file
......@@ -23,4 +23,7 @@
<string name="toast_new_word_fail">Couldn\'t add the word</string>
<string name="toast_update_word_failed">Couldn\'t update the word</string>
<string name="toast_successful_sign_up">Congratulations! You can now access your vocabulary from any device</string>
<string name="toast_enter_username_password">Please, enter username and password</string>
<string name="toast_username_characters">Please, create a username using letters a–z, numbers 0–9 and characters -_.</string>
<string name="toast_incorrect_username_password">Username or password is incorrect</string>
</resources>
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 sign in to comment