Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
likorn
/
vocabulary_notebook
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7bd71fc9
authored
Nov 18, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Now it's possible to sign up with either a username or an email
parent
d0c5f749
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
33 deletions
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/LogInActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/utils/ActivityUtil.kt
app/src/main/java/com/paktalin/vocabularynotebook/utils/UserManager.kt
app/src/main/res/values/strings.xml
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/LogInActivity.kt
View file @
7bd71fc9
...
@@ -8,8 +8,6 @@ import com.paktalin.vocabularynotebook.utils.*
...
@@ -8,8 +8,6 @@ import com.paktalin.vocabularynotebook.utils.*
import
kotlinx.android.synthetic.main.activity_log_in.*
import
kotlinx.android.synthetic.main.activity_log_in.*
class
LogInActivity
:
AppCompatActivity
()
{
class
LogInActivity
:
AppCompatActivity
()
{
private
var
email
:
String
?
=
null
private
var
password
:
String
?
=
null
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
...
@@ -24,25 +22,21 @@ class LogInActivity : AppCompatActivity() {
...
@@ -24,25 +22,21 @@ class LogInActivity : AppCompatActivity() {
}
}
fun
login
()
{
fun
login
()
{
processUser
(
resources
.
getString
(
R
.
string
.
toast_incorrect_username_password
))
{
val
(
username
,
password
)
=
getUsernameAndPassword
()
if
(
fieldsNotEmpty
(
username
,
password
,
this
))
addProgressBar
()
mLogIn
(
mLogIn
(
{
removeProgressBar
()
},
{
removeProgressBar
(
supportFragmentManager
)
},
{
startUserActivity
()
},
{
startUserActivity
()
},
{
showToastFailure
()
},
{
shortToast
(
this
@LogInActivity
,
getString
(
R
.
string
.
toast_auth_failed
))
},
email
!!
,
password
!!
)
username
,
password
)
}
}
private
fun
signUp
()
{
processUser
(
resources
.
getString
(
R
.
string
.
toast_username_characters
))
{
mSignUp
(
this
,
email
!!
,
password
!!
)
}
}
}
private
fun
processUser
(
invalidUsername
:
String
,
authAction
:
()
->
Unit
)
{
private
fun
signUp
()
{
email
=
etEmail
!!
.
text
.
toString
()
val
(
username
,
password
)
=
getUsernameAndPassword
()
password
=
etPassword
!!
.
text
.
toString
()
if
(
fieldsNotEmpty
(
username
,
password
,
this
)
&&
validUsername
(
username
,
this
))
{
if
(
validInput
(
email
!!
,
password
!!
,
this
,
invalidUsername
))
{
addProgressBar
()
addProgressBar
()
authAction
(
)
mSignUp
(
this
,
username
,
password
)
}
}
}
}
...
@@ -55,11 +49,7 @@ class LogInActivity : AppCompatActivity() {
...
@@ -55,11 +49,7 @@ class LogInActivity : AppCompatActivity() {
com
.
paktalin
.
vocabularynotebook
.
utils
.
addProgressBar
(
supportFragmentManager
,
R
.
id
.
container_login
)
com
.
paktalin
.
vocabularynotebook
.
utils
.
addProgressBar
(
supportFragmentManager
,
R
.
id
.
container_login
)
}
}
private
fun
removeProgressBar
()
{
private
fun
getUsernameAndPassword
()
=
Pair
(
etEmail
!!
.
text
.
toString
(),
etPassword
!!
.
text
.
toString
())
com
.
paktalin
.
vocabularynotebook
.
utils
.
removeProgressBar
(
supportFragmentManager
)
}
private
fun
showToastFailure
()
{
shortToast
(
this
@LogInActivity
,
getString
(
R
.
string
.
toast_auth_failed
))
}
companion
object
{
private
val
TAG
=
"VN/"
+
LogInActivity
::
class
.
simpleName
}
companion
object
{
private
val
TAG
=
"VN/"
+
LogInActivity
::
class
.
simpleName
}
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/utils/ActivityUtil.kt
View file @
7bd71fc9
...
@@ -5,12 +5,11 @@ import android.content.Intent
...
@@ -5,12 +5,11 @@ import android.content.Intent
import
android.os.Bundle
import
android.os.Bundle
import
android.support.v4.app.Fragment
import
android.support.v4.app.Fragment
import
android.support.v4.app.FragmentManager
import
android.support.v4.app.FragmentManager
import
android.text.TextUtils
import
android.view.View
import
android.view.View
import
android.widget.Toast
import
android.widget.Toast
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.ui.fragments.ProgressFragment
import
com.paktalin.vocabularynotebook.ui.fragments.ProgressFragment
import
org.apache.commons.lang3.StringUtils
.containsOnly
import
org.apache.commons.lang3.StringUtils
val
progressFragment
:
Fragment
=
ProgressFragment
()
val
progressFragment
:
Fragment
=
ProgressFragment
()
...
@@ -31,20 +30,21 @@ fun removeProgressBar(fragmentManager: FragmentManager) {
...
@@ -31,20 +30,21 @@ fun removeProgressBar(fragmentManager: FragmentManager) {
removeFragment
(
fragmentManager
,
progressFragment
)
removeFragment
(
fragmentManager
,
progressFragment
)
}
}
fun
validInput
(
username
:
String
,
password
:
String
,
context
:
Context
,
invalidUsername
:
String
):
Boolean
{
fun
fieldsNotEmpty
(
username
:
String
,
password
:
String
,
context
:
Context
):
Boolean
{
if
(
TextUtils
.
isEmpty
(
username
)
||
TextUtils
.
isEmpty
(
password
))
{
if
(
username
.
isEmpty
()
||
password
.
isEmpty
(
))
{
shortToast
(
context
,
context
.
resources
.
getString
(
R
.
string
.
toast_enter_username_password
))
shortToast
(
context
,
context
.
resources
.
getString
(
R
.
string
.
toast_enter_username_password
))
return
false
return
false
}
}
else
if
(!
appropriateCharacters
(
username
))
{
shortToast
(
context
,
invalidUsername
)
return
false
}
return
true
return
true
}
}
private
fun
appropriateCharacters
(
username
:
String
):
Boolean
{
fun
validUsername
(
username
:
String
,
context
:
Context
):
Boolean
{
return
containsOnly
(
username
.
toLowerCase
(),
"abcdefghijklmnopqrstuvwxyz0123456789-_."
)
return
if
(
StringUtils
.
containsOnly
(
username
.
toLowerCase
(),
"abcdefghijklmnopqrstuvwxyz0123456789-_."
))
true
else
{
shortToast
(
context
,
context
.
resources
.
getString
(
R
.
string
.
toast_invalid_username
))
false
}
}
}
fun
shortToast
(
context
:
Context
,
text
:
String
)
{
fun
shortToast
(
context
:
Context
,
text
:
String
)
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/utils/UserManager.kt
View file @
7bd71fc9
package
com.paktalin.vocabularynotebook.utils
package
com.paktalin.vocabularynotebook.utils
import
android.util.Patterns
import
com.google.firebase.auth.FirebaseAuth
import
com.google.firebase.auth.FirebaseAuth
import
com.google.firebase.auth.FirebaseUser
import
com.google.firebase.auth.FirebaseUser
import
com.paktalin.vocabularynotebook.R
import
com.paktalin.vocabularynotebook.R
...
@@ -28,6 +29,10 @@ fun mLogIn(onComplete: () -> Unit, onSuccess: () -> Unit, onFailure: () -> Unit,
...
@@ -28,6 +29,10 @@ fun mLogIn(onComplete: () -> Unit, onSuccess: () -> Unit, onFailure: () -> Unit,
}
}
}
}
private
fun
isEmail
(
string
:
String
)
=
Patterns
.
EMAIL_ADDRESS
.
matcher
(
string
).
matches
()
fun
mSignUp
(
activity
:
LogInActivity
,
username
:
String
,
password
:
String
)
{
fun
mSignUp
(
activity
:
LogInActivity
,
username
:
String
,
password
:
String
)
{
mAuth
!!
.
createUserWithEmailAndPassword
(
email
(
username
),
password
)
mAuth
!!
.
createUserWithEmailAndPassword
(
email
(
username
),
password
)
.
addOnCompleteListener
{
removeProgressBar
(
activity
.
supportFragmentManager
)
}
.
addOnCompleteListener
{
removeProgressBar
(
activity
.
supportFragmentManager
)
}
...
@@ -52,6 +57,10 @@ fun mLogOut() {
...
@@ -52,6 +57,10 @@ fun mLogOut() {
}
}
private
fun
email
(
username
:
String
):
String
{
private
fun
email
(
username
:
String
):
String
{
return
if
(
isEmail
(
username
))
username
else
{
val
dummyDomain
=
"@wordbook.com"
val
dummyDomain
=
"@wordbook.com"
return
username
.
toLowerCase
()
+
dummyDomain
username
.
toLowerCase
()
+
dummyDomain
}
}
}
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
7bd71fc9
...
@@ -24,6 +24,6 @@
...
@@ -24,6 +24,6 @@
<string
name=
"toast_update_word_failed"
>
Couldn\'t update 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_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_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_
invalid_username
"
>
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>
<string
name=
"toast_incorrect_username_password"
>
Username or password is incorrect
</string>
</resources>
</resources>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment