Browse Source

1. Registration page (Add username ,contact number and profile pic) (Done)

2. For unsuccessful registration throw an alert message . (Done)
3. Incorrect password exception to be handled. (Done)
4. Password length should be min 8 and should have special characters. (Done)
5. Firebase saving done . (Done)
master
Krish 1 year ago
parent
commit
76840c4993
7 changed files with 193 additions and 56 deletions
  1. +0
    -17
      .idea/deploymentTargetDropDown.xml
  2. +1
    -0
      app/build.gradle
  3. +2
    -0
      app/src/main/AndroidManifest.xml
  4. +10
    -1
      app/src/main/java/com/example/attendance/DBHelper.kt
  5. +83
    -3
      app/src/main/java/com/example/attendance/RegisterActivity.kt
  6. +5
    -0
      app/src/main/java/com/example/attendance/UserInfo.kt
  7. +92
    -35
      app/src/main/res/layout/activity_register.xml

+ 0
- 17
.idea/deploymentTargetDropDown.xml View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="RW9DYX45K7I7OZ7H" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-03-11T13:10:44.558803800Z" />
</component>
</project>

+ 1
- 0
app/build.gradle View File

@ -40,6 +40,7 @@ dependencies {
implementation 'com.google.android.material:material:1.8.0' implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.firebase:firebase-auth-ktx:21.0.3' implementation 'com.google.firebase:firebase-auth-ktx:21.0.3'
implementation 'com.google.firebase:firebase-database-ktx:20.1.0'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'


+ 2
- 0
app/src/main/AndroidManifest.xml View File

@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<application <application
android:allowBackup="true" android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules" android:dataExtractionRules="@xml/data_extraction_rules"


+ 10
- 1
app/src/main/java/com/example/attendance/DBHelper.kt View File

@ -16,6 +16,8 @@ class DBHelper(context: Context, factory: SQLiteDatabase.CursorFactory?) :
val query = ("CREATE TABLE " + TABLE_NAME + " (" val query = ("CREATE TABLE " + TABLE_NAME + " ("
+ ID_COL + " INTEGER PRIMARY KEY, " + + ID_COL + " INTEGER PRIMARY KEY, " +
EMAIL_COl + " TEXT," + EMAIL_COl + " TEXT," +
USERNAME_COl + " TEXT," +
PHONE_COl + " TEXT," +
PASSWORD_COL + " TEXT," + PASSWORD_COL + " TEXT," +
CONPASSWORD_COL + " TEXT" + ")") CONPASSWORD_COL + " TEXT" + ")")
@ -31,7 +33,7 @@ class DBHelper(context: Context, factory: SQLiteDatabase.CursorFactory?) :
} }
// This method is for adding data in our database // This method is for adding data in our database
fun addUser(email : String, password : String, conpassword : String ){
fun addUser(email : String,username :String,phone :String, password : String, conpassword : String ){
// below we are creating // below we are creating
// a content values variable // a content values variable
@ -40,6 +42,8 @@ class DBHelper(context: Context, factory: SQLiteDatabase.CursorFactory?) :
// we are inserting our values // we are inserting our values
// in the form of key-value pair // in the form of key-value pair
values.put(EMAIL_COl, email) values.put(EMAIL_COl, email)
values.put(USERNAME_COl, username)
values.put(PHONE_COl, phone)
values.put(PASSWORD_COL, password) values.put(PASSWORD_COL, password)
values.put(CONPASSWORD_COL, conpassword) values.put(CONPASSWORD_COL, conpassword)
@ -90,6 +94,11 @@ class DBHelper(context: Context, factory: SQLiteDatabase.CursorFactory?) :
// below is the variable for email column // below is the variable for email column
val EMAIL_COl = "email" val EMAIL_COl = "email"
val USERNAME_COl = "username"
val PHONE_COl = "phone"
// below is the variable for password column // below is the variable for password column
val PASSWORD_COL = "password" val PASSWORD_COL = "password"


+ 83
- 3
app/src/main/java/com/example/attendance/RegisterActivity.kt View File

@ -1,27 +1,41 @@
package com.example.attendance package com.example.attendance
import android.content.Intent import android.content.Intent
import android.graphics.Bitmap
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.provider.MediaStore
import android.view.View
import android.widget.Button import android.widget.Button
import android.widget.ImageView
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import com.google.android.material.textfield.TextInputEditText import com.google.android.material.textfield.TextInputEditText
import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.ktx.auth import com.google.firebase.auth.ktx.auth
import com.google.firebase.database.DatabaseReference
import com.google.firebase.database.FirebaseDatabase
import com.google.firebase.ktx.Firebase import com.google.firebase.ktx.Firebase
class RegisterActivity : AppCompatActivity() { class RegisterActivity : AppCompatActivity() {
private lateinit var edt_email: TextInputEditText private lateinit var edt_email: TextInputEditText
private lateinit var edt_pass: TextInputEditText private lateinit var edt_pass: TextInputEditText
private lateinit var edt_usrname: TextInputEditText
private lateinit var edt_phone: TextInputEditText
private lateinit var edt_conPass: TextInputEditText private lateinit var edt_conPass: TextInputEditText
private lateinit var btn_register: Button private lateinit var btn_register: Button
private lateinit var profile_image: ImageView
lateinit var email: String lateinit var email: String
lateinit var usrname: String
lateinit var phone: String
lateinit var pass: String lateinit var pass: String
lateinit var conpass: String lateinit var conpass: String
// For firebase implementation // For firebase implementation
private lateinit var auth: FirebaseAuth private lateinit var auth: FirebaseAuth
private lateinit var database: DatabaseReference
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -29,8 +43,11 @@ class RegisterActivity : AppCompatActivity() {
edt_email = findViewById(R.id.edt_email) edt_email = findViewById(R.id.edt_email)
edt_pass = findViewById(R.id.edt_pass) edt_pass = findViewById(R.id.edt_pass)
edt_usrname = findViewById(R.id.edt_usrname)
edt_phone = findViewById(R.id.edt_phone)
edt_conPass = findViewById(R.id.edt_conPass) edt_conPass = findViewById(R.id.edt_conPass)
btn_register = findViewById(R.id.btn_register) btn_register = findViewById(R.id.btn_register)
profile_image = findViewById(R.id.profile_image)
auth = FirebaseAuth.getInstance() auth = FirebaseAuth.getInstance()
@ -39,18 +56,51 @@ class RegisterActivity : AppCompatActivity() {
email = edt_email.text.toString() email = edt_email.text.toString()
pass = edt_pass.text.toString() pass = edt_pass.text.toString()
conpass = edt_conPass.text.toString() conpass = edt_conPass.text.toString()
usrname = edt_usrname.text.toString()
phone = edt_phone.text.toString()
signUpUser() signUpUser()
database = FirebaseDatabase.getInstance().getReference("UserInfo")
val userInfo = UserInfo(email,usrname,phone, pass)
database.child(usrname).setValue(userInfo).addOnSuccessListener {
edt_email.text?.clear()
edt_usrname.text?.clear()
edt_phone.text?.clear()
edt_pass.text?.clear()
edt_conPass.text?.clear()
}.addOnFailureListener{
Toast.makeText(this, "Failed", Toast.LENGTH_LONG).show()
}
db.addUser(email,usrname,phone,pass,conpass)
Toast.makeText(this, email + " added to database", Toast.LENGTH_LONG).show()
db.addUser(email, pass, conpass)
}
profile_image.setOnClickListener(View.OnClickListener { v: View? ->
// Create the camera_intent ACTION_IMAGE_CAPTURE it will open the camera for capture the image
val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
// Start the activity with camera_intent, and request pic id
startActivityForResult(cameraIntent, pic_id)
})
Toast.makeText(this, email + " added to database", Toast.LENGTH_LONG).show()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
// Match the request 'pic id with requestCode
if (requestCode == pic_id) {
// BitMap is data structure of image file which store the image in memory
val photo = data!!.extras!!["data"] as Bitmap?
// Set the image in imageview for display
profile_image.setImageBitmap(photo)
} }
} }
companion object {
// Define the pic id
private const val pic_id = 123
}
private fun signUpUser() { private fun signUpUser() {
@ -67,6 +117,16 @@ class RegisterActivity : AppCompatActivity() {
.show() .show()
return return
} }
if(pass.length<8){
Toast.makeText(this, "Password should atleast have 8 characters", Toast.LENGTH_SHORT)
.show()
return
}
if(!pass.contains("#") || !pass.contains("&") || !pass.contains("@")){
Toast.makeText(this, "Password should special characters", Toast.LENGTH_SHORT)
.show()
return
}
// If all credential are correct // If all credential are correct
@ -76,9 +136,10 @@ class RegisterActivity : AppCompatActivity() {
auth.createUserWithEmailAndPassword(email, pass).addOnCompleteListener(this) { auth.createUserWithEmailAndPassword(email, pass).addOnCompleteListener(this) {
if (it.isSuccessful) { if (it.isSuccessful) {
moveToLogin() moveToLogin()
Toast.makeText(this, "Successfully signed Up", Toast.LENGTH_SHORT).show()
Toast.makeText(this, "Successfully signed Up", Toast.LENGTH_SHORT).show()
finish() finish()
} else { } else {
showAlert()
Toast.makeText(this, it.exception.toString(), Toast.LENGTH_SHORT).show() Toast.makeText(this, it.exception.toString(), Toast.LENGTH_SHORT).show()
} }
System.out.println("error: " + it.exception.toString()) System.out.println("error: " + it.exception.toString())
@ -90,4 +151,23 @@ class RegisterActivity : AppCompatActivity() {
val intent = Intent(this, LoginActivity::class.java) val intent = Intent(this, LoginActivity::class.java)
startActivity(intent) startActivity(intent)
} }
private fun showAlert(){
val builder = AlertDialog.Builder(this)
//set title for alert dialog
builder.setTitle("Warning")
//set message for alert dialog
builder.setMessage("Unsuccessfull attempt")
builder.setIcon(android.R.drawable.ic_dialog_alert)
//performing positive action
builder.setPositiveButton("Try again"){dialogInterface, which ->
}
// Create the AlertDialog
val alertDialog: AlertDialog = builder.create()
// Set other dialog properties
alertDialog.setCancelable(false)
alertDialog.show()
}
} }

+ 5
- 0
app/src/main/java/com/example/attendance/UserInfo.kt View File

@ -0,0 +1,5 @@
package com.example.attendance
data class UserInfo(val email : String? = null,val userName : String? = null,val phone : String? = null,val password : String? = null){
}

+ 92
- 35
app/src/main/res/layout/activity_register.xml View File

@ -10,17 +10,7 @@
android:padding="10dp" android:padding="10dp"
> >
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sentient Geeks!!"
android:textColor="@color/white"
android:layout_gravity="center_horizontal"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginBottom="20dp"/>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -31,6 +21,26 @@
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal" /> android:layout_gravity="center_horizontal" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_image"
app:civ_border_width="4dp"
android:layout_centerInParent="true"
android:src="@drawable/login"
app:civ_border_color="#FF000000"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click here for profile pic"
android:textSize="10sp"
android:textColor="@color/white"
android:textStyle="bold"
android:layout_marginTop="5dp"
android:layout_gravity="center_horizontal" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -44,7 +54,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="12dp" android:layout_marginBottom="12dp"
android:hint="Username/Email"
android:hint="Email"
app:endIconMode="clear_text" app:endIconMode="clear_text"
app:endIconTint="@color/black"> app:endIconTint="@color/black">
@ -53,6 +63,37 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:hint="Username"
app:endIconMode="clear_text"
app:endIconTint="@color/black">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edt_usrname"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:hint="Phone"
app:endIconMode="clear_text"
app:endIconTint="@color/black">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edt_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"/>
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
@ -61,12 +102,13 @@
android:layout_marginBottom="12dp" android:layout_marginBottom="12dp"
android:hint="Enter password" android:hint="Enter password"
app:endIconMode="password_toggle" app:endIconMode="password_toggle"
app:endIconTint="@color/black">
app:endIconTint="@color/white">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/edt_pass" android:id="@+id/edt_pass"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:inputType="textPassword"/>
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
@ -76,12 +118,13 @@
android:layout_marginBottom="12dp" android:layout_marginBottom="12dp"
android:hint="Confirm password" android:hint="Confirm password"
app:endIconMode="password_toggle" app:endIconMode="password_toggle"
app:endIconTint="@color/black">
app:endIconTint="@color/white">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/edt_conPass" android:id="@+id/edt_conPass"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:inputType="textPassword"/>
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
@ -115,27 +158,41 @@
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_marginBottom="40dp"/> android:layout_marginBottom="40dp"/>
<Button
android:id="@+id/btn_finger"
android:layout_width="match_parent"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Use finger pattern"
android:background="@drawable/login_button_bg"
android:textColor="@color/white"
android:textStyle="bold"
android:layout_marginBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"/>
android:orientation="horizontal"
android:layout_weight="1.0">
<Button
android:id="@+id/btn_finger"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Use finger pattern"
android:background="@drawable/login_button_bg"
android:textColor="@color/white"
android:textStyle="bold"
android:layout_weight="0.5"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
/>
<Button
android:id="@+id/btn_face"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Use face recognition"
android:background="@drawable/login_button_bg"
android:textColor="@color/white"
android:textStyle="bold"
android:layout_weight="0.5"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
/>
</LinearLayout>
<Button
android:id="@+id/btn_face"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Use face recognition"
android:background="@drawable/login_button_bg"
android:textColor="@color/white"
android:textStyle="bold"
android:paddingLeft="20dp"
android:paddingRight="20dp"/>
</LinearLayout> </LinearLayout>

Loading…
Cancel
Save