Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-235 Vehicle parking system
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2022-235
2022-235 Vehicle parking system
Commits
598a61f7
Commit
598a61f7
authored
Nov 09, 2022
by
Thilakasiri M.D.T.S
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into 'IT18203004'
Master to merge IT18203004 See merge request
!6
parents
09a5ed21
4fd4466f
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
510 additions
and
0 deletions
+510
-0
app/src/main/java/com/example/vehicleparkingsystem/ParkingSlots.java
...n/java/com/example/vehicleparkingsystem/ParkingSlots.java
+317
-0
app/src/main/java/com/example/vehicleparkingsystem/Register.java
.../main/java/com/example/vehicleparkingsystem/Register.java
+193
-0
No files found.
app/src/main/java/com/example/vehicleparkingsystem/ParkingSlots.java
0 → 100644
View file @
598a61f7
This diff is collapsed.
Click to expand it.
app/src/main/java/com/example/vehicleparkingsystem/Register.java
0 → 100644
View file @
598a61f7
package
com.example.vehicleparkingsystem
;
import
androidx.annotation.NonNull
;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.example.vehicleparkingsystem.Models.Users
;
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
com.google.firebase.database.DatabaseReference
;
import
com.google.firebase.database.FirebaseDatabase
;
public
class
Register
extends
AppCompatActivity
{
EditText
editText1
;
EditText
editText2
;
EditText
editText3
;
EditText
editText4
;
EditText
editText5
;
EditText
editText6
;
Button
reg
;
TextView
textView
;
FirebaseDatabase
rootNode
;
DatabaseReference
reference
;
FirebaseAuth
firebaseAuth
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_register
);
editText1
=(
EditText
)
findViewById
(
R
.
id
.
Uname
);
editText2
=(
EditText
)
findViewById
(
R
.
id
.
Remail
);
editText3
=(
EditText
)
findViewById
(
R
.
id
.
Age
);
editText4
=(
EditText
)
findViewById
(
R
.
id
.
contct
);
editText5
=(
EditText
)
findViewById
(
R
.
id
.
password
);
editText6
=(
EditText
)
findViewById
(
R
.
id
.
vehicle
);
reg
=(
Button
)
findViewById
(
R
.
id
.
register
);
textView
=(
TextView
)
findViewById
(
R
.
id
.
gotologin
);
textView
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
Intent
intent
=
new
Intent
(
Register
.
this
,
MainActivity
.
class
);
startActivity
(
intent
);
}
});
firebaseAuth
=
FirebaseAuth
.
getInstance
();
reg
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
reference
=
FirebaseDatabase
.
getInstance
().
getReference
(
"User"
);
// reference = rootNode.getReference("Users");
final
String
namee
=
editText1
.
getText
().
toString
();
final
String
emaill
=
editText2
.
getText
().
toString
();
final
String
age
=
editText3
.
getText
().
toString
();
final
String
phonee
=
editText4
.
getText
().
toString
();
final
String
pass
=
editText5
.
getText
().
toString
();
final
String
vehicle
=
editText6
.
getText
().
toString
();
if
(!
validateUserName
()
|
!
validateEmail
()
|
!
validateAge
()
|
!
validatePhone
()
|
!
validatePassword
())
{
Toast
.
makeText
(
Register
.
this
,
"Sign up failed"
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
firebaseAuth
.
createUserWithEmailAndPassword
(
emaill
,
pass
)
.
addOnCompleteListener
(
Register
.
this
,
new
OnCompleteListener
<
AuthResult
>()
{
@Override
public
void
onComplete
(
@NonNull
Task
<
AuthResult
>
task
)
{
if
(
task
.
isSuccessful
())
{
FirebaseUser
user
=
FirebaseAuth
.
getInstance
().
getCurrentUser
();
String
userid
=
user
.
getUid
();
Users
members
=
new
Users
(
namee
,
emaill
,
age
,
phonee
,
vehicle
,
pass
);
reference
.
child
(
userid
).
setValue
(
members
);
System
.
out
.
println
(
members
);
Toast
.
makeText
(
Register
.
this
,
"Sign up successfully"
,
Toast
.
LENGTH_SHORT
).
show
();
Intent
intent
=
new
Intent
(
Register
.
this
,
Dashboard
.
class
);
startActivity
(
intent
);
}
else
{
Toast
.
makeText
(
Register
.
this
,
"Sign up failed"
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
});
}
}
});
}
public
boolean
validateUserName
()
{
String
value
=
editText1
.
getText
().
toString
();
String
noWhiteSpace
=
"\\A\\w{4,20}\\z"
;
if
(
value
.
isEmpty
())
{
editText1
.
setError
(
"Field cannot be empty"
);
return
false
;
}
else
if
(
value
.
length
()
>=
15
)
{
editText1
.
setError
(
"Username too long. limit to 15 characters"
);
return
false
;
}
else
if
(!
value
.
matches
(
noWhiteSpace
))
{
editText1
.
setError
(
"White Spaces are not allowed"
);
return
false
;
}
else
{
editText1
.
setError
(
null
);
return
true
;
}
}
public
boolean
validateEmail
()
{
String
value
=
editText2
.
getText
().
toString
();
String
emailPattern
=
"[a-zA-Z0-9._-]+@[a-z].+[a-z]+\\.+[a-z]+"
;
//Regex Expression
if
(
value
.
isEmpty
())
{
editText2
.
setError
(
"Field cannot be empty"
);
return
false
;
}
else
if
(!
value
.
matches
(
emailPattern
))
{
editText2
.
setError
(
"Invalid email address"
);
return
false
;
}
else
{
editText2
.
setError
(
null
);
return
true
;
}
}
public
boolean
validateAge
()
{
String
value
=
editText3
.
getText
().
toString
();
if
(
value
.
isEmpty
())
{
editText3
.
setError
(
"Field cannot be empty"
);
return
false
;
}
else
{
editText3
.
setError
(
null
);
return
true
;
}
}
public
boolean
validatePhone
()
{
String
value
=
editText4
.
getText
().
toString
();
if
(
value
.
isEmpty
())
{
editText4
.
setError
(
"Field cannot be empty"
);
return
false
;
}
else
{
editText4
.
setError
(
null
);
return
true
;
}
}
public
boolean
validatePassword
()
{
String
value
=
editText5
.
getText
().
toString
();
String
password
=
"^"
+
//"(?=.*[0-9])" + //at least 1 digit
//"(?=.*[a-z])" + //at least 1 lower case letter
//"(?=.*[A-Z])" + //at least 1 upper case letter
"(?=.*[a-zA-Z])"
+
//any letter
"(?=.*[@#$%^&+=])"
+
//at least 1 special character
"(?=\\S+$)"
+
//no white spaces
".{2,}"
+
//at least 2 characters
"$"
;
if
(
value
.
isEmpty
())
{
editText5
.
setError
(
"Field cannot be empty"
);
return
false
;
}
else
if
(!
value
.
matches
(
password
))
{
editText5
.
setError
(
"Password must have at least 1 special character, 2 numbers and letters"
);
return
false
;
}
else
{
editText5
.
setError
(
null
);
return
true
;
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment