登录
-.search input {
- border: 2px solid gray;
- border-radius: 5px;
- background: transparent;
- top: 0;
- right: 0;
+
diff --git a/frontend/src/main.js b/frontend/src/main.js
index 8c88c13..b3a9cf4 100644
--- a/frontend/src/main.js
+++ b/frontend/src/main.js
@@ -10,4 +10,5 @@ URLSearchParams.prototype.appendIfExists = function (key, value) {
};
+
createApp(App).use(store).use(router).mount('#app')
diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js
index 3e6a413..ec4056f 100644
--- a/frontend/src/router/index.js
+++ b/frontend/src/router/index.js
@@ -3,6 +3,7 @@ import HomePage from '@/views/HomePageView.vue'
import ArticleDetail from '@/views/ArticleDetailView.vue'
import LoginView from '@/views/LoginView.vue'
import RegisterView from '@/views/RegisterView.vue'
+import UserCenter from '@/views/UserCenterView.vue'
const routes = [
{
@@ -24,7 +25,12 @@ const routes = [
path: '/register/',
name: 'register',
component: RegisterView,
- }
+ },
+ {
+ path: "/user/:username",
+ name: "UserCenter",
+ component: UserCenter,
+ },
]
const router = createRouter({
diff --git a/frontend/src/utils/authorization.js b/frontend/src/utils/authorization.js
new file mode 100644
index 0000000..b344526
--- /dev/null
+++ b/frontend/src/utils/authorization.js
@@ -0,0 +1,59 @@
+import $ from 'jquery';
+
+const authorization = async () => {
+ const storage = localStorage;
+
+ let haslogin = false;
+ // 用户名
+ let username = storage.getItem('username_blog');
+ // 过期时间
+ const expired_time = Number(storage.getItem("expired_time"));
+ console.log("expired_time ",new Date(expired_time).toLocaleString());
+ // 当前时间
+ const current = new Date().getTime();
+ // 刷新令牌
+ const refreshToken = storage.getItem("refresh_blog");
+ // 未过期
+ if (expired_time > current) {
+ haslogin = true;
+ console.log('authorization success');
+ }
+ // 初始tokeng过期,则由刷新令牌申请新的token
+ else if (refreshToken !== null) {
+ try {
+ $.ajax({
+ url: "http://127.0.0.1:6789/api/token/refresh/",
+ type: "POST",
+ async: false,
+ data: {
+ refresh: refreshToken,
+ },
+ success(resp) {
+ const nextExpiredTime = new Date().getTime() + 60000;
+ storage.setItem("access_blog", resp.access);
+ storage.removeItem("refresh_blog"); // 移除刷新令牌
+ console.log(
+ "令牌刷新时间: ",
+ new Date().toLocaleString()
+ );
+ storage.setItem("expired_time", nextExpiredTime);
+ haslogin = true;
+ },
+ });
+ }catch(err){
+ storage.clear();
+ haslogin = false;
+ console.log('authorization err');
+ }
+
+ } else {
+ storage.clear(); // 清除所有有效信息
+ haslogin = false;
+ console.log('authorization exp');
+ }
+
+ console.log('authorization done');
+ return [haslogin, username];
+}
+
+export default authorization;
\ No newline at end of file
diff --git a/frontend/src/views/LoginView.vue b/frontend/src/views/LoginView.vue
index b6b501f..d05896b 100644
--- a/frontend/src/views/LoginView.vue
+++ b/frontend/src/views/LoginView.vue
@@ -48,8 +48,6 @@ export default {
setup() {
let username = ref("");
let password = ref("");
- const current = (new Date()).getTime();
- console.log(current);
const login = () => {
$.ajax({
@@ -62,7 +60,6 @@ export default {
success(resp) {
// 将token保存到localStorage
const storage = localStorage;
-
const current = (new Date()).getTime();
const expiredTime = current + 60000;
storage.setItem('access_blog', resp.access);
@@ -71,7 +68,6 @@ export default {
storage.setItem('username_blog', username.value);
console.log("登录时间: ",new Date().toLocaleString());
router.push({ name: "home" });
-
},
error(resp) {
console.log(resp);
diff --git a/frontend/src/views/UserCenterView.vue b/frontend/src/views/UserCenterView.vue
new file mode 100644
index 0000000..4b3c328
--- /dev/null
+++ b/frontend/src/views/UserCenterView.vue
@@ -0,0 +1,205 @@
+
+
+
+
+
+
+
+
+
diff --git a/frontend/vue.config.js b/frontend/vue.config.js
index 910e297..af1adf4 100644
--- a/frontend/vue.config.js
+++ b/frontend/vue.config.js
@@ -2,3 +2,4 @@ const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true
})
+