Kaynağa Gözat

Merge branch 'master' of http://git.choozmo.com:3000/ai-anchor/video-maker

tomoya 2 yıl önce
ebeveyn
işleme
a1368a9455

+ 1 - 1
frontend/src/App.vue

@@ -10,7 +10,7 @@
 import { RouterView } from "vue-router";
 import { useMainStore } from "@/stores/main";
 import { onMounted } from "vue";
-import LoadingView from "./views/LoadingView.vue";
+import LoadingView from "@/components/Loading.vue";
 import { storeToRefs } from "pinia";
 import NotificationsManager from "@/components/NotificationsManager.vue";
 //store

+ 4 - 4
frontend/src/api.ts

@@ -1,6 +1,6 @@
 import axios from "axios";
 import { apiUrl } from "@/env";
-import type { IUserProfile, IUserProfileUpdate, IUserProfileCreate, IUserProfileRegister } from "@/interfaces";
+import type { IUserProfile, IUserProfileUpdate, IUserProfileCreate} from "@/interfaces";
 
 function authHeaders(token: string) {
   return {
@@ -40,13 +40,13 @@ export const api = {
   async passwordRecovery(email: string) {
     return axios.post(`${apiUrl}/api/v1/password-recovery/${email}`);
   },
-  async resetPassword(password: string, token: string) {
+  async resetPassword(token: string, password: string) {
     return axios.post(`${apiUrl}/api/v1/reset-password/`, {
+      token: token,
       new_password: password,
-      token,
     });
   },
-  async registerUser(data: IUserProfileRegister) {
+  async registerUser(data: IUserProfileCreate) {
     return axios.post(`${apiUrl}/api/v1/users/register`, data);
   },
   async testCeleryMsg(token: string, data:{msg: string}){

+ 0 - 0
frontend/src/views/LoadingView.vue → frontend/src/components/Loading.vue


+ 1 - 1
frontend/src/components/NotificationsManager.vue

@@ -12,7 +12,7 @@
 
 <script setup lang="ts">
   import { ref, computed, watch } from 'vue';
-  import type { AppNotification } from '@/stores/main';
+  import type { AppNotification } from '@/interfaces';
   import { useMainStore } from '@/stores/main';
   import { storeToRefs } from 'pinia';
 

+ 15 - 4
frontend/src/interfaces/index.ts

@@ -22,7 +22,18 @@ export interface IUserProfileCreate {
     is_superuser?: boolean;
 }
 
-export interface IUserProfileRegister {
-    email: string;
-    password: string;
-}
+export interface AppNotification {
+  content: string;
+  color?: string;
+  showProgress?: boolean;
+};
+
+export interface MainState {
+  token: string;
+  isLoggedIn: boolean | null;
+  logInError: boolean;
+  userProfile: IUserProfile | null;
+  dashboardMiniDrawer: boolean;
+  dashboardShowDrawer: boolean;
+  notifications: AppNotification[];
+};

+ 112 - 112
frontend/src/stores/admin.ts

@@ -9,121 +9,121 @@ interface AdminState {
 }
 
 const defaultState: AdminState = {
-    users: [],
+  users: [],
 };
   
 export const useAdminStore = defineStore("AdminStoreId", {
-    state: () => defaultState,
-    getters: {
-        readAdminUsers: (state) => state.users,
-        readAdminOneUser: (state) => {
-          return (userId:number) => state.users.filter((user) => user.id === userId)[0] || undefined;
-        },
-    },
-    actions: {
-        // setters
-        setUsers(payload: IUserProfile[]) {
-          this.users = payload;
-        },
-        setUser(payload: IUserProfile) {
-          const users = this.users.filter((user: IUserProfile) => user.id !== payload.id);
-          users.push(payload);
-          this.users = users;
-        },
-        
-        // actions
-        async actionGetUsers(){
-          const mainStore = useMainStore();
-          try {
-              const response = await api.getUsers(mainStore.token)
-              if (response) {
-                this.setUsers(response.data);
-              }
-          } catch (error) {
-              await mainStore.checkApiError(error);
-          }
-        },
-        async actionUpdateUser(payload: { id: number; user: IUserProfileUpdate }) {
-            const mainStore = useMainStore();
-            try {
-                const loadingNotification = { content: "saving", showProgress: true };
-                mainStore.addNotification(loadingNotification);
-                const response = (
-                  await Promise.all([
-                    api.updateUser(mainStore.token, payload.id, payload.user),
-                    await new Promise<void>((resolve, _) => setTimeout(() => resolve(), 500)),
-                  ])
-                )[0];
-                this.setUser(response.data);
-                mainStore.removeNotification(loadingNotification);
-                mainStore.addNotification({
-                  content: "User successfully updated",
-                  color: "success",
-                });
-            } catch (error) {
-                await mainStore.checkApiError(error);
-            }
-        },
-        async actionCreateUser(payload: IUserProfileCreate) {
-            const mainStore = useMainStore();
-            try {
-              const loadingNotification = { content: "saving", showProgress: true };
-              mainStore.addNotification(loadingNotification);
-              const response = (
-                await Promise.all([
-                  api.createUser(mainStore.token, payload),
-                  await new Promise<void>((resolve, _) => setTimeout(() => resolve(), 500)),
-                ])
-              )[0];
-              this.setUser(response.data);
-              mainStore.removeNotification(loadingNotification);
-              mainStore.addNotification({
-                content: "User successfully created",
-                color: "success",
-              });
-            } catch (error) {
-              await mainStore.checkApiError(error);
-            }
-        },
-        async actionTestCeleryMsg(payload: {msg:string}) {
-          const mainStore = useMainStore();
-          try {
-            const loadingNotification = { content: "sending", showProgress: true };
-            mainStore.addNotification(loadingNotification);
-            const response = (
-              await Promise.all([
-                api.testCeleryMsg(mainStore.token, payload),
-                await new Promise<void>((resolve, _) => setTimeout(() => resolve(), 500)),
-              ])
-            );
-            mainStore.removeNotification(loadingNotification);
-            mainStore.addNotification({
-              content: "Word received",
-                color: "success",
-            })
-          } catch (error) {
-            await mainStore.checkApiError(error);
-          }
-        },
-        async actionTestCeleryFile(payload: File) {
-          const mainStore = useMainStore();
-          try {
-            const loadingNotification = { content: "sending", showProgress: true };
-            mainStore.addNotification(loadingNotification);
-            const response = (
-              await Promise.all([
-                api.testCeleryFile(mainStore.token, payload),
-                await new Promise<void>((resolve, _) => setTimeout(() => resolve(), 500)),
-              ])
-            );
-            mainStore.removeNotification(loadingNotification);
-            mainStore.addNotification({
-              content: "File received",
-                color: "success",
-            })
-          } catch (error) {
-            await mainStore.checkApiError(error);
+  state: () => defaultState,
+  getters: {
+      readAdminUsers: (state) => state.users,
+      readAdminOneUser: (state) => {
+        return (userId:number) => state.users.filter((user) => user.id === userId)[0] || undefined;
+      },
+  },
+  actions: {
+      // setters
+      setUsers(payload: IUserProfile[]) {
+        this.users = payload;
+      },
+      setUser(payload: IUserProfile) {
+        const users = this.users.filter((user: IUserProfile) => user.id !== payload.id);
+        users.push(payload);
+        this.users = users;
+      },
+      
+      // actions
+      async actionGetUsers(){
+        const mainStore = useMainStore();
+        try {
+          const response = await api.getUsers(mainStore.token)
+          if (response) {
+            this.setUsers(response.data);
           }
+        } catch (error) {
+          await mainStore.checkApiError(error);
+        }
+      },
+      async actionUpdateUser(payload: { id: number; user: IUserProfileUpdate }) {
+        const mainStore = useMainStore();
+        try {
+          const loadingNotification = { content: "saving", showProgress: true };
+          mainStore.addNotification(loadingNotification);
+          const response = (
+            await Promise.all([
+              api.updateUser(mainStore.token, payload.id, payload.user),
+              await new Promise<void>((resolve, _) => setTimeout(() => resolve(), 500)),
+            ])
+          )[0];
+          this.setUser(response.data);
+          mainStore.removeNotification(loadingNotification);
+          mainStore.addNotification({
+            content: "User successfully updated",
+            color: "success",
+          });
+        } catch (error) {
+          await mainStore.checkApiError(error);
+        }
+      },
+      async actionCreateUser(payload: IUserProfileCreate) {
+        const mainStore = useMainStore();
+        try {
+          const loadingNotification = { content: "saving", showProgress: true };
+          mainStore.addNotification(loadingNotification);
+          const response = (
+            await Promise.all([
+              api.createUser(mainStore.token, payload),
+              await new Promise<void>((resolve, _) => setTimeout(() => resolve(), 500)),
+            ])
+          )[0];
+          this.setUser(response.data);
+          mainStore.removeNotification(loadingNotification);
+          mainStore.addNotification({
+            content: "User successfully created",
+            color: "success",
+          });
+        } catch (error) {
+          await mainStore.checkApiError(error);
+        }
+      },
+      async actionTestCeleryMsg(payload: {msg:string}) {
+        const mainStore = useMainStore();
+        try {
+          const loadingNotification = { content: "sending", showProgress: true };
+          mainStore.addNotification(loadingNotification);
+          const response = (
+            await Promise.all([
+              api.testCeleryMsg(mainStore.token, payload),
+              await new Promise<void>((resolve, _) => setTimeout(() => resolve(), 500)),
+            ])
+          );
+          mainStore.removeNotification(loadingNotification);
+          mainStore.addNotification({
+            content: "Word received",
+              color: "success",
+          })
+        } catch (error) {
+          await mainStore.checkApiError(error);
+        }
+      },
+      async actionTestCeleryFile(payload: File) {
+        const mainStore = useMainStore();
+        try {
+          const loadingNotification = { content: "sending", showProgress: true };
+          mainStore.addNotification(loadingNotification);
+          const response = (
+            await Promise.all([
+              api.testCeleryFile(mainStore.token, payload),
+              await new Promise<void>((resolve, _) => setTimeout(() => resolve(), 500)),
+            ])
+          );
+          mainStore.removeNotification(loadingNotification);
+          mainStore.addNotification({
+            content: "File received",
+              color: "success",
+          })
+        } catch (error) {
+          await mainStore.checkApiError(error);
         }
-    },
+      }
+  },
 });

+ 11 - 26
frontend/src/stores/main.ts

@@ -3,32 +3,17 @@ import { defineStore } from "pinia";
 import { api } from "@/api"
 import router from "@/router"
 import { getLocalToken, removeLocalToken, saveLocalToken } from "@/utils";
-import type { IUserProfile, IUserProfileRegister, IUserProfileUpdate } from '@/interfaces';
-
-export interface AppNotification {
-  content: string;
-  color?: string;
-  showProgress?: boolean;
-};
-
-interface MainState {
-  token: string;
-  isLoggedIn: boolean | null;
-  logInError: boolean;
-  userProfile: IUserProfile | null;
-  dashboardMiniDrawer: boolean;
-  dashboardShowDrawer: boolean;
-  notifications: AppNotification[];
-};
+import type { AppNotification } from '@/interfaces';
+import type { IUserProfile, IUserProfileCreate, IUserProfileUpdate, MainState } from '@/interfaces';
 
 const defaultState: MainState = {
-    isLoggedIn: null,
-    token: '',
-    logInError: false,
-    userProfile: null,
-    dashboardMiniDrawer: false,
-    dashboardShowDrawer: true,
-    notifications: [],
+  isLoggedIn: null,
+  token: '',
+  logInError: false,
+  userProfile: null,
+  dashboardMiniDrawer: false,
+  dashboardShowDrawer: true,
+  notifications: [],
 };
 
 export const useMainStore = defineStore("MainStoreId", {
@@ -196,7 +181,7 @@ export const useMainStore = defineStore("MainStoreId", {
               await this.checkApiError(error);
           }
         },
-        async passwordRecovery(username: string) {
+        async passwordRecovery(payload: {username: string }) {
             const loadingNotification = {
                 content: "Sending password recovery email",
                 showProgress: true,
@@ -204,7 +189,7 @@ export const useMainStore = defineStore("MainStoreId", {
             try {
                 this.addNotification(loadingNotification);
                 await Promise.all([
-                  api.passwordRecovery(username),
+                  api.passwordRecovery(payload.username),
                   await new Promise<void>((resolve, _) => setTimeout(() => resolve(), 500)),
                 ]);
                 this.removeNotification(loadingNotification);

+ 0 - 53
frontend/src/views/Login.vue

@@ -103,57 +103,4 @@ onMounted(() => {});
       </v-col>
     </v-row>
   </v-container>
-
-  <!-- <v-container fluid class="d-flex fill-height">
-    <v-row align="center" justify="center">
-      <v-col :cols="width">
-        <v-card class="elevation-12">
-          <v-toolbar dark color="primary">
-            <v-toolbar-title>{{ appName }}</v-toolbar-title>
-            <v-spacer></v-spacer>
-            <v-btn to="/signup">SignUp</v-btn>
-          </v-toolbar>
-          <v-card-text>
-            <v-form @keyup.enter="submit">
-              <v-text-field
-                @keyup.enter="submit"
-                v-model="email"
-                prepend-icon="person"
-                name="email"
-                label="Email"
-                type="text"
-              ></v-text-field>
-              <v-text-field
-                @keyup.enter="submit"
-                v-model="password"
-                prepend-icon="key"
-                name="password"
-                label="Password"
-                id="password"
-                type="password"
-              ></v-text-field>
-            </v-form>
-            <div v-if="loginError">
-              <v-alert
-                :value="loginError"
-                transition="fade-transition"
-                type="error"
-              >
-                Incorrect email or password
-              </v-alert>
-            </div>
-            <div class="d-flex align-end flex-column">
-              <router-link to="/recover-password"
-                >Forgot your password?</router-link
-              >
-            </div>
-          </v-card-text>
-          <v-card-actions>
-            <v-spacer></v-spacer>
-            <v-btn @click.prevent="submit">Login</v-btn>
-          </v-card-actions>
-        </v-card>
-      </v-col>
-    </v-row>
-  </v-container> -->
 </template>

+ 1 - 1
frontend/src/views/ResetPassword.vue

@@ -86,7 +86,7 @@ async function submit(){
   if (valid.value) {
     const token = checkToken();
     if (token) {
-      await mainStore.resetPassword({token, password: password1.value});
+      await mainStore.resetPassword(token, password1.value);
       router.push('/');
     }
   }

+ 0 - 36
frontend/src/views/Signup.vue

@@ -40,7 +40,6 @@ const width = computed(() => {
 // action
 async function submit() {
   if (confirmPassword.value === data.password) {
-    console.log("data", data.password);
     mainStore.register(data);
   } else {
     confirmState.value = true;
@@ -186,41 +185,6 @@ async function submit() {
       </v-col>
     </v-row>
   </v-container>
-
-  <!-- <v-container fluid class="d-flex fill-height">
-    <v-row align="center" justify="center">
-      <v-col :cols="width">
-        <v-card class="elevation-12">
-          <v-toolbar dark color="primary">
-            <v-toolbar-title>{{ appName }}</v-toolbar-title>
-            <v-spacer></v-spacer>
-            <v-btn to="/login">LogIn</v-btn>
-          </v-toolbar>
-          <v-card-text>
-            <v-form @keyup.enter="submit">
-              <v-text-field
-                @keyup.enter="submit"
-                v-model="email"
-                prepend-icon="person"
-                name="email"
-                label="Email"
-                type="text"
-              ></v-text-field>
-              <v-text-field
-                @keyup.enter="submit"
-                v-model="password"
-                prepend-icon="key"
-                name="password"
-                label="Password"
-                id="password"
-                type="password"
-              ></v-text-field>
-            </v-form>
-          </v-card-text>
-        </v-card>
-      </v-col>
-    </v-row>
-  </v-container> -->
 </template>
 
 <style lang="scss">