merged with master
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
let set = { username: '', tfa: false };
|
||||
let nameTmp; // annoying...
|
||||
const errors = { username: '', checkbox: '', avatar: ''};
|
||||
let success = {username: '', avatar: '' };
|
||||
|
||||
onMount( async() => {
|
||||
user = await fetch('http://transcendance:8080/api/v2/user')
|
||||
@@ -50,51 +51,41 @@
|
||||
})
|
||||
|
||||
const settingsHandler = async() => {
|
||||
let valid = false;
|
||||
|
||||
// I don't really care which i use at this point...
|
||||
// if (set.username === nameTmp) {
|
||||
// if (set.username === user.username || (set.username !== '' && set.username.trim() === '')) {
|
||||
// if (set.username !== '' && set.username.trim() === '') {
|
||||
if (set.username === undefined || (set.username !== '' && set.username.trim() === '')) {
|
||||
if ((set.username.trim() === '') && set.tfa === user.isEnabledTwoFactorAuth) {
|
||||
errors.username = 'Invalid new username';
|
||||
valid = false;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
else if ((set.username.trim() === '') && set.tfa !== user.isEnabledTwoFactorAuth) {
|
||||
set.username = user.username
|
||||
}
|
||||
else {
|
||||
errors.username = '';
|
||||
valid = true;
|
||||
}
|
||||
if (set.username === '') {
|
||||
// set.username = nameTmp;
|
||||
set.username = user.username;
|
||||
}
|
||||
await fetch('http://transcendance:8080/api/v2/user',{
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
"username": set.username,
|
||||
"isEnabledTwoFactorAuth": set.tfa
|
||||
})
|
||||
})
|
||||
.then((response) => {
|
||||
if (response.status === 200)
|
||||
success.username = "Your changes have been saved"
|
||||
else if (response.status === 201)
|
||||
push("/2fa")
|
||||
else
|
||||
errors.username = "Something went wrong"
|
||||
}
|
||||
)
|
||||
.catch((err) => errors.username = err)
|
||||
|
||||
console.log("valid is " + valid)
|
||||
console.log("username is " + set.username)
|
||||
|
||||
if (valid) {
|
||||
console.log('settings valid about to fetch')
|
||||
const response = await fetch('http://transcendance:8080/api/v2/user',
|
||||
{
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
"username": set.username,
|
||||
"isEnabledTwoFactorAuth": set.tfa
|
||||
})
|
||||
})
|
||||
// .then(() => push('/profile'))
|
||||
// .then(response => response.json())
|
||||
// .then((result) => console.log("this is result " + result))
|
||||
// .then((result) => console.log(result))
|
||||
// .then(() => console.log('successful sub of new settings'))
|
||||
console.log('end of settings is valid')
|
||||
// if (response.status === 200) {
|
||||
// push('/profile');
|
||||
// console.log('valid Code for 2FA')
|
||||
// }
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const uploadAvatar = async() => {
|
||||
@@ -103,23 +94,28 @@
|
||||
errors.avatar = 'You need to pick a file.'
|
||||
return;
|
||||
}
|
||||
const data = new FormData();
|
||||
data.append("file", newAvatar[0]);
|
||||
const data = new FormData();
|
||||
data.append("file", newAvatar[0]);
|
||||
|
||||
// tmp
|
||||
console.log(data);
|
||||
// tmp
|
||||
console.log(data);
|
||||
|
||||
await fetch("http://transcendance:8080/api/v2/user/avatar",
|
||||
{
|
||||
method : 'POST',
|
||||
body : data,
|
||||
})
|
||||
.then(() => uploadAvatarSuccess = true ) // for some reason it needs to be a function, i think a TS thing, not a promis otherwise
|
||||
.then(() => push('/profile') )
|
||||
.catch(() => errors.avatar = 'Sorry failed to upload your new Avatar' )
|
||||
// some of this shit is unnecessary...
|
||||
// also i'm not convinced the .catch works...
|
||||
}
|
||||
await fetch("http://transcendance:8080/api/v2/user/avatar",
|
||||
{
|
||||
method : 'POST',
|
||||
body : data,
|
||||
})
|
||||
.then(() => uploadAvatarSuccess = true ) // for some reason it needs to be a function, i think a TS thing, not a promis otherwise
|
||||
.then(() => success.avatar = 'Your changes have been saved')
|
||||
.catch(() => errors.avatar = 'Sorry failed to upload your new Avatar' );
|
||||
await fetch("http://transcendance:8080/api/v2/user/avatar", {method: "GET"})
|
||||
.then(response => {return response.blob()})
|
||||
.then(data => {
|
||||
const url = URL.createObjectURL(data);
|
||||
avatar = url;
|
||||
})
|
||||
.catch(() => errors.avatar = 'Sorry your avatar could not be loaded' );
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
@@ -134,6 +130,7 @@
|
||||
<!-- it really hates {user.username} and ${user.username} -->
|
||||
<!-- <input type="text" placeholder="current username: ${user.username}" bind:value={set.username}> -->
|
||||
<input type="text" placeholder="current username: {nameTmp}" bind:value={set.username}>
|
||||
<div class="success">{success.username}</div>
|
||||
<div class="error">{errors.username}</div>
|
||||
</div>
|
||||
<div class="form-field">
|
||||
@@ -217,5 +214,10 @@
|
||||
color: red;
|
||||
}
|
||||
|
||||
.success{
|
||||
font-size: 0.8em;
|
||||
font-weight: bold;
|
||||
color: green;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user