Files
XP-System/views/edit.ejs
T
2021-04-04 22:06:26 -07:00

99 lines
3.7 KiB
Plaintext

<div style="margin: 15px;" id="div-container"></div>
<div class="row mt-5">
<div class="col-md-6 m-auto">
<div class="card card-body">
<h1 class="text-center mb-3">
<i class="fas fa-user-cog"></i> Edit Account
</h1>
<% include ./partials/messages %>
<form action="/users/edit" method="POST" enctype="multipart/form-data">
<!-- Catching _id -->
<script>
window.onload = function () {
var url = document.location.href,
params = url.split('?')[1].split('&'),
data = {}, tmp;
for (var i = 0, l = params.length; i < l; i++) {
tmp = params[i].split('=');
data[tmp[0]] = tmp[1];
}
document.getElementById('_id').value = data.name;
}
</script>
<input id='_id' type='text' name='_id' value='' style='display: none'></input>
<div class="form-group">
<label for="name">Name</label>
<input
type="name"
id="name"
name="name"
class="form-control"
placeholder="Enter Name"
value="<%= typeof name != 'undefined' ? name : '' %>"
/>
</div>
<div class='form-group'>
<label for='image'>Change Profile Picture</label>
<input class='form-control-file' type="file" id="image" name="image" value="">
</div>
<div class="form-group">
<label for="password2">New Password</label>
<input
type="password"
id="newPassword"
name="newPassword"
class="form-control"
placeholder="New Password"
value="<%= typeof password2 != 'undefined' ? password2 : '' %>"
/>
</div>
<div class="form-group">
<label for="password2">Confirm New Password</label>
<input
type="password"
id="newPassword2"
name="newPassword2"
class="form-control"
placeholder="Confirm New Password"
value="<%= typeof password2 != 'undefined' ? password2 : '' %>"
/>
</div>
<button type="submit" class="btn btn-primary btn-block">
Save Changes
</button>
</form>
</div>
</div>
</div>
<script>
// Creates unique ID
function makeid(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
// Create Div
// Stole this function from teacherDashboard to make a single FYI note
// I know its pretty dumb
function createDiv(type, message) {
let id = makeid(8);
if (type == 'error') {
document.getElementById('div-container').innerHTML += '<div id="new-div-'+id+'" style="display: none;" class="alert alert-warning alert-dismissible fade show" role="alert">';
}
if (type == 'message') {
document.getElementById('div-container').innerHTML += '<div id="new-div-'+id+'" style="display: none;" class="alert alert-info alert-dismissible fade show" role="alert">';
}
document.getElementById('new-div-'+id).innerHTML += '<div id="message'+id+'">'+message+'</div>';
document.getElementById('new-div-'+id).innerHTML += '<button id="close-btn-'+id+'" class="close" data-dismiss="alert" aria-label="Close"></button>';
document.getElementById('close-btn-'+id).innerHTML += '<span aria-hidden="true">&times;</span>';
document.getElementById('new-div-'+id).style.display = "block";
}
createDiv('message', 'FYI: Only enter the fields you want to change');
</script>