mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 13:38:41 +00:00
Get token from user
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'com.google.gms.google-services'
|
||||
}
|
||||
|
||||
android {
|
||||
@@ -32,6 +33,12 @@ android {
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath 'com.google.gms:google-services:4.3.15'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -39,6 +46,7 @@ dependencies {
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'com.google.firebase:firebase-auth:21.1.0'
|
||||
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||
@@ -63,4 +71,7 @@ dependencies {
|
||||
implementation 'com.github.slavce14:SJ-Dialog:1.5'
|
||||
implementation 'com.saadahmedev.popup-dialog:popup-dialog:1.0.2'
|
||||
implementation 'com.github.gabriel-TheCode:AestheticDialogs:1.3.6'
|
||||
|
||||
//Firebase
|
||||
implementation platform('com.google.firebase:firebase-bom:31.2.3')
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"project_info": {
|
||||
"project_number": "213676556381",
|
||||
"firebase_url": "https://foodify-55954-default-rtdb.firebaseio.com",
|
||||
"project_id": "foodify-55954",
|
||||
"storage_bucket": "foodify-55954.appspot.com"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:213676556381:android:b1fb5bb1a827c24ce88db4",
|
||||
"android_client_info": {
|
||||
"package_name": "com.capstone.foodify"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "213676556381-jmh1dva918r6juc331d1jclgjeinqor1.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyBBboME-vz27_Rgg98ftivvSvMVoH9lV1A"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": [
|
||||
{
|
||||
"client_id": "213676556381-jmh1dva918r6juc331d1jclgjeinqor1.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import com.capstone.foodify.R;
|
||||
import com.capstone.foodify.ViewPagerAdapter;
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
import com.google.android.material.navigation.NavigationBarView;
|
||||
import com.google.firebase.FirebaseApp;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@@ -31,6 +32,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
SplashScreen.installSplashScreen(this);
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
initComponent();
|
||||
|
||||
bottomNavigation();
|
||||
|
||||
@@ -1,32 +1,56 @@
|
||||
package com.capstone.foodify.Activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.capstone.foodify.Common;
|
||||
import com.capstone.foodify.R;
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
import com.google.firebase.FirebaseApp;
|
||||
import com.google.firebase.auth.AuthResult;
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
import com.google.firebase.auth.FirebaseUser;
|
||||
import com.google.firebase.auth.GetTokenResult;
|
||||
|
||||
public class SignInActivity extends AppCompatActivity {
|
||||
|
||||
private FirebaseAuth mAuth;
|
||||
TextView signUp_textView, forgotPassword_textView;
|
||||
|
||||
TextInputLayout textInput_account, textInput_password;
|
||||
TextInputEditText email, password;
|
||||
MaterialButton signInButton;
|
||||
|
||||
ImageView back_image;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_sign_in);
|
||||
initComponent();
|
||||
//Init firebase app
|
||||
FirebaseApp.initializeApp(SignInActivity.this);
|
||||
|
||||
setContentView(R.layout.activity_sign_in);
|
||||
|
||||
|
||||
// Initialize Firebase Auth
|
||||
mAuth = FirebaseAuth.getInstance();
|
||||
|
||||
initComponent();
|
||||
setFontUI();
|
||||
|
||||
back_image.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -48,13 +72,54 @@ public class SignInActivity extends AppCompatActivity {
|
||||
startActivity(new Intent(SignInActivity.this, ForgotPasswordActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
//Set event when user click sign in button
|
||||
signInButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mAuth.signInWithEmailAndPassword(email.getText().toString(), password.getText().toString())
|
||||
.addOnCompleteListener(SignInActivity.this, new OnCompleteListener<AuthResult>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<AuthResult> task) {
|
||||
if (task.isSuccessful()) {
|
||||
// Sign in success, update UI with the signed-in user's information
|
||||
FirebaseUser user = mAuth.getCurrentUser();
|
||||
|
||||
user.getIdToken(true)
|
||||
.addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<GetTokenResult> task) {
|
||||
if(task.isSuccessful()){
|
||||
String idToken = task.getResult().getToken();
|
||||
|
||||
System.out.println("TOKEN: " + idToken);
|
||||
} else {
|
||||
Toast.makeText(SignInActivity.this, "Error when taking token!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// If sign in fails, display a message to the user.
|
||||
Toast.makeText(SignInActivity.this, "Authentication failed.",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initComponent() {
|
||||
textInput_account = (TextInputLayout) findViewById(R.id.textInput_account);
|
||||
textInput_password = (TextInputLayout) findViewById(R.id.textInput_password);
|
||||
signUp_textView = (TextView) findViewById(R.id.sign_up_textView);
|
||||
forgotPassword_textView = (TextView) findViewById(R.id.forgotPassword_textView);
|
||||
back_image = (ImageView) findViewById(R.id.back_image);
|
||||
|
||||
email = (TextInputEditText) findViewById(R.id.edt_email);
|
||||
password = (TextInputEditText) findViewById(R.id.edt_password);
|
||||
|
||||
signInButton = (MaterialButton) findViewById(R.id.sign_in_button);
|
||||
}
|
||||
private void setFontUI() {
|
||||
textInput_account.setTypeface(Common.setFontBebas(getAssets()));
|
||||
|
||||
@@ -13,12 +13,13 @@ import androidx.fragment.app.Fragment;
|
||||
import com.capstone.foodify.Activity.AccountAndProfileActivity;
|
||||
import com.capstone.foodify.Activity.AddressManagerActivity;
|
||||
import com.capstone.foodify.Activity.OrderActivity;
|
||||
import com.capstone.foodify.Activity.SignInActivity;
|
||||
import com.capstone.foodify.Activity.SignUpActivity;
|
||||
import com.capstone.foodify.R;
|
||||
|
||||
public class ProfileFragment extends Fragment {
|
||||
|
||||
Button btnSignUp;
|
||||
Button btnSignUp, btnSignIn;
|
||||
|
||||
LinearLayout account_and_profile, manage_address, order_history;
|
||||
@Override
|
||||
@@ -30,6 +31,7 @@ public class ProfileFragment extends Fragment {
|
||||
account_and_profile = rootView.findViewById(R.id.account_and_profile);
|
||||
manage_address = rootView.findViewById(R.id.manage_address);
|
||||
order_history = rootView.findViewById(R.id.order_history);
|
||||
btnSignIn = rootView.findViewById(R.id.sign_in_button);
|
||||
|
||||
btnSignUp.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -58,6 +60,13 @@ public class ProfileFragment extends Fragment {
|
||||
startActivity(new Intent(getActivity(), OrderActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
btnSignIn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getContext().startActivity(new Intent(getContext(), SignInActivity.class));
|
||||
}
|
||||
});
|
||||
return rootView;
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@
|
||||
app:layout_constraintTop_toBottomOf="@+id/textInput_password" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/sign_up_button"
|
||||
android:id="@+id/sign_in_button"
|
||||
style="@style/DefaultSolid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:visibility="visible"
|
||||
android:visibility="gone"
|
||||
>
|
||||
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
@@ -227,7 +227,7 @@
|
||||
android:id="@+id/guest_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="gone"
|
||||
android:visibility="visible"
|
||||
>
|
||||
|
||||
<com.makeramen.roundedimageview.RoundedImageView
|
||||
|
||||
Reference in New Issue
Block a user