Skip to content

Commit

Permalink
Merge pull request dsc-sookmyung#26 from dsc-sookmyung/shpark0308
Browse files Browse the repository at this point in the history
Shpark0308
  • Loading branch information
shpark0308 authored Mar 17, 2021
2 parents 5a0ef30 + d31aacd commit 6ff9edd
Show file tree
Hide file tree
Showing 60 changed files with 87 additions and 2,563 deletions.
3 changes: 0 additions & 3 deletions AmongEarth/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@
<activity android:name="com.example.amongearth.mypage.MyStatsActivity" />
<activity android:name=".mypage.NoStatsActivity"/>
<activity android:name="com.example.amongearth.mypage.MyRecordActivity" />
<activity android:name="com.example.amongearth.community.Community_MainActivity"></activity>
<activity android:name="com.example.amongearth.community.Community_Page3"></activity>
<activity android:name="com.example.amongearth.community.Community_Page4"></activity>
<activity android:name="com.example.amongearth.community.Zerowaste_Community"></activity>
<activity android:name="com.example.amongearth.mypage.MyBadgeActivity"/>
<provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

Expand All @@ -28,21 +27,12 @@
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


public class LoginActivity extends AppCompatActivity {

// 구글로그인 result 상수
private static final int RC_SIGN_IN = 900;
// 구글api클라이언트
private GoogleSignInClient googleSignInClient;
// 파이어베이스 인증 객체 생성
private FirebaseAuth firebaseAuth;
// 구글 로그인 버튼
private SignInButton buttonGoogle;


Expand All @@ -53,13 +43,10 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

// 파이어베이스 인증 객체 선언
firebaseAuth = FirebaseAuth.getInstance();

buttonGoogle = findViewById(R.id.sign_in_btn);

// Google 로그인을 앱에 통합
// GoogleSignInOptions 개체를 구성할 때 requestIdToken을 호출
GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken( "841121443421-acfgdidgg607m9hkra1g4ergecg66pqk.apps.googleusercontent.com")
.requestEmail()
Expand All @@ -80,22 +67,16 @@ public void onClick(View view) {
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

// 구글로그인 버튼 응답
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
// 구글 로그인 성공
GoogleSignInAccount account = task.getResult(ApiException.class);
Log.d("sksksksksksk", "firebaseAuthWithGoogle:" + account.getId());
firebaseAuthWithGoogle(account);
} catch (ApiException e) {
Log.w("라라라라라", "Google sign in failed", e);
}
}
}

// 사용자가 정상적으로 로그인한 후에 GoogleSignInAccount 개체에서 ID 토큰을 가져와서
// Firebase 사용자 인증 정보로 교환하고 Firebase 사용자 인증 정보를 사용해 Firebase에 인증합니다.
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {

AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
Expand All @@ -104,44 +85,31 @@ private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// 로그인 성공
Toast.makeText(LoginActivity.this, "성공", Toast.LENGTH_SHORT).show();

FirebaseUser currentUser = firebaseAuth.getCurrentUser();

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
rootRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
// 이미 로그인한 적 있을 때
if (snapshot.hasChild("user/" + currentUser.getUid())) {
//User Exists , No Need To add new data.
//Get previous data from firebase. Take previous data as soon as possible..
Intent main = new Intent(getApplicationContext(), MainActivity.class);
startActivity(main);
}
// 처음 로그인 했을 때
else {
Intent nickname = new Intent(getApplicationContext(), NicknameActivity.class);
startActivity(nickname);
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});

} else {
// 로그인 실패
Toast.makeText(LoginActivity.this, "실패", Toast.LENGTH_SHORT).show();
}

}
});
}


}

Loading

0 comments on commit 6ff9edd

Please sign in to comment.