Skip to content

Commit

Permalink
Merge pull request #23 from ConeGroup/userprofile
Browse files Browse the repository at this point in the history
Userprofile
  • Loading branch information
nandapratama21 committed Oct 29, 2023
2 parents ecf2d1b + b2dd2b6 commit 5ffb019
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 6 deletions.
87 changes: 87 additions & 0 deletions userprofile/static/js/userprofile2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

async function saveChanges() {


var formData = new FormData(document.getElementById("edit-profile-form"));

var username = formData.get('username');
var email = formData.get('email');

if (!username || !email) {
// Jika input kosong, tampilkan pesan kesalahan atau lakukan tindakan sesuai kebutuhan
showAlert("Please fill the form!", 'warning');
return;
}
fetch("/userprofile/edit_profile_ajax", {
method: "POST",
body: formData,
})
.then(response => {
response.json();
showAlert('Username and Email Has Been Successfully Changed!','warning');
}).catch(error => {
// Tangani kesalahan jika fetch gagal

// Kembalikan teks awal jika terjadi kesalahan
});
var linkElement2 = document.getElementById("usernametextprofiledetails");
var linkElement3 = document.getElementById("useremailtextprofiledetails");
linkElement2.textContent = document.getElementById('inputusername').value;
linkElement3.textContent = document.getElementById('inputuseremail').value;
}


async function savePassword() {
var formData = new FormData(document.getElementById("change-password-form"));
var oldpassword = formData.get('old_password');
var newpassword = formData.get('new_password1');
var newpasswordconfirm = formData.get('new_password2')
var error = false;
if (!oldpassword || !newpassword || !newpasswordconfirm) {
// Jika input kosong, tampilkan pesan kesalahan atau lakukan tindakan sesuai kebutuhan
showAlert("Please fill the form!", 'warning');
return;
}
if(newpassword != newpasswordconfirm) {
showAlert('Wrong confirm Password','warning');
return;
}


fetch("/userprofile/change_password_ajax", {
method: "POST",
body: formData,
})
.then(response => {
if (!response.ok) {
throw new Error('Password Error');
}
else {
showAlert('Password Has Been Successfully Changed!','warning');
}
return response.text();
})
.then(data => {
// Handle your successful response here
})
.catch(error => {
if (error.message === 'Password Error') {
showAlert('Change Password is not valid, read the rules','warning');
}
});


}

function showAlert(message, category) {
var html = '<div class="alert alert-' + category + ' alert-dismissible fade show" role="alert">' +
message +
'<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>' +
'</div>';

document.getElementById('alert_placeholder').innerHTML = html;
}




11 changes: 5 additions & 6 deletions userprofile/templates/userprofile.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@


{% block content %}
{% include 'navbar2.html' %}
{% include 'navbar.html' %}
<style>
body {margin: 0; height: 100vh; background-color: rgba(224, 236, 244);
background-attachment: fixed; background-size: cover; background-repeat: no-repeat;
}

.card {
background-color: rgba(224, 236, 244);
}

</style>

Expand Down Expand Up @@ -195,7 +194,7 @@ <h1>Rules:</h1>


{% load static %}
<script type="application/javascript" src="{% static 'js/script.js' %}">
<script type="application/javascript" src="{% static 'js/userprofile2.js' %}">



Expand Down

0 comments on commit 5ffb019

Please sign in to comment.