Toggle navigation
Toggle navigation
This project
Loading...
Sign in
손장민
/
FirebaseAuth
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
한윤범
2017-10-19 19:26:45 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b83f4e27da5e9c808114b866f683b5bb1cd6f6b8
b83f4e27
1 parent
816a75aa
user profile update
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
172 additions
and
27 deletions
app/src/main/java/com/example/user/firebaseauthdemo/Main2Activity.java
app/src/main/java/com/example/user/firebaseauthdemo/MainActivity.java
app/src/main/java/com/example/user/firebaseauthdemo/PostActivity.java
app/src/main/java/com/example/user/firebaseauthdemo/ProfileActivity.java
app/src/main/java/com/example/user/firebaseauthdemo/ProfileActivityGmail.java
app/src/main/res/layout/activity_main.xml
app/src/main/res/layout/activity_profile.xml
app/src/main/res/layout/activity_profile_simple_login.xml
app/src/main/java/com/example/user/firebaseauthdemo/Main2Activity.java
View file @
b83f4e2
...
...
@@ -13,9 +13,15 @@ import android.support.v7.widget.Toolbar;
import
android.view.Menu
;
import
android.view.MenuItem
;
import
com.google.firebase.auth.FirebaseAuth
;
import
com.google.firebase.auth.FirebaseUser
;
public
class
Main2Activity
extends
AppCompatActivity
implements
NavigationView
.
OnNavigationItemSelectedListener
{
private
FirebaseAuth
firebaseAuth
;
private
FirebaseUser
mCurrentUser
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
...
@@ -24,7 +30,6 @@ public class Main2Activity extends AppCompatActivity
Toolbar
toolbar
=
(
Toolbar
)
findViewById
(
R
.
id
.
toolbar
);
setSupportActionBar
(
toolbar
);
DrawerLayout
drawer
=
(
DrawerLayout
)
findViewById
(
R
.
id
.
drawer_layout
);
ActionBarDrawerToggle
toggle
=
new
ActionBarDrawerToggle
(
this
,
drawer
,
toolbar
,
R
.
string
.
navigation_drawer_open
,
R
.
string
.
navigation_drawer_close
);
...
...
@@ -33,6 +38,9 @@ public class Main2Activity extends AppCompatActivity
NavigationView
navigationView
=
(
NavigationView
)
findViewById
(
R
.
id
.
nav_view
);
navigationView
.
setNavigationItemSelectedListener
(
this
);
firebaseAuth
=
FirebaseAuth
.
getInstance
();
mCurrentUser
=
firebaseAuth
.
getCurrentUser
();
}
@Override
...
...
@@ -69,6 +77,8 @@ public class Main2Activity extends AppCompatActivity
private
void
displaySelectedScreen
(
int
id
){
String
mail
=
mCurrentUser
.
getEmail
();
Fragment
fragment
=
null
;
switch
(
id
){
...
...
@@ -82,8 +92,14 @@ public class Main2Activity extends AppCompatActivity
fragment
=
new
Community
();
break
;
case
R
.
id
.
nav_manage
:
finish
();
startActivity
(
new
Intent
(
getApplicationContext
(),
ProfileActivity
.
class
));
if
(
mail
.
contains
(
"gmail.com"
))
{
finish
();
startActivity
(
new
Intent
(
getApplicationContext
(),
ProfileActivityGmail
.
class
));
}
else
{
finish
();
startActivity
(
new
Intent
(
getApplicationContext
(),
ProfileActivity
.
class
));
}
}
if
(
fragment
!=
null
){
...
...
app/src/main/java/com/example/user/firebaseauthdemo/MainActivity.java
View file @
b83f4e2
...
...
@@ -16,11 +16,14 @@ import com.google.android.gms.tasks.OnCompleteListener;
import
com.google.android.gms.tasks.Task
;
import
com.google.firebase.auth.AuthResult
;
import
com.google.firebase.auth.FirebaseAuth
;
import
com.google.firebase.database.DatabaseReference
;
import
com.google.firebase.database.FirebaseDatabase
;
public
class
MainActivity
extends
AppCompatActivity
implements
View
.
OnClickListener
{
private
Button
buttonRegister
;
private
EditText
editTextName
;
private
EditText
editTextEmail
;
private
EditText
editTextPassword
;
private
TextView
textViewSignIn
;
...
...
@@ -28,6 +31,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private
ProgressDialog
progressDialog
;
private
FirebaseAuth
firebaseAuth
;
private
DatabaseReference
mDatabase
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
...
@@ -37,6 +41,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
progressDialog
=
new
ProgressDialog
(
MainActivity
.
this
);
firebaseAuth
=
FirebaseAuth
.
getInstance
();
mDatabase
=
FirebaseDatabase
.
getInstance
().
getReference
().
child
(
"Users"
);
if
(
firebaseAuth
.
getCurrentUser
()
!=
null
){
//profile activity here
...
...
@@ -46,6 +51,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
buttonRegister
=
(
Button
)
findViewById
(
R
.
id
.
buttonRegister
);
editTextName
=
(
EditText
)
findViewById
(
R
.
id
.
editTextName
);
editTextEmail
=
(
EditText
)
findViewById
(
R
.
id
.
editTextEmail
);
editTextPassword
=
(
EditText
)
findViewById
(
R
.
id
.
editTextPassword
);
...
...
@@ -56,8 +62,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}
private
void
registerUser
(){
String
email
=
editTextEmail
.
getText
().
toString
().
trim
();
String
password
=
editTextPassword
.
getText
().
toString
().
trim
();
final
String
name
=
editTextName
.
getText
().
toString
().
trim
();
final
String
email
=
editTextEmail
.
getText
().
toString
().
trim
();
final
String
password
=
editTextPassword
.
getText
().
toString
().
trim
();
if
(
TextUtils
.
isEmpty
(
name
)){
Toast
.
makeText
(
this
,
"이름을 입력하세요"
,
Toast
.
LENGTH_SHORT
).
show
();
return
;
}
if
(
TextUtils
.
isEmpty
(
email
)){
//email is empty
...
...
@@ -86,6 +98,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
public
void
onComplete
(
@NonNull
Task
<
AuthResult
>
task
)
{
if
(
task
.
isSuccessful
()){
finish
();
DatabaseReference
newPost
=
mDatabase
.
push
();
newPost
.
child
(
"name"
).
setValue
(
name
);
newPost
.
child
(
"email"
).
setValue
(
email
);
startActivity
(
new
Intent
(
getApplicationContext
(),
Main2Activity
.
class
));
}
else
{
Toast
.
makeText
(
MainActivity
.
this
,
"등록할 수 없습니다."
,
Toast
.
LENGTH_SHORT
).
show
();
...
...
app/src/main/java/com/example/user/firebaseauthdemo/PostActivity.java
View file @
b83f4e2
...
...
@@ -16,6 +16,7 @@ import android.widget.Toast;
import
com.google.android.gms.tasks.OnSuccessListener
;
import
com.google.firebase.auth.FirebaseAuth
;
import
com.google.firebase.auth.FirebaseUser
;
import
com.google.firebase.database.DatabaseReference
;
import
com.google.firebase.database.FirebaseDatabase
;
import
com.google.firebase.storage.FirebaseStorage
;
...
...
@@ -38,6 +39,8 @@ public class PostActivity extends AppCompatActivity {
private
StorageReference
mStorage
;
private
DatabaseReference
mDatabase
;
private
FirebaseAuth
firebaseAuth
;
private
FirebaseUser
mCurrentUser
;
private
DatabaseReference
mDatabaseUser
;
private
ProgressDialog
mProgress
;
...
...
@@ -59,6 +62,8 @@ public class PostActivity extends AppCompatActivity {
mStorage
=
FirebaseStorage
.
getInstance
().
getReference
();
mDatabase
=
FirebaseDatabase
.
getInstance
().
getReference
().
child
(
"Blog"
);
firebaseAuth
=
FirebaseAuth
.
getInstance
();
mCurrentUser
=
firebaseAuth
.
getCurrentUser
();
mDatabaseUser
=
FirebaseDatabase
.
getInstance
().
getReference
().
child
(
"Users"
).
child
(
mCurrentUser
.
getUid
());
mProgress
=
new
ProgressDialog
(
this
);
...
...
@@ -99,7 +104,7 @@ public class PostActivity extends AppCompatActivity {
newPost
.
child
(
"title"
).
setValue
(
title_val
);
newPost
.
child
(
"desc"
).
setValue
(
desc_val
);
newPost
.
child
(
"image"
).
setValue
(
downloadUrl
.
toString
());
newPost
.
child
(
"uid"
).
setValue
(
firebaseAuth
.
getCurrentUser
());
newPost
.
child
(
"uid"
).
setValue
(
mCurrentUser
.
getUid
());
mProgress
.
dismiss
();
...
...
app/src/main/java/com/example/user/firebaseauthdemo/ProfileActivity.java
View file @
b83f4e2
package
com
.
example
.
user
.
firebaseauthdemo
;
import
android.content.Intent
;
import
android.support.v7.app.AppCompatActivity
;
import
android.os.Bundle
;
import
android.support.annotation.NonNull
;
import
android.support.v7.app.AppCompatActivity
;
import
android.util.Log
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.google.android.gms.tasks.OnCompleteListener
;
import
com.google.android.gms.tasks.Task
;
import
com.google.firebase.auth.FirebaseAuth
;
import
com.google.firebase.auth.FirebaseUser
;
import
com.google.firebase.database.DatabaseReference
;
...
...
@@ -18,13 +22,15 @@ public class ProfileActivity extends AppCompatActivity implements View.OnClickLi
private
FirebaseAuth
firebaseAuth
;
private
TextView
textViewUser
Email
;
private
TextView
textViewUser
Name
;
private
Button
buttonLogout
;
private
DatabaseReference
databaseReference
;
private
EditText
editTextName
,
editTextAddress
;
private
EditText
resetPassword
,
resetPasswordRe
;
private
Button
buttonSave
;
public
static
final
String
TAG
=
"HELPLIST"
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
...
...
@@ -37,27 +43,35 @@ public class ProfileActivity extends AppCompatActivity implements View.OnClickLi
databaseReference
=
FirebaseDatabase
.
getInstance
().
getReference
().
child
(
"UserInfo"
);
editTextAddress
=
(
EditText
)
findViewById
(
R
.
id
.
editTextAddress
);
editTextName
=
(
EditText
)
findViewById
(
R
.
id
.
editTextNam
e
);
resetPassword
=
(
EditText
)
findViewById
(
R
.
id
.
resetPassword
);
resetPasswordRe
=
(
EditText
)
findViewById
(
R
.
id
.
resetPasswordR
e
);
buttonSave
=
(
Button
)
findViewById
(
R
.
id
.
buttonSave
);
FirebaseUser
user
=
firebaseAuth
.
getCurrentUser
();
textViewUser
Email
=
(
TextView
)
findViewById
(
R
.
id
.
textViewUserEmail
);
textViewUser
Email
.
setText
(
"Welcome "
+
user
.
getEmail
());
textViewUser
Name
=
(
TextView
)
findViewById
(
R
.
id
.
textViewUserName
);
textViewUser
Name
.
setText
(
" Welcome "
+
user
.
getDisplayName
());
buttonLogout
=
(
Button
)
findViewById
(
R
.
id
.
buttonLogout
);
buttonLogout
.
setOnClickListener
(
this
);
buttonSave
.
setOnClickListener
(
this
);
}
private
void
saveUserInformation
(){
String
name
=
editTextName
.
getText
().
toString
().
trim
();
String
add
=
editTextAddress
.
getText
().
toString
().
trim
();
UserInformation
userInformation
=
new
UserInformation
(
name
,
add
);
FirebaseUser
user
=
firebaseAuth
.
getCurrentUser
();
databaseReference
.
child
(
user
.
getUid
()).
setValue
(
userInformation
);
String
password
=
resetPassword
.
getText
().
toString
().
trim
();
String
passwordRe
=
resetPasswordRe
.
getText
().
toString
().
trim
();
if
(
password
==
passwordRe
){
FirebaseUser
user
=
firebaseAuth
.
getCurrentUser
();
user
.
updatePassword
(
password
)
.
addOnCompleteListener
(
new
OnCompleteListener
<
Void
>()
{
@Override
public
void
onComplete
(
@NonNull
Task
<
Void
>
task
)
{
if
(
task
.
isSuccessful
()){
Log
.
d
(
TAG
,
"user password updated."
);
}
}
});
}
Toast
.
makeText
(
this
,
"저장되었습니다."
,
Toast
.
LENGTH_LONG
).
show
();
}
...
...
app/src/main/java/com/example/user/firebaseauthdemo/ProfileActivityGmail.java
0 → 100644
View file @
b83f4e2
package
com
.
example
.
user
.
firebaseauthdemo
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.support.v7.app.AppCompatActivity
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.TextView
;
import
com.google.firebase.auth.FirebaseAuth
;
import
com.google.firebase.auth.FirebaseUser
;
/**
* Created by HYB on 2017. 10. 19..
*/
public
class
ProfileActivityGmail
extends
AppCompatActivity
implements
View
.
OnClickListener
{
private
FirebaseAuth
firebaseAuth
;
private
TextView
textViewGmail
;
private
Button
buttonLogout
;
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_profile_simple_login
);
firebaseAuth
=
FirebaseAuth
.
getInstance
();
if
(
firebaseAuth
.
getCurrentUser
()
==
null
){
finish
();
startActivity
(
new
Intent
(
this
,
LoginActivity
.
class
));
}
FirebaseUser
user
=
firebaseAuth
.
getCurrentUser
();
textViewGmail
=
(
TextView
)
findViewById
(
R
.
id
.
textViewUserGmail
);
textViewGmail
.
setText
(
" Welcome "
+
user
.
getEmail
());
buttonLogout
=
(
Button
)
findViewById
(
R
.
id
.
buttonLogout
);
buttonLogout
.
setOnClickListener
(
this
);
}
@Override
public
void
onClick
(
View
view
)
{
if
(
view
==
buttonLogout
)
{
firebaseAuth
.
signOut
();
finish
();
startActivity
(
new
Intent
(
this
,
LoginActivity
.
class
));
}
}
}
app/src/main/res/layout/activity_main.xml
View file @
b83f4e2
...
...
@@ -25,6 +25,16 @@
android:layout_gravity=
"center_horizontal"
/>
<EditText
android:layout_margin=
"15dp"
android:inputType=
"textPersonName"
android:hint=
"Enter your name"
android:id=
"@+id/editTextName"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
tools:layout_editor_absoluteY=
"0dp"
tools:layout_editor_absoluteX=
"8dp"
/>
<EditText
android:layout_margin=
"15dp"
android:inputType=
"textEmailAddress"
android:hint=
"Enter your email"
...
...
@@ -34,7 +44,7 @@
tools:layout_editor_absoluteY=
"0dp"
tools:layout_editor_absoluteX=
"8dp"
/>
<EditText
<EditText
android:layout_margin=
"15dp"
android:inputType=
"textPassword"
android:hint=
"Enter your password"
...
...
@@ -44,6 +54,7 @@
tools:layout_editor_absoluteY=
"0dp"
tools:layout_editor_absoluteX=
"8dp"
/>
<Button
android:layout_margin=
"15dp"
android:id=
"@+id/buttonRegister"
...
...
app/src/main/res/layout/activity_profile.xml
View file @
b83f4e2
...
...
@@ -15,7 +15,7 @@
<TextView
android:layout_margin=
"15dp"
android:id=
"@+id/textViewUser
Email
"
android:id=
"@+id/textViewUser
Name
"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textAppearance=
"?android:attr/textAppearanceLarge"
...
...
@@ -23,14 +23,14 @@
android:layout_gravity=
"center_horizontal"
/>
<EditText
android:id=
"@+id/
editTextName
"
android:hint=
"
이름을 입력해 주세요
"
android:id=
"@+id/
resetPassword
"
android:hint=
"
수정할 비밀번호
"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
<EditText
android:id=
"@+id/
editTextAddress
"
android:hint=
"
주소를 입력해 주
세요"
android:id=
"@+id/
resetPasswordRe
"
android:hint=
"
수정할 비밀번호를 다시 입력하
세요"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
...
...
@@ -39,7 +39,7 @@
android:id=
"@+id/buttonSave"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:text=
"
정보 저장
"
/>
android:text=
"
저장하기
"
/>
<Button
android:id=
"@+id/buttonLogout"
...
...
app/src/main/res/layout/activity_profile_simple_login.xml
0 → 100644
View file @
b83f4e2
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
tools:context=
"com.example.user.firebaseauthdemo.ProfileActivity"
>
<LinearLayout
android:layout_width=
"368dp"
android:layout_height=
"495dp"
android:orientation=
"vertical"
tools:layout_editor_absoluteX=
"8dp"
tools:layout_editor_absoluteY=
"8dp"
>
<TextView
android:layout_margin=
"15dp"
android:id=
"@+id/textViewUserGmail"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textAppearance=
"?android:attr/textAppearanceLarge"
android:text=
"TextView"
android:layout_gravity=
"center_horizontal"
/>
<Button
android:id=
"@+id/buttonLogout"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_horizontal"
android:text=
"로그아웃"
/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
Please
register
or
login
to post a comment