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
3d8d2db3
Commit
3d8d2db3
authored
Nov 02, 2022
by
sasifina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make register part
parent
3d7491f9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
193 additions
and
0 deletions
+193
-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/Register.java
0 → 100644
View file @
3d8d2db3
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