Skip to content

Commit

Permalink
login page created
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashish-1020 committed Jul 9, 2024
1 parent 738a921 commit e79a281
Show file tree
Hide file tree
Showing 26 changed files with 510 additions and 56 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.google.gms.google.services)
}

android {
Expand Down Expand Up @@ -29,6 +30,9 @@ android {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding = true
}
}

dependencies {
Expand All @@ -37,6 +41,9 @@ dependencies {
implementation(libs.material)
implementation(libs.activity)
implementation(libs.constraintlayout)
implementation(libs.firebase.auth)
implementation(libs.navigation.fragment)
implementation(libs.navigation.ui)
testImplementation(libs.junit)
androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core)
Expand Down
48 changes: 5 additions & 43 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -1,59 +1,21 @@
{
"project_info": {
"project_number": "858443541871",
"project_id": "self-116a9",
"storage_bucket": "self-116a9.appspot.com"
"project_number": "445427857114",
"project_id": "college-app-c8a3e",
"storage_bucket": "college-app-c8a3e.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:858443541871:android:be4e8b416841b7366bcc9a",
"mobilesdk_app_id": "1:445427857114:android:a93dd38f6ef4468b21d7e3",
"android_client_info": {
"package_name": "com.example.camerax"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyAFVAPgVQwq7nm8KAamNY4glBVsQiw_vXk"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:858443541871:android:856b5cbb0d3c58d36bcc9a",
"android_client_info": {
"package_name": "com.example.entry"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyAFVAPgVQwq7nm8KAamNY4glBVsQiw_vXk"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:858443541871:android:b2ce7e4de5435a556bcc9a",
"android_client_info": {
"package_name": "com.example.self"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyAFVAPgVQwq7nm8KAamNY4glBVsQiw_vXk"
"current_key": "AIzaSyDDs1_JW61ldMvQqur-GGJhjbheeFCHjPs"
}
],
"services": {
Expand Down
25 changes: 15 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,28 @@
android:theme="@style/Theme.CameraX"
tools:targetApi="31">
<activity
android:name=".OkDoneActivity"
android:exported="false" >

</activity>

android:name=".GateKeeperActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="portrait" >

android:name=".AdminActivity"
android:exported="false"
android:theme="@style/Theme.CameraX" />
<activity
android:name=".LoginActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>
<activity
android:name=".OkDoneActivity"
android:exported="false"></activity>
<activity
android:name=".MainActivity"
android:exported="false"
android:screenOrientation="portrait" />

<meta-data
android:name="com.google.mlkit.vision.DEPENDENCIES"
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/com/example/camerax/AdminActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.camerax;

import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class AdminActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_admin);

}
}
24 changes: 24 additions & 0 deletions app/src/main/java/com/example/camerax/GateKeeperActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.camerax;

import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class GateKeeperActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_gate_keeper);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
}
}
120 changes: 120 additions & 0 deletions app/src/main/java/com/example/camerax/LoginActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package com.example.camerax;

import static android.content.ContentValues.TAG;

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

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

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.auth.FirebaseUser;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class LoginActivity extends AppCompatActivity {

private EditText emailEditText, passwordEditText;
private Button loginButton;
private FirebaseAuth mAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);


mAuth = FirebaseAuth.getInstance();


emailEditText = findViewById(R.id.userName_edit_text);
passwordEditText = findViewById(R.id.password_edit_text);
loginButton = findViewById(R.id.button);

loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loginUser();
}
});
}

private void loginUser() {
String email = emailEditText.getText().toString().trim();
String password = passwordEditText.getText().toString().trim();

if (email.isEmpty() || password.isEmpty()) {
Toast.makeText(LoginActivity.this, "Please fill all fields", Toast.LENGTH_SHORT).show();
return;
}


mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {

FirebaseUser user = mAuth.getCurrentUser();


String rollno = user.getEmail().substring(0, 8);

// Check student login format
String checkStudent = "^\\d{2}[A-Za-z]{2}\\d{4}$";
Pattern patternStudent = Pattern.compile(checkStudent);
Matcher matcherStudent = patternStudent.matcher(rollno);

// Check guard login format
String checkGuard = "^[A-Za-z]{3}\\d{4}[A-Za-z]{1}$";
Pattern patternGuard = Pattern.compile(checkGuard);
Matcher matcherGuard = patternGuard.matcher(rollno);

// check for admin format
String checkAdmin="^[A-Za-z]{5}\\d{2}[a-z]{1}$";
Pattern patternAdmin=Pattern.compile(checkAdmin);
Matcher matcherAdmin=patternAdmin.matcher(rollno);


if (matcherStudent.matches()) {
Toast.makeText(LoginActivity.this, "Student login", Toast.LENGTH_SHORT).show();
Intent studentIntent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(studentIntent);
finish();
}

else if (matcherGuard.matches()) {
Toast.makeText(LoginActivity.this, "Admin login", Toast.LENGTH_SHORT).show();
Intent adminIntent = new Intent(LoginActivity.this, GateKeeperActivity.class);
startActivity(adminIntent);
finish();
}

else if(matcherAdmin.matches()) {

Toast.makeText(LoginActivity.this, "Admin login", Toast.LENGTH_SHORT).show();
Intent adminIntent = new Intent(LoginActivity.this, AdminActivity.class);
startActivity(adminIntent);
finish();
}
}

else {
Log.w(TAG, "signInWithEmail:failure", task.getException());
Toast.makeText(LoginActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
Binary file added app/src/main/res/drawable/background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/box.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">

<corners android:radius="8dp"/>
<stroke android:color="@color/blue"
android:width="2dp"/>

</shape>
17 changes: 17 additions & 0 deletions app/src/main/res/drawable/group.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="44dp"
android:height="44dp"
android:viewportWidth="44"
android:viewportHeight="44">
<path
android:pathData="M2,37C2,34.348 3.054,31.804 4.929,29.929C6.804,28.054 9.348,27 12,27H32C34.652,27 37.196,28.054 39.071,29.929C40.946,31.804 42,34.348 42,37C42,38.326 41.473,39.598 40.535,40.535C39.598,41.473 38.326,42 37,42H7C5.674,42 4.402,41.473 3.464,40.535C2.527,39.598 2,38.326 2,37Z"
android:strokeLineJoin="round"
android:strokeWidth="2.5"
android:fillColor="#00000000"
android:strokeColor="#699BF7"/>
<path
android:pathData="M22,17C26.142,17 29.5,13.642 29.5,9.5C29.5,5.358 26.142,2 22,2C17.858,2 14.5,5.358 14.5,9.5C14.5,13.642 17.858,17 22,17Z"
android:strokeWidth="2.5"
android:fillColor="#00000000"
android:strokeColor="#699BF7"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/password.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="40dp"
android:height="24dp"
android:viewportWidth="40"
android:viewportHeight="24">
<path
android:pathData="M1.818,20H38.182V24H1.818V20ZM3.909,11.9L5.455,8.94L7,11.9L9.364,10.4L7.818,7.44H10.909V4.44H7.818L9.364,1.5L7,0L5.455,2.94L3.909,0L1.545,1.5L3.091,4.44H0V7.44H3.091L1.545,10.4L3.909,11.9ZM16.091,10.4L18.455,11.9L20,8.94L21.545,11.9L23.909,10.4L22.364,7.44H25.455V4.44H22.364L23.909,1.5L21.545,0L20,2.94L18.455,0L16.091,1.5L17.636,4.44H14.545V7.44H17.636L16.091,10.4ZM40,4.44H36.909L38.454,1.5L36.091,0L34.546,2.94L33,0L30.636,1.5L32.182,4.44H29.091V7.44H32.182L30.636,10.4L33,11.9L34.546,8.94L36.091,11.9L38.454,10.4L36.909,7.44H40V4.44Z"
android:fillColor="#699BF7"/>
</vector>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/src/main/res/layout/activity_admin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AdminActivity">

</androidx.constraintlayout.widget.ConstraintLayout>
10 changes: 10 additions & 0 deletions app/src/main/res/layout/activity_gate_keeper.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".GateKeeperActivity">

</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit e79a281

Please sign in to comment.