Skip to content

Commit

Permalink
Signup Conditional for Temporarily Disabled Security (#388)
Browse files Browse the repository at this point in the history
* Fixed typo for return

* Fix for refresh during first slide upload

* Fixed refresh on first slide upload

* Added space after 'if'  for eslint configuration

* Added functionality to delete slide from system

* Removed refresh on first slide upload

* Added alert for slide deletion success

* Update to fix linting errors

* Update to fix linting errors

* Fix linting errors

* Fix lint errors

* Fix lint error

* Rechained promises to handle mishandled slide deletions

* style fix

* Added delete slide request functionality

* style fix

* style fix

* style fix

* style fix

* style fix

* Client side changes for handling new 'requests' collection

* merge fix

* merge fix

* Fix for direct deletion of slides

* style fix

* Added feature for user registration requests

* style fix

* Commented line stating that signup page is just for admins

* Added line explaining new workflow of signup page

* Added popups for success instead of alerts and moved showSuccessPopup to util.js for reusability

* Comment fix

* Style fix

* Solved permsisions is not defined error in signup.html

* Comment fix

* catch promise error

Co-Authored-By: Ryan Birmingham <birm@rbirm.us>

* error handling on fetching requests

Co-Authored-By: Ryan Birmingham <birm@rbirm.us>

* Update apps/table.html

* modifications for handling prototype

* removed unwanted console.logs

* Update functions to handle first time user registrations

* Fix to a missing .html extension

Co-authored-by: Ryan Birmingham <birm@rbirm.us>
  • Loading branch information
Vedant1202 and birm authored Apr 28, 2020
1 parent da94d8b commit 9487b88
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 32 deletions.
107 changes: 77 additions & 30 deletions apps/signup/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@

</head>
<script>
var userSignupUrl = "../../data/User/post"
var userSignupUrl = "../../data/User/post";
var protoTokenUrl = "../../auth/Token/proto";
var permissions;

function addUser(){
Expand All @@ -52,34 +53,80 @@
if (attr == "2"){
userType = "Editor"
}
// if (getUserType() === "Admin") {
if (permissions.user.post == true) {
var doc = {email: email, userType: userType, userFilter:filters}
fetch(userSignupUrl, {
method: 'POST',
mode: 'cors', // no-cors, cors, *same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(doc),
}).then(x=>{
if (x.status>=400){
throw "failed to sign up user"
}
x.json()
}).then(x=>{
window.alert("User registered successfully")
console.log(x)
}).catch(e=>{
// window.alert("error!")
console.error(e)
});
} else {
const store = new Store('../data/');
store.requestToCreateUser(email, filters, userType);
}

getUserPermissions(getUserType())
.then(response => response.text())
.then((data) => {
return (data ? JSON.parse(data) : null);
})
.then((data)=> {
if(data===null)
return;
permissions = data;
return;
})
.then((resp) => {
return fetch(protoTokenUrl)
})
.then((response) => {
// console.log(response);
return response.json();
})
.then((data) => {
return data.exists
})
.then((x) => {
if (x) {
var doc = {email: email, userType: userType, userFilter:filters}
fetch(userSignupUrl, {
method: 'POST',
mode: 'cors', // no-cors, cors, *same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(doc),
}).then(x=>{
if (x.status>=400){
throw "failed to sign up user"
}
x.json()
}).then(x=>{
window.alert("User registered successfully")
}).catch(e=>{
// window.alert("error!")
console.error(e)
});
} else {
if (permissions.user && permissions.user.post == true) {
var doc = {email: email, userType: userType, userFilter:filters}
fetch(userSignupUrl, {
method: 'POST',
mode: 'cors', // no-cors, cors, *same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(doc),
}).then(x=>{
if (x.status>=400){
throw "failed to sign up user"
}
x.json()
}).then(x=>{
window.alert("User registered successfully");
}).catch(e=>{
// window.alert("error!")
console.error(e)
});
} else {
const store = new Store('../data/');
store.requestToCreateUser(email, filters, userType);
}
}
});
}

$(window).on('load', function() {
Expand All @@ -95,7 +142,7 @@
if(data===null)
return;
permissions = data;
})
});
});

</script>
Expand Down
2 changes: 1 addition & 1 deletion apps/table.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@ nav li:not(.active):hover a{

.collapse.in {
display: inline !important;
}
}
2 changes: 1 addition & 1 deletion login.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
window.location = state
} else {
window.alert("User not added")
window.location = "./apps/signup/signup"
window.location = "./apps/signup/signup.html"
}

})
Expand Down

0 comments on commit 9487b88

Please sign in to comment.