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
f80abd62
authored
Sep 06, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Linked users to database
parent
6d0def63
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
143 additions
and
36 deletions
app/build.gradle
app/src/main/AndroidManifest.xml
app/src/main/java/com/paktalin/vocabularynotebook/SignInActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/User.java
app/src/main/java/com/paktalin/vocabularynotebook/UserActivity.java
app/src/main/java/com/paktalin/vocabularynotebook/UserActivity.kt
app/src/main/res/layout/activity_user.xml
app/src/main/res/values/dimens.xml
app/src/main/res/values/strings.xml
app/build.gradle
View file @
f80abd62
...
...
@@ -28,7 +28,9 @@ dependencies {
implementation
'com.google.firebase:firebase-database:16.0.1'
implementation
'com.google.firebase:firebase-auth:16.0.3'
implementation
'com.firebase:firebase-client-android:2.3.1'
implementation
'com.google.firebase:firebase-firestore:17.1.0'
implementation
'com.android.support:support-annotations:28.0.0-rc02'
testImplementation
'junit:junit:4.12'
androidTestImplementation
'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
...
...
app/src/main/AndroidManifest.xml
View file @
f80abd62
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"com.paktalin.vocabularynotebook"
>
package=
"com.paktalin.vocabularynotebook"
>
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission
android:name=
"android.permission.GET_ACCOUNTS"
/>
<uses-permission
android:name=
"android.permission.READ_PROFILE"
/>
<uses-permission
android:name=
"android.permission.READ_CONTACTS"
/>
<application
android:name=
".VocabularyApplication"
android:allowBackup=
"true"
android:icon=
"@mipmap/ic_launcher"
android:label=
"@string/app_name"
android:roundIcon=
"@mipmap/ic_launcher_round"
android:supportsRtl=
"true"
android:theme=
"@style/AppTheme"
android:name=
".VocabularyApplication"
>
<activity
android:name=
".UserActivity"
/>
android:theme=
"@style/AppTheme"
>
<activity
android:name=
".UserActivity"
/>
<activity
android:name=
".SignInActivity"
>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
...
...
app/src/main/java/com/paktalin/vocabularynotebook/SignInActivity.kt
View file @
f80abd62
...
...
@@ -9,7 +9,9 @@ import android.widget.Toast
import
com.google.android.gms.signin.SignIn
import
com.google.firebase.auth.FirebaseAuth
import
com.google.firebase.auth.FirebaseUser
import
kotlinx.android.synthetic.main.activity_sign_in.*
import
com.google.firebase.firestore.FirebaseFirestore
class
SignInActivity
:
AppCompatActivity
()
{
...
...
@@ -37,7 +39,10 @@ class SignInActivity : AppCompatActivity() {
if
(
fieldsNotEmpty
(
email
,
password
))
{
mAuth
!!
.
signInWithEmailAndPassword
(
email
,
password
)
.
addOnCompleteListener
{
task
->
if
(
task
.
isSuccessful
)
startUserActivity
()
if
(
task
.
isSuccessful
)
{
Log
.
d
(
TAG
,
"Successfully signed in"
)
startUserActivity
()
}
else
{
Log
.
w
(
TAG
,
"signInWithEmail:failure"
,
task
.
exception
)
Toast
.
makeText
(
this
@SignInActivity
,
"Authentication failed."
,
...
...
@@ -45,7 +50,6 @@ class SignInActivity : AppCompatActivity() {
}
}
}
}
private
fun
signUp
()
{
...
...
@@ -53,21 +57,26 @@ class SignInActivity : AppCompatActivity() {
val
password
=
etPassword
!!
.
text
.
toString
()
if
(
fieldsNotEmpty
(
email
,
password
))
{
//todo check if the password is good
// todo verify email
mAuth
!!
.
createUserWithEmailAndPassword
(
email
,
password
)
.
addOnCompleteListener
(
this
)
{
task
->
if
(
task
.
isSuccessful
)
startUserActivity
()
if
(
task
.
isSuccessful
)
{
Log
.
d
(
TAG
,
"Successfully signed up a new user"
)
addNewUserToDb
(
mAuth
!!
.
currentUser
!!
)
startUserActivity
()
}
else
{
Log
.
w
(
TAG
,
"createUserWithEmail:failure"
,
task
.
exception
)
Toast
.
makeText
(
this
@SignInActivity
,
"Authentication failed."
,
Toast
.
LENGTH_SHORT
).
show
()
}
}
}
}
private
fun
startUserActivity
()
{
Log
.
d
(
TAG
,
"Signed in successfully"
)
;
Log
.
d
(
TAG
,
"Signed in successfully"
)
val
userActivityIntent
=
Intent
(
this
@SignInActivity
,
UserActivity
::
class
.
java
)
startActivity
(
userActivityIntent
)
}
...
...
@@ -80,6 +89,16 @@ class SignInActivity : AppCompatActivity() {
return
true
}
private
fun
addNewUserToDb
(
newUser
:
FirebaseUser
)
{
//todo add condition to writing to the db in Firebase Console (request.auth.uid)
val
db
=
FirebaseFirestore
.
getInstance
()
db
.
collection
(
"users"
).
document
(
newUser
.
uid
).
set
(
User
(
newUser
.
email
))
.
addOnCompleteListener
({
task
->
if
(
task
.
isSuccessful
)
Log
.
i
(
TAG
,
"Successfully added user to the collection"
)
else
Log
.
w
(
TAG
,
"addUser:failure"
,
task
.
exception
)
})
}
companion
object
{
private
val
TAG
=
"VN/"
+
SignIn
::
class
.
simpleName
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/User.java
0 → 100644
View file @
f80abd62
package
com
.
paktalin
.
vocabularynotebook
;
public
class
User
{
private
String
email
,
name
;
User
(
String
email
)
{
this
.
email
=
email
;
}
public
String
getEmail
()
{
return
email
;
}
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
}
app/src/main/java/com/paktalin/vocabularynotebook/UserActivity.java
deleted
100644 → 0
View file @
6d0def63
package
com
.
paktalin
.
vocabularynotebook
;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.support.v7.app.AppCompatActivity
;
import
com.google.firebase.auth.FirebaseAuth
;
public
class
UserActivity
extends
AppCompatActivity
{
private
static
final
String
TAG
=
"VN/"
+
UserActivity
.
class
.
getSimpleName
();
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_user
);
}
@Override
protected
void
onDestroy
()
{
super
.
onDestroy
();
FirebaseAuth
.
getInstance
().
signOut
();
}
}
app/src/main/java/com/paktalin/vocabularynotebook/UserActivity.kt
0 → 100644
View file @
f80abd62
package
com.paktalin.vocabularynotebook
import
android.annotation.SuppressLint
import
android.os.Bundle
import
android.support.v7.app.AppCompatActivity
import
android.util.Log
import
com.google.android.gms.tasks.OnCompleteListener
import
com.google.firebase.auth.FirebaseAuth
import
com.google.firebase.firestore.DocumentReference
import
com.google.firebase.firestore.FirebaseFirestore
import
kotlinx.android.synthetic.main.activity_user.*
class
UserActivity
:
AppCompatActivity
()
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_user
)
printUserData
()
}
override
fun
onDestroy
()
{
super
.
onDestroy
()
FirebaseAuth
.
getInstance
().
signOut
()
}
@SuppressLint
(
"SetTextI18n"
)
private
fun
printUserData
()
{
val
userId
=
FirebaseAuth
.
getInstance
().
currentUser
!!
.
uid
Log
.
d
(
TAG
,
"retrieved userId: $userId"
)
val
db
=
FirebaseFirestore
.
getInstance
()
db
.
collection
(
"users"
).
document
(
userId
).
get
().
addOnSuccessListener
{
task
->
val
email
=
task
.
get
(
"email"
).
toString
()
tvUserData
.
text
=
"email: $email"
}
}
companion
object
{
private
val
TAG
=
"VN/"
+
UserActivity
::
class
.
simpleName
}
}
app/src/main/res/layout/activity_user.xml
View file @
f80abd62
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<TextView
android:id=
"@+id/t
extView
"
android:id=
"@+id/t
vCongrats
"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Congratulations! You have successfully logged in!"
app:layout_constraintBottom_toTopOf=
"@+id/tvUserData"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintHorizontal_bias=
"0.5"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintVertical_chainStyle=
"packed"
/>
<TextView
android:id=
"@+id/tvUserData"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginBottom=
"8dp"
android:layout_marginEnd=
"8dp"
android:layout_marginLeft=
"8dp"
android:layout_marginRight=
"8dp"
android:layout_marginStart=
"8dp"
android:layout_marginTop=
"8dp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintHorizontal_bias=
"0.5"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_to
TopOf=
"parent
"
/>
app:layout_constraintTop_to
BottomOf=
"@+id/tvCongrats
"
/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
app/src/main/res/values/dimens.xml
0 → 100644
View file @
f80abd62
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen
name=
"activity_horizontal_margin"
>
16dp
</dimen>
<dimen
name=
"activity_vertical_margin"
>
16dp
</dimen>
</resources>
app/src/main/res/values/strings.xml
View file @
f80abd62
...
...
@@ -3,4 +3,18 @@
<string
name=
"password_hint"
>
Password
</string>
<string
name=
"email_hint"
>
Email
</string>
<string
name=
"sign_in_text"
>
Sign In
</string>
<string
name=
"title_activity_login"
>
Sign in
</string>
<!-- Strings related to login -->
<string
name=
"prompt_email"
>
Email
</string>
<string
name=
"prompt_password"
>
Password (optional)
</string>
<string
name=
"action_sign_in"
>
Sign in or register
</string>
<string
name=
"action_sign_in_short"
>
Sign in
</string>
<string
name=
"error_invalid_email"
>
This email address is invalid
</string>
<string
name=
"error_invalid_password"
>
This password is too short
</string>
<string
name=
"error_incorrect_password"
>
This password is incorrect
</string>
<string
name=
"error_field_required"
>
This field is required
</string>
<string
name=
"permission_rationale"
>
"Contacts permissions are needed for providing email
completions."
</string>
</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