-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignUp.java
More file actions
184 lines (152 loc) · 7.93 KB
/
SignUp.java
File metadata and controls
184 lines (152 loc) · 7.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package com.example.lenovo.employeetrackingsystem;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
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.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SignUp extends AppCompatActivity {
private static EditText fullName, emailId, mobileNumber, location,
password, confirmPassword;
private static TextView login;
private static Button signUpButton;
private static CheckBox terms_conditions;
private DatabaseReference mDatabase;
// private Firebase Emp_reg;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
ProgressDialog progressDialog;
// Initialize all views
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
mAuth = FirebaseAuth.getInstance();
FirebaseDatabase database = FirebaseDatabase.getInstance();
final DatabaseReference Emp_reg = database.getReference("Emp_Registration");
//Emp_reg = new Firebase("https://employee-tracking-system-7df39.firebaseio.com/Emp_Registration");
fullName = (EditText) findViewById(R.id.fullName);
emailId = (EditText) findViewById(R.id.userEmailId);
mobileNumber = (EditText) findViewById(R.id.mobileNumber);
location = (EditText) findViewById(R.id.location);
password = (EditText) findViewById(R.id.password);
confirmPassword = (EditText) findViewById(R.id.confirmPassword);
signUpButton = (Button) findViewById(R.id.signUpBtn);
terms_conditions = (CheckBox) findViewById(R.id.terms_conditions);
mDatabase = FirebaseDatabase.getInstance().getReference();
signUpButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (checkValidation()) {
String name = fullName.getText().toString().trim();
String email = emailId.getText().toString().trim();
String mobileno = mobileNumber.getText().toString().trim();
String loc = location.getText().toString().trim();
String pass = password.getText().toString().trim();
String des = "Employee";
String task = "Null";
mAuth.createUserWithEmailAndPassword(email, pass).addOnCompleteListener(SignUp.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.v("status", "createUserWithEmail:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Toast.makeText(SignUp.this, "Password Short", Toast.LENGTH_SHORT).show();
password.setText("");
confirmPassword.setText("");
} else if (task.isSuccessful()) {
Toast.makeText(SignUp.this, "Successfull", Toast.LENGTH_SHORT).show();
fullName.setText("");
emailId.setText("");
mobileNumber.setText("");
location.setText("");
password.setText("");
confirmPassword.setText("");
}
// ...
}
});
String key = Emp_reg.push().getKey();
Emp_details emp = new Emp_details(key, name, email, mobileno, loc, des, task);
Map<String, Object> postValues = emp.toMap();
Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put("/Emp_details/" + key, postValues);
mDatabase.updateChildren(childUpdates);
}
}
});
// Setting text selector over textviews
// XmlResourceParser xrp = getResources().getXml(R.drawable.text_selector);
//try {
// ColorStateList csl = ColorStateList.createFromXml(getResources(),
// xrp);
// login.setTextColor(csl);
// terms_conditions.setTextColor(csl);
// } catch (Exception e) {
// }
}
// Check Validation Method
private boolean checkValidation() {
// Get all edittext texts
String getFullName = fullName.getText().toString();
String getEmailId = emailId.getText().toString();
String getMobileNumber = mobileNumber.getText().toString();
String getLocation = location.getText().toString();
String getPassword = password.getText().toString();
String getConfirmPassword = confirmPassword.getText().toString();
// Pattern match for email id
Pattern p = Pattern.compile(".+@.+\\..+");
Matcher m = p.matcher(getEmailId);
// Check if all strings are null or not
if (getFullName.equals("") || getFullName.length() == 0
|| getEmailId.equals("") || getEmailId.length() == 0
|| getMobileNumber.equals("") || getMobileNumber.length() == 0
|| getLocation.equals("") || getLocation.length() == 0
|| getPassword.equals("") || getPassword.length() == 0
|| getConfirmPassword.equals("")
|| getConfirmPassword.length() == 0) {
// new CustomToast().Show_Toast(this, view,
// "All fields are required.");
Toast.makeText(getApplicationContext(), "All fields are required", Toast.LENGTH_LONG).show();
return false;
}
// Check if email id valid or not
else if (!m.find()) {
// new CustomToast().Show_Toast(this, view,
// "Your Email Id is Invalid.");
Toast.makeText(getApplicationContext(), "Your Email Id is Invalid.", Toast.LENGTH_LONG).show();
return false;
}
// Check if both password should be equal
else if (!getConfirmPassword.equals(getPassword)) {
// new CustomToast().Show_Toast(this, view,
// "Both password doesn't match.");
Toast.makeText(getApplicationContext(), "Both password doesn't match.", Toast.LENGTH_LONG).show();
return false;
}
// Make sure user should check Terms and Conditions checkbox
else if (!terms_conditions.isChecked()) {
// new CustomToast().Show_Toast(this, view,
// "Please select Terms and Conditions.");
Toast.makeText(getApplicationContext(), "Please select Terms and Conditions.", Toast.LENGTH_LONG).show();
return false;
}
return true;
}}