ProfileActivity.java
3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.example.user.firebaseauthdemo;
import android.content.Intent;
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;
import com.google.firebase.database.FirebaseDatabase;
public class ProfileActivity extends AppCompatActivity implements View.OnClickListener{
private FirebaseAuth firebaseAuth;
private TextView textViewUserName;
private Button buttonLogout;
private DatabaseReference databaseReference;
private EditText resetPassword, resetPasswordRe;
private Button buttonSave;
public static final String TAG = "HELPLIST";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
firebaseAuth = FirebaseAuth.getInstance();
if(firebaseAuth.getCurrentUser() == null){
finish();
startActivity(new Intent(this,LoginActivity.class));
}
databaseReference = FirebaseDatabase.getInstance().getReference().child("UserInfo");
resetPassword = (EditText) findViewById(R.id.resetPassword);
resetPasswordRe = (EditText)findViewById(R.id.resetPasswordRe);
buttonSave = (Button)findViewById(R.id.buttonSave);
FirebaseUser user = firebaseAuth.getCurrentUser();
textViewUserName = (TextView) findViewById(R.id.textViewUserName);
textViewUserName.setText(" Welcome " + user.getDisplayName());
buttonLogout = (Button)findViewById(R.id.buttonLogout);
buttonLogout.setOnClickListener(this);
buttonSave.setOnClickListener(this);
}
private void saveUserInformation(){
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();
}
@Override
public void onClick(View view) {
if(view == buttonLogout){
firebaseAuth.signOut();
finish();
startActivity(new Intent(this, LoginActivity.class));
}
if(view == buttonSave){
saveUserInformation();
}
}
}