한윤범

user profile update

...@@ -13,9 +13,15 @@ import android.support.v7.widget.Toolbar; ...@@ -13,9 +13,15 @@ import android.support.v7.widget.Toolbar;
13 import android.view.Menu; 13 import android.view.Menu;
14 import android.view.MenuItem; 14 import android.view.MenuItem;
15 15
16 +import com.google.firebase.auth.FirebaseAuth;
17 +import com.google.firebase.auth.FirebaseUser;
18 +
16 public class Main2Activity extends AppCompatActivity 19 public class Main2Activity extends AppCompatActivity
17 implements NavigationView.OnNavigationItemSelectedListener { 20 implements NavigationView.OnNavigationItemSelectedListener {
18 21
22 + private FirebaseAuth firebaseAuth;
23 + private FirebaseUser mCurrentUser;
24 +
19 @Override 25 @Override
20 protected void onCreate(Bundle savedInstanceState) { 26 protected void onCreate(Bundle savedInstanceState) {
21 27
...@@ -24,7 +30,6 @@ public class Main2Activity extends AppCompatActivity ...@@ -24,7 +30,6 @@ public class Main2Activity extends AppCompatActivity
24 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 30 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
25 setSupportActionBar(toolbar); 31 setSupportActionBar(toolbar);
26 32
27 -
28 DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 33 DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
29 ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( 34 ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
30 this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 35 this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
...@@ -33,6 +38,9 @@ public class Main2Activity extends AppCompatActivity ...@@ -33,6 +38,9 @@ public class Main2Activity extends AppCompatActivity
33 38
34 NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 39 NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
35 navigationView.setNavigationItemSelectedListener(this); 40 navigationView.setNavigationItemSelectedListener(this);
41 +
42 + firebaseAuth = FirebaseAuth.getInstance();
43 + mCurrentUser = firebaseAuth.getCurrentUser();
36 } 44 }
37 45
38 @Override 46 @Override
...@@ -69,6 +77,8 @@ public class Main2Activity extends AppCompatActivity ...@@ -69,6 +77,8 @@ public class Main2Activity extends AppCompatActivity
69 77
70 private void displaySelectedScreen(int id){ 78 private void displaySelectedScreen(int id){
71 79
80 + String mail = mCurrentUser.getEmail();
81 +
72 Fragment fragment = null; 82 Fragment fragment = null;
73 83
74 switch (id){ 84 switch (id){
...@@ -82,8 +92,14 @@ public class Main2Activity extends AppCompatActivity ...@@ -82,8 +92,14 @@ public class Main2Activity extends AppCompatActivity
82 fragment = new Community(); 92 fragment = new Community();
83 break; 93 break;
84 case R.id.nav_manage: 94 case R.id.nav_manage:
85 - finish(); 95 + if(mail.contains("gmail.com")) {
86 - startActivity(new Intent(getApplicationContext(), ProfileActivity.class)); 96 + finish();
97 + startActivity(new Intent(getApplicationContext(), ProfileActivityGmail.class));
98 + }
99 + else{
100 + finish();
101 + startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
102 + }
87 } 103 }
88 104
89 if(fragment != null){ 105 if(fragment != null){
......
...@@ -16,11 +16,14 @@ import com.google.android.gms.tasks.OnCompleteListener; ...@@ -16,11 +16,14 @@ import com.google.android.gms.tasks.OnCompleteListener;
16 import com.google.android.gms.tasks.Task; 16 import com.google.android.gms.tasks.Task;
17 import com.google.firebase.auth.AuthResult; 17 import com.google.firebase.auth.AuthResult;
18 import com.google.firebase.auth.FirebaseAuth; 18 import com.google.firebase.auth.FirebaseAuth;
19 +import com.google.firebase.database.DatabaseReference;
20 +import com.google.firebase.database.FirebaseDatabase;
19 21
20 public class MainActivity extends AppCompatActivity implements View.OnClickListener{ 22 public class MainActivity extends AppCompatActivity implements View.OnClickListener{
21 23
22 private Button buttonRegister; 24 private Button buttonRegister;
23 25
26 + private EditText editTextName;
24 private EditText editTextEmail; 27 private EditText editTextEmail;
25 private EditText editTextPassword; 28 private EditText editTextPassword;
26 private TextView textViewSignIn; 29 private TextView textViewSignIn;
...@@ -28,6 +31,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -28,6 +31,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
28 private ProgressDialog progressDialog; 31 private ProgressDialog progressDialog;
29 32
30 private FirebaseAuth firebaseAuth; 33 private FirebaseAuth firebaseAuth;
34 + private DatabaseReference mDatabase;
31 35
32 @Override 36 @Override
33 protected void onCreate(Bundle savedInstanceState) { 37 protected void onCreate(Bundle savedInstanceState) {
...@@ -37,6 +41,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -37,6 +41,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
37 41
38 progressDialog = new ProgressDialog(MainActivity.this); 42 progressDialog = new ProgressDialog(MainActivity.this);
39 firebaseAuth = FirebaseAuth.getInstance(); 43 firebaseAuth = FirebaseAuth.getInstance();
44 + mDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
40 45
41 if(firebaseAuth.getCurrentUser() != null){ 46 if(firebaseAuth.getCurrentUser() != null){
42 //profile activity here 47 //profile activity here
...@@ -46,6 +51,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -46,6 +51,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
46 51
47 buttonRegister = (Button) findViewById(R.id.buttonRegister); 52 buttonRegister = (Button) findViewById(R.id.buttonRegister);
48 53
54 + editTextName = (EditText) findViewById(R.id.editTextName);
49 editTextEmail = (EditText) findViewById(R.id.editTextEmail); 55 editTextEmail = (EditText) findViewById(R.id.editTextEmail);
50 editTextPassword = (EditText) findViewById(R.id.editTextPassword); 56 editTextPassword = (EditText) findViewById(R.id.editTextPassword);
51 57
...@@ -56,8 +62,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -56,8 +62,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
56 } 62 }
57 63
58 private void registerUser(){ 64 private void registerUser(){
59 - String email = editTextEmail.getText().toString().trim(); 65 + final String name = editTextName.getText().toString().trim();
60 - String password = editTextPassword.getText().toString().trim(); 66 + final String email = editTextEmail.getText().toString().trim();
67 + final String password = editTextPassword.getText().toString().trim();
68 +
69 + if(TextUtils.isEmpty(name)){
70 + Toast.makeText(this, "이름을 입력하세요", Toast.LENGTH_SHORT).show();
71 + return;
72 + }
61 73
62 if(TextUtils.isEmpty(email)){ 74 if(TextUtils.isEmpty(email)){
63 //email is empty 75 //email is empty
...@@ -86,6 +98,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -86,6 +98,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
86 public void onComplete(@NonNull Task<AuthResult> task) { 98 public void onComplete(@NonNull Task<AuthResult> task) {
87 if(task.isSuccessful()){ 99 if(task.isSuccessful()){
88 finish(); 100 finish();
101 + DatabaseReference newPost = mDatabase.push();
102 + newPost.child("name").setValue(name);
103 + newPost.child("email").setValue(email);
89 startActivity(new Intent(getApplicationContext(), Main2Activity.class)); 104 startActivity(new Intent(getApplicationContext(), Main2Activity.class));
90 }else{ 105 }else{
91 Toast.makeText(MainActivity.this, "등록할 수 없습니다.", Toast.LENGTH_SHORT).show(); 106 Toast.makeText(MainActivity.this, "등록할 수 없습니다.", Toast.LENGTH_SHORT).show();
......
...@@ -16,6 +16,7 @@ import android.widget.Toast; ...@@ -16,6 +16,7 @@ import android.widget.Toast;
16 16
17 import com.google.android.gms.tasks.OnSuccessListener; 17 import com.google.android.gms.tasks.OnSuccessListener;
18 import com.google.firebase.auth.FirebaseAuth; 18 import com.google.firebase.auth.FirebaseAuth;
19 +import com.google.firebase.auth.FirebaseUser;
19 import com.google.firebase.database.DatabaseReference; 20 import com.google.firebase.database.DatabaseReference;
20 import com.google.firebase.database.FirebaseDatabase; 21 import com.google.firebase.database.FirebaseDatabase;
21 import com.google.firebase.storage.FirebaseStorage; 22 import com.google.firebase.storage.FirebaseStorage;
...@@ -38,6 +39,8 @@ public class PostActivity extends AppCompatActivity { ...@@ -38,6 +39,8 @@ public class PostActivity extends AppCompatActivity {
38 private StorageReference mStorage; 39 private StorageReference mStorage;
39 private DatabaseReference mDatabase; 40 private DatabaseReference mDatabase;
40 private FirebaseAuth firebaseAuth; 41 private FirebaseAuth firebaseAuth;
42 + private FirebaseUser mCurrentUser;
43 + private DatabaseReference mDatabaseUser;
41 44
42 private ProgressDialog mProgress; 45 private ProgressDialog mProgress;
43 46
...@@ -59,6 +62,8 @@ public class PostActivity extends AppCompatActivity { ...@@ -59,6 +62,8 @@ public class PostActivity extends AppCompatActivity {
59 mStorage = FirebaseStorage.getInstance().getReference(); 62 mStorage = FirebaseStorage.getInstance().getReference();
60 mDatabase = FirebaseDatabase.getInstance().getReference().child("Blog"); 63 mDatabase = FirebaseDatabase.getInstance().getReference().child("Blog");
61 firebaseAuth = FirebaseAuth.getInstance(); 64 firebaseAuth = FirebaseAuth.getInstance();
65 + mCurrentUser = firebaseAuth.getCurrentUser();
66 + mDatabaseUser = FirebaseDatabase.getInstance().getReference().child("Users").child(mCurrentUser.getUid());
62 67
63 mProgress = new ProgressDialog(this); 68 mProgress = new ProgressDialog(this);
64 69
...@@ -99,7 +104,7 @@ public class PostActivity extends AppCompatActivity { ...@@ -99,7 +104,7 @@ public class PostActivity extends AppCompatActivity {
99 newPost.child("title").setValue(title_val); 104 newPost.child("title").setValue(title_val);
100 newPost.child("desc").setValue(desc_val); 105 newPost.child("desc").setValue(desc_val);
101 newPost.child("image").setValue(downloadUrl.toString()); 106 newPost.child("image").setValue(downloadUrl.toString());
102 - newPost.child("uid").setValue(firebaseAuth.getCurrentUser()); 107 + newPost.child("uid").setValue(mCurrentUser.getUid());
103 108
104 mProgress.dismiss(); 109 mProgress.dismiss();
105 110
......
1 package com.example.user.firebaseauthdemo; 1 package com.example.user.firebaseauthdemo;
2 2
3 import android.content.Intent; 3 import android.content.Intent;
4 -import android.support.v7.app.AppCompatActivity;
5 import android.os.Bundle; 4 import android.os.Bundle;
5 +import android.support.annotation.NonNull;
6 +import android.support.v7.app.AppCompatActivity;
7 +import android.util.Log;
6 import android.view.View; 8 import android.view.View;
7 import android.widget.Button; 9 import android.widget.Button;
8 import android.widget.EditText; 10 import android.widget.EditText;
9 import android.widget.TextView; 11 import android.widget.TextView;
10 import android.widget.Toast; 12 import android.widget.Toast;
11 13
14 +import com.google.android.gms.tasks.OnCompleteListener;
15 +import com.google.android.gms.tasks.Task;
12 import com.google.firebase.auth.FirebaseAuth; 16 import com.google.firebase.auth.FirebaseAuth;
13 import com.google.firebase.auth.FirebaseUser; 17 import com.google.firebase.auth.FirebaseUser;
14 import com.google.firebase.database.DatabaseReference; 18 import com.google.firebase.database.DatabaseReference;
...@@ -18,13 +22,15 @@ public class ProfileActivity extends AppCompatActivity implements View.OnClickLi ...@@ -18,13 +22,15 @@ public class ProfileActivity extends AppCompatActivity implements View.OnClickLi
18 22
19 private FirebaseAuth firebaseAuth; 23 private FirebaseAuth firebaseAuth;
20 24
21 - private TextView textViewUserEmail; 25 + private TextView textViewUserName;
22 private Button buttonLogout; 26 private Button buttonLogout;
23 27
24 private DatabaseReference databaseReference; 28 private DatabaseReference databaseReference;
25 - private EditText editTextName, editTextAddress; 29 + private EditText resetPassword, resetPasswordRe;
26 private Button buttonSave; 30 private Button buttonSave;
27 31
32 + public static final String TAG = "HELPLIST";
33 +
28 @Override 34 @Override
29 protected void onCreate(Bundle savedInstanceState) { 35 protected void onCreate(Bundle savedInstanceState) {
30 super.onCreate(savedInstanceState); 36 super.onCreate(savedInstanceState);
...@@ -37,27 +43,35 @@ public class ProfileActivity extends AppCompatActivity implements View.OnClickLi ...@@ -37,27 +43,35 @@ public class ProfileActivity extends AppCompatActivity implements View.OnClickLi
37 43
38 databaseReference = FirebaseDatabase.getInstance().getReference().child("UserInfo"); 44 databaseReference = FirebaseDatabase.getInstance().getReference().child("UserInfo");
39 45
40 - editTextAddress = (EditText) findViewById(R.id.editTextAddress); 46 + resetPassword = (EditText) findViewById(R.id.resetPassword);
41 - editTextName = (EditText)findViewById(R.id.editTextName); 47 + resetPasswordRe = (EditText)findViewById(R.id.resetPasswordRe);
42 buttonSave = (Button)findViewById(R.id.buttonSave); 48 buttonSave = (Button)findViewById(R.id.buttonSave);
43 49
44 FirebaseUser user = firebaseAuth.getCurrentUser(); 50 FirebaseUser user = firebaseAuth.getCurrentUser();
45 51
46 - textViewUserEmail = (TextView) findViewById(R.id.textViewUserEmail); 52 + textViewUserName = (TextView) findViewById(R.id.textViewUserName);
47 - textViewUserEmail.setText("Welcome " + user.getEmail()); 53 + textViewUserName.setText(" Welcome " + user.getDisplayName());
48 buttonLogout = (Button)findViewById(R.id.buttonLogout); 54 buttonLogout = (Button)findViewById(R.id.buttonLogout);
49 buttonLogout.setOnClickListener(this); 55 buttonLogout.setOnClickListener(this);
50 buttonSave.setOnClickListener(this); 56 buttonSave.setOnClickListener(this);
51 } 57 }
52 58
53 private void saveUserInformation(){ 59 private void saveUserInformation(){
54 - String name = editTextName.getText().toString().trim(); 60 + String password = resetPassword.getText().toString().trim();
55 - String add = editTextAddress.getText().toString().trim(); 61 + String passwordRe = resetPasswordRe.getText().toString().trim();
56 - 62 +
57 - UserInformation userInformation = new UserInformation(name, add); 63 + if(password == passwordRe){
58 - 64 + FirebaseUser user = firebaseAuth.getCurrentUser();
59 - FirebaseUser user = firebaseAuth.getCurrentUser(); 65 + user.updatePassword(password)
60 - databaseReference.child(user.getUid()).setValue(userInformation); 66 + .addOnCompleteListener(new OnCompleteListener<Void>() {
67 + @Override
68 + public void onComplete(@NonNull Task<Void> task) {
69 + if(task.isSuccessful()){
70 + Log.d(TAG, "user password updated.");
71 + }
72 + }
73 + });
74 + }
61 75
62 Toast.makeText(this, "저장되었습니다.", Toast.LENGTH_LONG).show(); 76 Toast.makeText(this, "저장되었습니다.", Toast.LENGTH_LONG).show();
63 } 77 }
......
1 +package com.example.user.firebaseauthdemo;
2 +
3 +import android.content.Intent;
4 +import android.os.Bundle;
5 +import android.support.annotation.Nullable;
6 +import android.support.v7.app.AppCompatActivity;
7 +import android.view.View;
8 +import android.widget.Button;
9 +import android.widget.TextView;
10 +
11 +import com.google.firebase.auth.FirebaseAuth;
12 +import com.google.firebase.auth.FirebaseUser;
13 +
14 +/**
15 + * Created by HYB on 2017. 10. 19..
16 + */
17 +
18 +public class ProfileActivityGmail extends AppCompatActivity implements View.OnClickListener{
19 +
20 + private FirebaseAuth firebaseAuth;
21 +
22 + private TextView textViewGmail;
23 + private Button buttonLogout;
24 +
25 + @Override
26 + protected void onCreate(@Nullable Bundle savedInstanceState) {
27 + super.onCreate(savedInstanceState);
28 +
29 + setContentView(R.layout.activity_profile_simple_login);
30 + firebaseAuth = FirebaseAuth.getInstance();
31 + if(firebaseAuth.getCurrentUser() == null){
32 + finish();
33 + startActivity(new Intent(this,LoginActivity.class));
34 + }
35 +
36 + FirebaseUser user = firebaseAuth.getCurrentUser();
37 +
38 + textViewGmail = (TextView) findViewById(R.id.textViewUserGmail);
39 + textViewGmail.setText(" Welcome " + user.getEmail());
40 + buttonLogout = (Button)findViewById(R.id.buttonLogout);
41 + buttonLogout.setOnClickListener(this);
42 + }
43 +
44 + @Override
45 + public void onClick(View view) {
46 + if(view == buttonLogout) {
47 + firebaseAuth.signOut();
48 + finish();
49 + startActivity(new Intent(this, LoginActivity.class));
50 + }
51 + }
52 +}
...@@ -25,6 +25,16 @@ ...@@ -25,6 +25,16 @@
25 android:layout_gravity="center_horizontal"/> 25 android:layout_gravity="center_horizontal"/>
26 26
27 <EditText 27 <EditText
28 + android:layout_margin="15dp"
29 + android:inputType="textPersonName"
30 + android:hint="Enter your name"
31 + android:id="@+id/editTextName"
32 + android:layout_width="match_parent"
33 + android:layout_height="wrap_content"
34 + tools:layout_editor_absoluteY="0dp"
35 + tools:layout_editor_absoluteX="8dp" />
36 +
37 + <EditText
28 android:layout_margin="15dp" 38 android:layout_margin="15dp"
29 android:inputType="textEmailAddress" 39 android:inputType="textEmailAddress"
30 android:hint="Enter your email" 40 android:hint="Enter your email"
...@@ -34,7 +44,7 @@ ...@@ -34,7 +44,7 @@
34 tools:layout_editor_absoluteY="0dp" 44 tools:layout_editor_absoluteY="0dp"
35 tools:layout_editor_absoluteX="8dp" /> 45 tools:layout_editor_absoluteX="8dp" />
36 46
37 - <EditText 47 + <EditText
38 android:layout_margin="15dp" 48 android:layout_margin="15dp"
39 android:inputType="textPassword" 49 android:inputType="textPassword"
40 android:hint="Enter your password" 50 android:hint="Enter your password"
...@@ -44,6 +54,7 @@ ...@@ -44,6 +54,7 @@
44 tools:layout_editor_absoluteY="0dp" 54 tools:layout_editor_absoluteY="0dp"
45 tools:layout_editor_absoluteX="8dp" /> 55 tools:layout_editor_absoluteX="8dp" />
46 56
57 +
47 <Button 58 <Button
48 android:layout_margin="15dp" 59 android:layout_margin="15dp"
49 android:id="@+id/buttonRegister" 60 android:id="@+id/buttonRegister"
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
15 15
16 <TextView 16 <TextView
17 android:layout_margin="15dp" 17 android:layout_margin="15dp"
18 - android:id="@+id/textViewUserEmail" 18 + android:id="@+id/textViewUserName"
19 android:layout_width="wrap_content" 19 android:layout_width="wrap_content"
20 android:layout_height="wrap_content" 20 android:layout_height="wrap_content"
21 android:textAppearance="?android:attr/textAppearanceLarge" 21 android:textAppearance="?android:attr/textAppearanceLarge"
...@@ -23,14 +23,14 @@ ...@@ -23,14 +23,14 @@
23 android:layout_gravity="center_horizontal"/> 23 android:layout_gravity="center_horizontal"/>
24 24
25 <EditText 25 <EditText
26 - android:id="@+id/editTextName" 26 + android:id="@+id/resetPassword"
27 - android:hint="이름을 입력해 주세요" 27 + android:hint="수정할 비밀번호"
28 android:layout_width="match_parent" 28 android:layout_width="match_parent"
29 android:layout_height="wrap_content" /> 29 android:layout_height="wrap_content" />
30 30
31 <EditText 31 <EditText
32 - android:id="@+id/editTextAddress" 32 + android:id="@+id/resetPasswordRe"
33 - android:hint="주소를 입력해 주세요" 33 + android:hint="수정할 비밀번호를 다시 입력하세요"
34 android:layout_width="match_parent" 34 android:layout_width="match_parent"
35 android:layout_height="wrap_content" /> 35 android:layout_height="wrap_content" />
36 36
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
39 android:id="@+id/buttonSave" 39 android:id="@+id/buttonSave"
40 android:layout_width="match_parent" 40 android:layout_width="match_parent"
41 android:layout_height="wrap_content" 41 android:layout_height="wrap_content"
42 - android:text="정보 저장" /> 42 + android:text="저장하기" />
43 43
44 <Button 44 <Button
45 android:id="@+id/buttonLogout" 45 android:id="@+id/buttonLogout"
......
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 + xmlns:app="http://schemas.android.com/apk/res-auto"
4 + xmlns:tools="http://schemas.android.com/tools"
5 + android:layout_width="match_parent"
6 + android:layout_height="match_parent"
7 + tools:context="com.example.user.firebaseauthdemo.ProfileActivity">
8 +
9 + <LinearLayout
10 + android:layout_width="368dp"
11 + android:layout_height="495dp"
12 + android:orientation="vertical"
13 + tools:layout_editor_absoluteX="8dp"
14 + tools:layout_editor_absoluteY="8dp">
15 +
16 + <TextView
17 + android:layout_margin="15dp"
18 + android:id="@+id/textViewUserGmail"
19 + android:layout_width="wrap_content"
20 + android:layout_height="wrap_content"
21 + android:textAppearance="?android:attr/textAppearanceLarge"
22 + android:text="TextView"
23 + android:layout_gravity="center_horizontal"/>
24 +
25 + <Button
26 + android:id="@+id/buttonLogout"
27 + android:layout_width="wrap_content"
28 + android:layout_height="wrap_content"
29 + android:layout_gravity="center_horizontal"
30 + android:text="로그아웃" />
31 + </LinearLayout>
32 +</android.support.constraint.ConstraintLayout>