Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-005
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
0
Merge Requests
0
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-005
2022-005
Commits
71bf80c0
Commit
71bf80c0
authored
Oct 10, 2022
by
Chathura IT19243986
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
761c2704
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
156 additions
and
0 deletions
+156
-0
signup.java
signup.java
+156
-0
No files found.
signup.java
0 → 100644
View file @
71bf80c0
package
com.example.peopluz1
;
import
androidx.annotation.NonNull
;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.util.Patterns
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.ProgressBar
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.google.android.gms.tasks.OnCompleteListener
;
import
com.google.android.gms.tasks.OnFailureListener
;
import
com.google.android.gms.tasks.OnSuccessListener
;
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.firestore.DocumentReference
;
import
com.google.firebase.firestore.FirebaseFirestore
;
import
java.util.HashMap
;
import
java.util.Map
;
public
class
signup
extends
AppCompatActivity
{
EditText
mFullName
,
mEmail
,
mPassword
,
mPhone
;
Button
mRegisterBtn
;
TextView
mLoginBtn
;
FirebaseAuth
fAuth
;
FirebaseFirestore
fStore
;
String
userID
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_signup
);
mFullName
=
findViewById
(
R
.
id
.
name
);
mEmail
=
findViewById
(
R
.
id
.
email
);
mPassword
=
findViewById
(
R
.
id
.
pass
);
mPhone
=
findViewById
(
R
.
id
.
mob
);
mRegisterBtn
=
findViewById
(
R
.
id
.
btnsignup
);
mLoginBtn
=
findViewById
(
R
.
id
.
textViewLogin
);
fAuth
=
FirebaseAuth
.
getInstance
();
fStore
=
FirebaseFirestore
.
getInstance
();
// if(fAuth.getCurrentUser() != null){
// startActivity(new Intent(getApplicationContext(), home.class));
// finish();
// }
mRegisterBtn
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
final
String
email
=
mEmail
.
getText
().
toString
().
trim
();
String
password
=
mPassword
.
getText
().
toString
().
trim
();
final
String
fullName
=
mFullName
.
getText
().
toString
();
final
String
phone
=
mPhone
.
getText
().
toString
();
if
(
TextUtils
.
isEmpty
(
fullName
)){
mFullName
.
setError
(
"Full Name is Required."
);
return
;
}
if
(
TextUtils
.
isEmpty
(
phone
)
||
phone
.
length
()
!=
10
){
mPhone
.
setError
(
"Phone number is Required."
);
return
;
}
if
(
TextUtils
.
isEmpty
(
email
)
||
!
Patterns
.
EMAIL_ADDRESS
.
matcher
(
email
).
matches
()){
mEmail
.
setError
(
"Email is Required."
);
return
;
}
if
(
TextUtils
.
isEmpty
(
password
)){
mPassword
.
setError
(
"Password is Required."
);
return
;
}
if
(
password
.
length
()
<
6
){
mPassword
.
setError
(
"Password Must be >= 6 Characters"
);
return
;
}
// register the user in firebase
fAuth
.
createUserWithEmailAndPassword
(
email
,
password
).
addOnCompleteListener
(
new
OnCompleteListener
<
AuthResult
>()
{
@Override
public
void
onComplete
(
@NonNull
Task
<
AuthResult
>
task
)
{
if
(
task
.
isSuccessful
()){
// send verification link
FirebaseUser
fuser
=
fAuth
.
getCurrentUser
();
fuser
.
sendEmailVerification
().
addOnSuccessListener
(
new
OnSuccessListener
<
Void
>()
{
@Override
public
void
onSuccess
(
Void
aVoid
)
{
Toast
.
makeText
(
signup
.
this
,
"Verification Email Has been Sent."
,
Toast
.
LENGTH_SHORT
).
show
();
}
}).
addOnFailureListener
(
new
OnFailureListener
()
{
@Override
public
void
onFailure
(
@NonNull
Exception
e
)
{
Log
.
d
(
""
,
"onFailure: Email not sent "
+
e
.
getMessage
());
}
});
Toast
.
makeText
(
signup
.
this
,
"User Created."
,
Toast
.
LENGTH_SHORT
).
show
();
userID
=
fAuth
.
getCurrentUser
().
getUid
();
DocumentReference
documentReference
=
fStore
.
collection
(
"users"
).
document
(
userID
);
Map
<
String
,
Object
>
user
=
new
HashMap
<>();
user
.
put
(
"fName"
,
fullName
);
user
.
put
(
"email"
,
email
);
user
.
put
(
"phone"
,
phone
);
documentReference
.
set
(
user
).
addOnSuccessListener
(
new
OnSuccessListener
<
Void
>()
{
@Override
public
void
onSuccess
(
Void
aVoid
)
{
Log
.
d
(
""
,
"onSuccess: user Profile is created for "
+
userID
);
}
}).
addOnFailureListener
(
new
OnFailureListener
()
{
@Override
public
void
onFailure
(
@NonNull
Exception
e
)
{
Log
.
d
(
""
,
"onFailure: "
+
e
.
toString
());
}
});
startActivity
(
new
Intent
(
getApplicationContext
(),
home
.
class
));
}
else
{
Toast
.
makeText
(
signup
.
this
,
"Error ! "
+
task
.
getException
().
getMessage
(),
Toast
.
LENGTH_SHORT
).
show
();
}
}
});
}
});
mLoginBtn
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
startActivity
(
new
Intent
(
getApplicationContext
(),
signin
.
class
));
}
});
}
}
\ 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