diff --git a/hn-vue/package-lock.json b/hn-vue/package-lock.json index a9f0e76..e2fd2d1 100644 --- a/hn-vue/package-lock.json +++ b/hn-vue/package-lock.json @@ -11021,6 +11021,11 @@ "integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==", "dev": true }, + "vuelidate": { + "version": "0.7.6", + "resolved": "https://registry.npmjs.org/vuelidate/-/vuelidate-0.7.6.tgz", + "integrity": "sha512-suzIuet1jGcyZ4oUSW8J27R2tNrJ9cIfklAh63EbAkFjE380iv97BAiIeolRYoB9bF9usBXCu4BxftWN1Dkn3g==" + }, "watchpack": { "version": "1.7.5", "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-1.7.5.tgz", diff --git a/hn-vue/package.json b/hn-vue/package.json index 715fbee..b5aef67 100644 --- a/hn-vue/package.json +++ b/hn-vue/package.json @@ -10,7 +10,8 @@ "dependencies": { "core-js": "^3.6.5", "vue": "^2.6.11", - "vue-router": "^3.4.9" + "vue-router": "^3.4.9", + "vuelidate": "^0.7.6" }, "devDependencies": { "@vue/cli-plugin-babel": "~4.5.0", diff --git a/hn-vue/src/Layout.vue b/hn-vue/src/Layout.vue index a30285b..269f109 100644 --- a/hn-vue/src/Layout.vue +++ b/hn-vue/src/Layout.vue @@ -2,6 +2,8 @@
diff --git a/hn-vue/src/api.js b/hn-vue/src/api.js index a362dc3..f2ae648 100644 --- a/hn-vue/src/api.js +++ b/hn-vue/src/api.js @@ -15,6 +15,10 @@ class Api { return this._get(`/api/links/${id}/comments`); } + register(data) { + return this._post("/api/accounts", data); + } + _get(path) { return fetch(this.baseUrl + path, { headers: { @@ -28,6 +32,27 @@ class Api { return r.json(); }); } + + _post(path, data) { + return fetch(this.baseUrl + path, { + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + }, + body: JSON.stringify(data), + }).then((r) => { + if (!r.ok) { + return Promise.reject(new Error("Erreur dans la requête")); + } + + if (r.status === 204) { + return r; + } + + return r.json(); + }); + } } export default new Api(process.env.VUE_APP_API_URL); diff --git a/hn-vue/src/components/Textfield.vue b/hn-vue/src/components/Textfield.vue new file mode 100644 index 0000000..ec55663 --- /dev/null +++ b/hn-vue/src/components/Textfield.vue @@ -0,0 +1,37 @@ + + + + + diff --git a/hn-vue/src/main.js b/hn-vue/src/main.js index f4ab2c3..777bcf3 100644 --- a/hn-vue/src/main.js +++ b/hn-vue/src/main.js @@ -1,8 +1,10 @@ import Vue from "vue"; +import Vuelidate from "vuelidate"; import Layout from "./Layout.vue"; import createRouter from "./router"; Vue.config.productionTip = false; +Vue.use(Vuelidate); const router = createRouter(); diff --git a/hn-vue/src/pages/Register.vue b/hn-vue/src/pages/Register.vue new file mode 100644 index 0000000..2de0924 --- /dev/null +++ b/hn-vue/src/pages/Register.vue @@ -0,0 +1,64 @@ + + + diff --git a/hn-vue/src/router.js b/hn-vue/src/router.js index 8e93150..92593d8 100644 --- a/hn-vue/src/router.js +++ b/hn-vue/src/router.js @@ -1,6 +1,7 @@ import Vue from "vue"; import VueRouter from "vue-router"; import Links from "./pages/Links.vue"; +import Register from "./pages/Register.vue"; import LinkDetail from "./pages/LinkDetail.vue"; Vue.use(VueRouter); @@ -15,6 +16,7 @@ export default function createRouter() { component: LinkDetail, props: true, }, + { path: "/register", name: "register", component: Register }, { path: "*", redirect: "/" }, ], }); diff --git a/vue2/src/components/AForm.vue b/vue2/src/components/AForm.vue index 7cb7072..4319beb 100644 --- a/vue2/src/components/AForm.vue +++ b/vue2/src/components/AForm.vue @@ -35,7 +35,7 @@