mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-05-05 12:22:35 +02:00
Remove useless try/catch (errors already handled by the interceptor)
This commit is contained in:
parent
f434fcbc72
commit
747a5be567
3 changed files with 98 additions and 83 deletions
|
@ -26,6 +26,7 @@ export default {
|
||||||
|
|
||||||
let response = await this.$axios.get("/stream?start_index=" + this.start_idx + "&limit=" + this.limit);
|
let response = await this.$axios.get("/stream?start_index=" + this.start_idx + "&limit=" + this.limit);
|
||||||
|
|
||||||
|
// Errors are handled by the interceptor, which shows a modal dialog to the user and returns a null response.
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
this.loadingError = true
|
this.loadingError = true
|
||||||
|
|
|
@ -13,37 +13,40 @@ export default {
|
||||||
async login() {
|
async login() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.errormsg = null;
|
this.errormsg = null;
|
||||||
try {
|
|
||||||
let response = await this.$axios.post("/session", {
|
|
||||||
name: this.field_username,
|
|
||||||
});
|
|
||||||
//this.$router.push({ name: "home" });
|
|
||||||
if (response.status == 201 || response.status == 200) {
|
|
||||||
// Save the token in the local storage if the user wants to be remembered
|
|
||||||
if (this.rememberLogin) {
|
|
||||||
localStorage.setItem("token", response.data["user_id"])
|
|
||||||
sessionStorage.removeItem("token");
|
|
||||||
}
|
|
||||||
// Else save the token in the session storage
|
|
||||||
else {
|
|
||||||
sessionStorage.setItem("token", response.data["user_id"]);
|
|
||||||
localStorage.removeItem("token");
|
|
||||||
}
|
|
||||||
// Tell the root view to enable the navbar
|
|
||||||
this.$root.setLoggedIn();
|
|
||||||
// Update the header
|
|
||||||
this.$axiosUpdate();
|
|
||||||
|
|
||||||
// Go back to the previous page
|
let response = await this.$axios.post("/session", {
|
||||||
this.$router.go(-1);
|
name: this.field_username,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Errors are handled by the interceptor, which shows a modal dialog to the user and returns a null response.
|
||||||
|
if (response == null) {
|
||||||
|
this.loading = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.status == 201 || response.status == 200) {
|
||||||
|
// Save the token in the local storage if the user wants to be remembered
|
||||||
|
if (this.rememberLogin) {
|
||||||
|
localStorage.setItem("token", response.data["user_id"])
|
||||||
|
sessionStorage.removeItem("token");
|
||||||
}
|
}
|
||||||
|
// Else save the token in the session storage
|
||||||
else {
|
else {
|
||||||
this.errormsg = response.data["error"];
|
sessionStorage.setItem("token", response.data["user_id"]);
|
||||||
|
localStorage.removeItem("token");
|
||||||
}
|
}
|
||||||
|
// Tell the root view to enable the navbar
|
||||||
|
this.$root.setLoggedIn();
|
||||||
|
// Update the header
|
||||||
|
this.$axiosUpdate();
|
||||||
|
|
||||||
|
// Go back to the previous page
|
||||||
|
this.$router.go(-1);
|
||||||
}
|
}
|
||||||
catch (e) {
|
else {
|
||||||
this.errormsg = e.toString();
|
this.errormsg = response.data["error"];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -51,50 +54,57 @@ export default {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="vh-100 container py-5 h-100">
|
<div class="vh-100 container py-5 h-100">
|
||||||
<div class="row d-flex justify-content-center align-items-center h-100">
|
<div class="row d-flex justify-content-center align-items-center h-100">
|
||||||
<!--<div class="col-sm"><h2>* immagina un logo carino *</h2></div>-->
|
<!--<div class="col-sm"><h2>* immagina un logo carino *</h2></div>-->
|
||||||
<div class="col-12 col-md-8 col-lg-6 col-xl-5">
|
<div class="col-12 col-md-8 col-lg-6 col-xl-5">
|
||||||
<div class="card" style="border-radius: 1rem">
|
<div class="card" style="border-radius: 1rem">
|
||||||
<div class="card-body p-4">
|
<div class="card-body p-4">
|
||||||
|
|
||||||
<h1 class="h2 pb-4 text-center">WASAPhoto</h1>
|
<h1 class="h2 pb-4 text-center">WASAPhoto</h1>
|
||||||
|
|
||||||
<form>
|
<form>
|
||||||
<!-- Email input -->
|
<!-- Email input -->
|
||||||
<div class="form-floating mb-4">
|
<div class="form-floating mb-4">
|
||||||
<input v-model="field_username" type="email" id="formUsername" class="form-control" placeholder="name@example.com"/>
|
<input v-model="field_username" type="email" id="formUsername" class="form-control"
|
||||||
<label class="form-label" for="formUsername">Username</label>
|
placeholder="name@example.com" />
|
||||||
</div>
|
<label class="form-label" for="formUsername">Username</label>
|
||||||
|
</div>
|
||||||
<!-- Password input -->
|
|
||||||
<div class="form-floating mb-4">
|
<!-- Password input -->
|
||||||
<input style="display: none" disabled type="password" id="formPassword" class="form-control" placeholder="gattina12"/>
|
<div class="form-floating mb-4">
|
||||||
<label style="display: none" class="form-label" for="formPassword">Password</label>
|
<input style="display: none" disabled type="password" id="formPassword"
|
||||||
</div>
|
class="form-control" placeholder="gattina12" />
|
||||||
|
<label style="display: none" class="form-label" for="formPassword">Password</label>
|
||||||
<!-- 2 column grid layout for inline styling -->
|
</div>
|
||||||
<div class="row mb-4">
|
|
||||||
<div class="col d-flex justify-content-center">
|
<!-- 2 column grid layout for inline styling -->
|
||||||
<!-- Checkbox -->
|
<div class="row mb-4">
|
||||||
<div class="form-check">
|
<div class="col d-flex justify-content-center">
|
||||||
<input v-model="rememberLogin" class="form-check-input" type="checkbox" value="" id="form2Example31" />
|
<!-- Checkbox -->
|
||||||
<label class="form-check-label" for="form2Example31">Remember me</label>
|
<div class="form-check">
|
||||||
</div>
|
<input v-model="rememberLogin" class="form-check-input" type="checkbox" value=""
|
||||||
</div>
|
id="form2Example31" />
|
||||||
</div>
|
<label class="form-check-label" for="form2Example31">Remember me</label>
|
||||||
|
</div>
|
||||||
<!-- Submit button -->
|
</div>
|
||||||
<button style="width: 100%" type="button" class="btn btn-primary btn-block mb-4" @click="login">Sign in</button>
|
</div>
|
||||||
<ErrorMsg v-if="errormsg" :msg="errormsg"></ErrorMsg>
|
|
||||||
<LoadingSpinner :loading="loading" />
|
<!-- Submit button -->
|
||||||
<i class="text-center text-secondary d-flex flex-column">repeat after me: "best password is no password"</i>
|
<button style="width: 100%" type="button" class="btn btn-primary btn-block mb-4"
|
||||||
</form>
|
@click="login">Sign in</button>
|
||||||
</div>
|
<ErrorMsg v-if="errormsg" :msg="errormsg"></ErrorMsg>
|
||||||
|
<LoadingSpinner :loading="loading" />
|
||||||
|
<i class="text-center text-secondary d-flex flex-column">repeat after me: "best password is
|
||||||
|
no password"</i>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div></div>
|
</div>
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script>
|
<script>
|
||||||
// import getCurrentSession from '../services/authentication'; todo: can be removed
|
// import getCurrentSession from '../services/authentication'; todo: can be removed
|
||||||
export default {
|
export default {
|
||||||
data: function() {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
errormsg: null,
|
errormsg: null,
|
||||||
loading: false,
|
loading: false,
|
||||||
|
@ -28,16 +28,21 @@ export default {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
let response = await this.$axios.get("/users?query=" + this.fieldUsername + "&start_index=" + this.startIdx + "&limit=" + this.limit);
|
let response = await this.$axios.get("/users?query=" + this.fieldUsername + "&start_index=" + this.startIdx + "&limit=" + this.limit);
|
||||||
if (response.data.length == 0) this.dataEnded = true;
|
|
||||||
else this.streamData = this.streamData.concat(response.data);
|
// Errors are handled by the interceptor, which shows a modal dialog to the user and returns a null response.
|
||||||
this.loading = false;
|
if (response == null) {
|
||||||
} catch (e) {
|
this.loading = false
|
||||||
this.errormsg = e.toString(); // todo: handle better
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (response.data.length == 0) this.dataEnded = true;
|
||||||
|
else this.streamData = this.streamData.concat(response.data);
|
||||||
|
this.loading = false;
|
||||||
|
|
||||||
},
|
},
|
||||||
scroll () {
|
scroll() {
|
||||||
window.onscroll = () => {
|
window.onscroll = () => {
|
||||||
let bottomOfWindow = Math.max(window.pageYOffset, document.documentElement.scrollTop, document.body.scrollTop) + window.innerHeight >= document.documentElement.offsetHeight - 5
|
let bottomOfWindow = Math.max(window.pageYOffset, document.documentElement.scrollTop, document.body.scrollTop) + window.innerHeight >= document.documentElement.offsetHeight - 5
|
||||||
if (bottomOfWindow && !this.dataEnded) {
|
if (bottomOfWindow && !this.dataEnded) {
|
||||||
|
@ -67,17 +72,15 @@ export default {
|
||||||
|
|
||||||
<ErrorMsg v-if="errormsg" :msg="errormsg"></ErrorMsg>
|
<ErrorMsg v-if="errormsg" :msg="errormsg"></ErrorMsg>
|
||||||
|
|
||||||
<div class="form-floating mb-4">
|
<div class="form-floating mb-4">
|
||||||
<input v-model="fieldUsername" @input="refresh" id="formUsername" class="form-control" placeholder="name@example.com"/>
|
<input v-model="fieldUsername" @input="refresh" id="formUsername" class="form-control"
|
||||||
<label class="form-label" for="formUsername">Search by username</label>
|
placeholder="name@example.com" />
|
||||||
</div>
|
<label class="form-label" for="formUsername">Search by username</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="main-content" v-for="item of streamData">
|
<div id="main-content" v-for="item of streamData">
|
||||||
<UserCard
|
<UserCard :user_id="item.user_id" :name="item.name" :followed="item.followed"
|
||||||
:user_id="item.user_id"
|
:banned="item.banned" />
|
||||||
:name="item.name"
|
|
||||||
:followed="item.followed"
|
|
||||||
:banned="item.banned" />
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<LoadingSpinner :loading="loading" /><br />
|
<LoadingSpinner :loading="loading" /><br />
|
||||||
|
@ -89,4 +92,5 @@ export default {
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue