Sonntagsarbeiten #30
19
package-lock.json
generated
19
package-lock.json
generated
@ -13,7 +13,6 @@
|
|||||||
"@vue/cli-plugin-router": "~4.5.0",
|
"@vue/cli-plugin-router": "~4.5.0",
|
||||||
"@vue/cli-service": "~4.5.0",
|
"@vue/cli-service": "~4.5.0",
|
||||||
"@vue/compiler-sfc": "^3.0.0",
|
"@vue/compiler-sfc": "^3.0.0",
|
||||||
"axios": "^0.21.1",
|
|
||||||
"babel-eslint": "^10.1.0",
|
"babel-eslint": "^10.1.0",
|
||||||
"bootstrap": "^5.0.1",
|
"bootstrap": "^5.0.1",
|
||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
@ -2587,15 +2586,6 @@
|
|||||||
"integrity": "sha1-1h9G2DslGSUOJ4Ta9bCUeai0HFk=",
|
"integrity": "sha1-1h9G2DslGSUOJ4Ta9bCUeai0HFk=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/axios": {
|
|
||||||
"version": "0.21.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
|
|
||||||
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"follow-redirects": "^1.10.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/babel-eslint": {
|
"node_modules/babel-eslint": {
|
||||||
"version": "10.1.0",
|
"version": "10.1.0",
|
||||||
"resolved": "https://registry.npm.taobao.org/babel-eslint/download/babel-eslint-10.1.0.tgz",
|
"resolved": "https://registry.npm.taobao.org/babel-eslint/download/babel-eslint-10.1.0.tgz",
|
||||||
@ -16912,15 +16902,6 @@
|
|||||||
"integrity": "sha1-1h9G2DslGSUOJ4Ta9bCUeai0HFk=",
|
"integrity": "sha1-1h9G2DslGSUOJ4Ta9bCUeai0HFk=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"axios": {
|
|
||||||
"version": "0.21.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
|
|
||||||
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"follow-redirects": "^1.10.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"babel-eslint": {
|
"babel-eslint": {
|
||||||
"version": "10.1.0",
|
"version": "10.1.0",
|
||||||
"resolved": "https://registry.npm.taobao.org/babel-eslint/download/babel-eslint-10.1.0.tgz",
|
"resolved": "https://registry.npm.taobao.org/babel-eslint/download/babel-eslint-10.1.0.tgz",
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
"@vue/cli-plugin-router": "~4.5.0",
|
"@vue/cli-plugin-router": "~4.5.0",
|
||||||
"@vue/cli-service": "~4.5.0",
|
"@vue/cli-service": "~4.5.0",
|
||||||
"@vue/compiler-sfc": "^3.0.0",
|
"@vue/compiler-sfc": "^3.0.0",
|
||||||
"axios": "^0.21.1",
|
|
||||||
"babel-eslint": "^10.1.0",
|
"babel-eslint": "^10.1.0",
|
||||||
"bootstrap": "^5.0.1",
|
"bootstrap": "^5.0.1",
|
||||||
"core-js": "^3.6.5",
|
"core-js": "^3.6.5",
|
||||||
|
@ -2,29 +2,33 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
import axios from "axios";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
methods: {
|
||||||
async submitLogin() {
|
async submitLogin() {
|
||||||
this.showErrorMessage = false;
|
this.showErrorMessage = false;
|
||||||
try {
|
try {
|
||||||
const loginResult = await axios.post(
|
const data = JSON.stringify({
|
||||||
`${this.apiUrl}/users/login`,
|
|
||||||
{
|
|
||||||
username: this.username,
|
username: this.username,
|
||||||
password: this.password,
|
password: this.password,
|
||||||
|
})
|
||||||
|
|
||||||
|
const response = await fetch(`${this.apiUrl}/users/login`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: data
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
this.showErrorMessage = true
|
||||||
|
return
|
||||||
}
|
}
|
||||||
);
|
|
||||||
if (loginResult.status === 200) {
|
const responseData = await response.json()
|
||||||
this.showErrorMessage = false;
|
localStorage.setItem('token', responseData.token);
|
||||||
//success login
|
localStorage.setItem('user_id', responseData.user_id);
|
||||||
localStorage.setItem("token", loginResult.data.token);
|
this.$router.push({ path: '/s/search' });
|
||||||
localStorage.setItem("user_id", loginResult.data.user_id);
|
|
||||||
this.$router.push({ path: "/s/search" });
|
|
||||||
} else {
|
|
||||||
this.showErrorMessage = true;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
this.showErrorMessage = true;
|
this.showErrorMessage = true;
|
||||||
@ -32,16 +36,22 @@ export default {
|
|||||||
},
|
},
|
||||||
async search() {
|
async search() {
|
||||||
try {
|
try {
|
||||||
const request = await axios.get(
|
const response = await fetch(`${this.apiUrl}/${this.type}s?search=${this.searchText}`, {
|
||||||
`${this.apiUrl}/${this.type}s?search=${this.searchText}`,
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if (request.status === 200) {
|
|
||||||
this.searchResults = request.data[`${this.type}s`];
|
if (!response.ok) {
|
||||||
|
console.error();
|
||||||
|
this.showErrorMessage = true;
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const responseData = await response.json()
|
||||||
|
this.searchResults = responseData[`${this.type}s`];
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!this.values
|
!this.values
|
||||||
.map((item) => item[this.type].name.toLowerCase())
|
.map((item) => item[this.type].name.toLowerCase())
|
||||||
@ -49,43 +59,58 @@ export default {
|
|||||||
) {
|
) {
|
||||||
this.searchResults.unshift({ name: this.searchText });
|
this.searchResults.unshift({ name: this.searchText });
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error();
|
console.error();
|
||||||
this.showErrorMessage = true;
|
this.showErrorMessage = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async initEditPage() {
|
async initEditPage() {
|
||||||
|
const userId = localStorage.getItem('user_id')
|
||||||
|
const url = `${this.apiUrl}/users/${userId}/profile`
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const userProfile = await axios.get(
|
const response = await fetch(url, {
|
||||||
`${this.apiUrl}/users/${localStorage.getItem("user_id")}/profile`,
|
headers: {
|
||||||
{
|
Authorization: `Bearer ${localStorage.getItem("token")}`
|
||||||
headers: { Authorization: `Bearer ${localStorage.getItem("token")}` },
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
this.profile = userProfile.data.profile;
|
|
||||||
|
if (!response.ok) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const responseData = await response.json()
|
||||||
|
|
||||||
|
this.profile = responseData.profile;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async submitFormEdit() {
|
async submitFormEdit() {
|
||||||
|
this.showErrorMessage = false
|
||||||
|
this.showSuccessMessage = false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const formSubmitResult = await axios.post(
|
const body = JSON.stringify(this.profile)
|
||||||
|
const response = await fetch(
|
||||||
`${this.apiUrl}/users/${localStorage.getItem("user_id")}/profile`,
|
`${this.apiUrl}/users/${localStorage.getItem("user_id")}/profile`,
|
||||||
this.profile,
|
|
||||||
{
|
{
|
||||||
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
|
body
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if (formSubmitResult.status === 200) {
|
|
||||||
// success
|
if (!response.ok) {
|
||||||
this.showSuccessMessage = true;
|
this.showErrorMessage = true
|
||||||
} else {
|
return
|
||||||
// failure
|
|
||||||
this.showErrorMessage = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.showSuccessMessage = true
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
this.showErrorMessage = true;
|
this.showErrorMessage = true;
|
||||||
@ -93,31 +118,46 @@ export default {
|
|||||||
},
|
},
|
||||||
async initViewPage() {
|
async initViewPage() {
|
||||||
try {
|
try {
|
||||||
const userProfile = await axios.get(
|
const response = await fetch(`${this.apiUrl}/users/${this.$route.params.memberId}/profile`, {
|
||||||
`${this.apiUrl}/users/${this.$route.params.memberId}/profile`,
|
|
||||||
{
|
|
||||||
headers: { Authorization: `Bearer ${localStorage.getItem("token")}` },
|
headers: { Authorization: `Bearer ${localStorage.getItem("token")}` },
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
this.profile = userProfile.data.profile;
|
|
||||||
|
if (!response.ok) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const responseData = await response.json()
|
||||||
|
this.profile = responseData.profile;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async submitSearch() {
|
async submitSearch() {
|
||||||
this.showErrorMessage = false;
|
this.showErrorMessage = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let url = `${this.apiUrl}/users/profiles`;
|
const url = new URL(`${this.apiUrl}/users/profiles`)
|
||||||
|
|
||||||
if (this.searchText != "") {
|
if (this.searchText != "") {
|
||||||
url += `?nickname=${this.searchText}`;
|
url.searchParams.append('nickname', this.searchText)
|
||||||
}
|
}
|
||||||
const result = await axios.get(url, {
|
|
||||||
|
const response = await fetch(url, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.searchResults = result.data.profiles;
|
|
||||||
this.searchTotal = result.data.total;
|
if (!response.ok) {
|
||||||
|
this.showErrorMessage = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const responseData = await response.json()
|
||||||
|
|
||||||
|
this.searchResults = responseData.profiles;
|
||||||
|
this.searchTotal = responseData.total;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
this.showErrorMessage = true;
|
this.showErrorMessage = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user