forked from omairys/final_project_task_mgmt_system
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
158 lines (136 loc) · 4.03 KB
/
index.js
File metadata and controls
158 lines (136 loc) · 4.03 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
// // Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyBswUAtEYm7rp_66YJ_LXN2ns-xjgu9wJc",
authDomain: "jsmanagment-15f9e.firebaseapp.com",
projectId: "jsmanagment-15f9e",
storageBucket: "jsmanagment-15f9e.appspot.com",
messagingSenderId: "290004854452",
appId: "1:290004854452:web:a57fa3359e0c48878119e1",
measurementId: "G-3V7Y7J1QEC"
};
// Initialize Firebase
const app=firebase.initializeApp(firebaseConfig);
// Initialize variables
const auth = firebase.auth()
const db = firebase.firestore()
// Set up our login function
function login () {
// Get all our input fields
email = document.getElementById('email').value
password = document.getElementById('password').value
// Validate input fields
if (validate_email(email) == false || validate_password(password) == false) {
alert('Email or Password is incorrect!')
return
// Don't continue running the code
}
auth.signInWithEmailAndPassword(email, password)
.then(function() {
// Declare user variable
var user = auth.currentUser
// // Add this user to Firebase Database
// var database_ref = database.ref()
// // Create User data
// var user_data = {
// last_login : Date.now()
// }
// // Push to Firebase Database
// database_ref.child('users/' + user.uid).update(user_data)
// DOne
// alert('User Logged In!!')
window.location.replace("main/main.html");
})
.catch(function(error) {
// Firebase will use this to alert of its errors
var error_code = error.code
var error_message = error.message
alert(error_message)
})
}
// Set up our register function
function register() {
// Get all our input fields
// email = document.getElementById('email').value
// password = document.getElementById('password').value
// full_name = document.getElementById('full_name').value
password="1234567";
full_name="Alejandro Morales";
// // Validate input fields
// if (validate_email(email) == false || validate_password(password) == false) {
// alert('Email or Password is Outta Line!!')
// return
// // Don't continue running the code
// }
// if (validate_field(full_name) == false ) {
// alert('One or More Extra Fields is Outta Line!!')
// return
// }
// Move on with Auth
auth.createUserWithEmailAndPassword(email, password)
.then(function() {
// Declare user variable
var user = auth.currentUser
db.collection("users").add({
Full_Name: full_name,
email:email,
admin: false
})
.then((docRef) => {
console.log("Document written with ID: ", docRef.id);
})
.catch((error) => {
console.error("Error adding document: ", error);
});
// DOne
alert('User Created!!')
})
.catch(function(error) {
// Firebase will use this to alert of its errors
var error_code = error.code
var error_message = error.message
alert(error_message)
})
}
// Validate Functions
function validate_email(email) {
expression = /^[^@]+@\w+(\.\w+)+\w$/
if (expression.test(email) == true) {
// Email is good
return true
} else {
// Email is not good
return false
}
}
function validate_password(password) {
// Firebase only accepts lengths greater than 6
if (password < 6) {
return false
} else {
return true
}
}
function validate_field(field) {
if (field == null) {
return false
}
if (field.length <= 0) {
return false
} else {
return true
}
}
function addTask(){
db.collection("users").add({
task_Name: "task x",
responsible:"alejandro",
status: "started"
})
.then((docRef) => {
console.log("Document written with ID: ", docRef.id);
})
.catch((error) => {
console.error("Error adding document: ", error);
});
console.log("adding task");
}