Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added get user info2 #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion Auth.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
class Auth {
static isLoggedIn = false;
static currentUser =null;
static li = document.getElementsByClassName('outLi');
static checkUser() {
firebase.auth().onAuthStateChanged(function (user) {
if (user) {
// if user signed in already
// if user signed in already
for (let i = 0; i < Auth.li.length; i++) {
Auth.li[i].classList.remove('hidden')
}
Auth.currentUser = user;
Auth.isLoggedIn = true;
} else {
Auth.isLoggedIn = false;
Expand Down Expand Up @@ -63,4 +65,19 @@ class Auth {
}
location.href = 'mailto:[email protected]'
}
static getUser(){
return new Promise((resolve, reject) => {

firebase.auth().onAuthStateChanged(function (user) {
if (user) {
return resolve(user)
} else {
return resolve(null)
}
});

})

}

}
3 changes: 3 additions & 0 deletions form/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ <h2 id="form-title" class="center red-text"></h2>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>

<script src="../Auth.js"></script>
<<<<<<< HEAD
=======

>>>>>>> bff3118c1c306d1d2d443ee6272823dc4b7dd642
<script src="./index.js"></script>

<script></script>
Expand Down
7 changes: 6 additions & 1 deletion form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ function initialMaterializeElements() {
formTitle.innerText = 'Mentor Form'
}

async function initialMaterializeElements() {
let user = await Auth.getUser();

console.log(user);

M.Timepicker.init(document.querySelector('#start-hour'));
M.Timepicker.init(document.querySelector('#end-hour'));
}
Expand Down Expand Up @@ -142,4 +147,4 @@ async function submit() {
}


}
}}
24 changes: 23 additions & 1 deletion home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ class MembersView {
}
}


async function run() {

Auth.checkUser()
configureNavButtons()

hasAmember()
FireBaseRequest.getMembers(memberRef).
then(members => {
MembersView.render(members);
Expand All @@ -135,6 +137,7 @@ function configureNavButtons() {

const urlParams = new URLSearchParams(window.location.search);
const memberType = urlParams.get('type');
hasAmember(memberType)

// If user click mentee gets data from mentees collection, for mentors gets from mentors db collection.
if (memberType == 'mentees') {
Expand Down Expand Up @@ -163,4 +166,23 @@ function configureNavButtons() {

}

document.addEventListener("DOMContentLoaded", run);
async function hasAmember(type) {
let menteeRef = db.collection(type)
let user = await Auth.getUser()

menteeRef.where("user_email", "==", user.email)
.get()
.then(querySnapshot =>{
console.log(querySnapshot);

querySnapshot.forEach(doc => {
if(doc) {
const beMember = document.getElementsByClassName("beMember")[0];
beMember.innerHTML = `my ${type}`
}

})
})
}

document.addEventListener("DOMContentLoaded", run);