Skip to content

Commit

Permalink
Merge pull request #450 from cornell-dti/master
Browse files Browse the repository at this point in the history
Public Release - Removing Whitelist and Resolving Bugs
  • Loading branch information
tcho6319 authored Apr 5, 2021
2 parents 56c52f8 + 9a389e7 commit b343ea1
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 315 deletions.
86 changes: 0 additions & 86 deletions functions/split-user-data.js

This file was deleted.

50 changes: 0 additions & 50 deletions functions/update-user-data-courses.js

This file was deleted.

98 changes: 0 additions & 98 deletions functions/update-user-data-semesters.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/Course/Course.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@delete-course="deleteCourse"
@color-course="colorCourse"
@edit-course-credit="editCourseCredit"
:getCreditRange="getCreditRange"
:getCreditRange="getCreditRange || []"
v-click-outside="closeMenuIfOpen"
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modals/CourseMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
class="courseMenu-section"
@mouseover="setDisplayEditCourseCredits(true)"
@mouseleave="setDisplayEditCourseCredits(false)"
v-if="getCreditRange[0] != getCreditRange[1]"
v-if="getCreditRange && getCreditRange[0] != getCreditRange[1]"
>
<img
v-if="isLeft"
Expand Down
5 changes: 5 additions & 0 deletions src/components/Modals/NewSemester.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export default Vue.extend({
default: null,
},
isEdit: { type: Boolean, default: false },
isSemesterAdd: { type: Boolean, default: false },
year: { type: Number, default: 0 },
type: { type: String as PropType<FirestoreSemesterType>, default: '' },
isCourseModelSelectingSemester: { type: Boolean, default: false },
Expand Down Expand Up @@ -287,6 +288,10 @@ export default Vue.extend({
} else {
this.yearText = 0;
}
if (this.isSemesterAdd) {
this.$emit('updateSemProps', this.seasonPlaceholder, Number(this.yearPlaceholder));
}
},
resetDropdowns() {
// reset season dropdown
Expand Down
1 change: 1 addition & 0 deletions src/components/Modals/NewSemesterModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<new-semester
:currentSemesters="semesters"
:isEdit="false"
:isSemesterAdd="true"
:isCourseModelSelectingSemester="false"
@duplicateSemester="disableButton"
@updateSemProps="updateSemProps"
Expand Down
87 changes: 11 additions & 76 deletions src/containers/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ import CustomFooter from '@/components/Footer.vue';
import { GTagLoginEvent } from '@/gtag';
import * as fb from '@/firebaseConfig';
const { whitelistCollection, landingEmailsCollection } = fb;
import store from '@/store';
import { checkNotNull } from '@/utilities';
type Data = {
loginForm: { email: string; password: string };
Expand Down Expand Up @@ -185,88 +185,23 @@ export default Vue.extend({
fb.auth
.signInWithPopup(provider)
.then(user => {
// Check whitelist emails to ensure user can log in
if (user == null) {
if (user == null || user.user == null) {
return;
}
this.checkEmailAccess(user);
const simplifiedUser = {
displayName: checkNotNull(user.user.displayName),
email: checkNotNull(user.user.email),
};
store.commit('setCurrentFirebaseUser', simplifiedUser);
this.performingRequest = false;
this.$router.push('/');
GTagLoginEvent(this.$gtag, 'Google');
})
.catch(err => {
this.performingRequest = false;
this.errorMsg = err.message;
});
},
checkEmailAccess({ user }: { user: firebase.User | null }) {
if (user == null) {
return;
}
const docRef = whitelistCollection.doc(user.email || '');
docRef
.get()
.then(doc => {
if (doc.exists) {
this.performingRequest = false;
this.$router.push('/');
GTagLoginEvent(this.$gtag, 'Google');
} else {
this.handleUserWithoutAccess();
}
})
.catch(() => this.handleUserWithoutAccess());
},
handleUserWithoutAccess() {
this.performingRequest = false;
fb.auth.signOut();
// eslint-disable-next-line no-alert
alert(
"Sorry, but you do not have access currently.\nPlease check back April 5 for CoursePlan's public release."
);
},
validateEmail(email: string): boolean {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
},
validateMajor(major: string): boolean {
return major.trim().length > 0;
},
addUser() {
if (this.validateEmail(this.waitlist.email) && this.validateMajor(this.waitlist.major)) {
// eslint-disable-next-line no-alert
alert("You have been added to the waitlist. We'll be in touch shortly!");
// Add timestamp to data in YYYY-MM-DD hh:mm:ss
const dt = new Date();
this.waitlist.time = `${(dt.getMonth() + 1)
.toString()
.padStart(2, '0')}/${dt
.getDate()
.toString()
.padStart(2, '0')}/${dt
.getFullYear()
.toString()
.padStart(4, '0')} ${dt
.getHours()
.toString()
.padStart(2, '0')}:${dt
.getMinutes()
.toString()
.padStart(2, '0')}:${dt.getSeconds().toString().padStart(2, '0')}`;
// Add landing page data to Firebase
landingEmailsCollection.add(this.waitlist);
// Clear fields
this.waitlist.email = '';
this.waitlist.major = '';
} else if (!this.validateEmail(this.waitlist.email)) {
// eslint-disable-next-line no-alert
alert('You have entered an invalid email address!');
} else {
// eslint-disable-next-line no-alert
alert('You have not entered a major!');
}
},
getYear(): number {
const today = new Date();
return today.getFullYear();
Expand Down
3 changes: 0 additions & 3 deletions src/firebaseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,3 @@ export const onboardingDataCollection = db
return userData;
},
});

export const whitelistCollection = db.collection('cpWhitelist');
export const landingEmailsCollection = db.collection('landingEmails');

0 comments on commit b343ea1

Please sign in to comment.