Add login view

main
DustyP 4 years ago
parent 215ed8f2ad
commit d891a3df9a

@ -60,7 +60,6 @@ func login(w http.ResponseWriter, r *http.Request) {
Expires: expires,
})
http.Redirect(w, r, "/", http.StatusFound) // Redirect with 302
}
func register(w http.ResponseWriter, r *http.Request) {
@ -84,8 +83,6 @@ func register(w http.ResponseWriter, r *http.Request) {
log.Println(err)
return
}
http.Redirect(w, r, "/login", http.StatusFound)
}
func refresh(w http.ResponseWriter, r *http.Request) {

@ -8,7 +8,9 @@
"name": "frontend",
"version": "0.1.0",
"dependencies": {
"axios": "^0.24.0",
"core-js": "^3.6.5",
"vee-validate": "^3.4.14",
"vue": "^2.6.11",
"vue-router": "^3.2.0",
"vuetify": "^2.5.14",
@ -3003,6 +3005,14 @@
"integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==",
"dev": true
},
"node_modules/axios": {
"version": "0.24.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz",
"integrity": "sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==",
"dependencies": {
"follow-redirects": "^1.14.4"
}
},
"node_modules/babel-loader": {
"version": "8.2.3",
"resolved": "https://registry.npmjs.org/babel-loader/-/babel-loader-8.2.3.tgz",
@ -6390,7 +6400,6 @@
"version": "1.14.5",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.5.tgz",
"integrity": "sha512-wtphSXy7d4/OR+MvIFbCVBDzZ5520qV8XfPklSN5QtxuMUJZ+b0Wnst1e1lCDocfzuCkHqj8k0FpZqO+UIaKNA==",
"dev": true,
"funding": [
{
"type": "individual",
@ -13098,6 +13107,14 @@
"node": ">= 0.8"
}
},
"node_modules/vee-validate": {
"version": "3.4.14",
"resolved": "https://registry.npmjs.org/vee-validate/-/vee-validate-3.4.14.tgz",
"integrity": "sha512-Hqqic8G9WcRSIzCxiCPqMZv4qB8JE1lIQqIOLDm2K5BXUiL8d4a2+kqkanv8gQSGDzYpnCQZ7BO/T99Aj05T1Q==",
"peerDependencies": {
"vue": "^2.5.18"
}
},
"node_modules/vendors": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/vendors/-/vendors-1.0.4.tgz",
@ -16808,6 +16825,14 @@
"integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==",
"dev": true
},
"axios": {
"version": "0.24.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.24.0.tgz",
"integrity": "sha512-Q6cWsys88HoPgAaFAVUb0WpPk0O8iTeisR9IMqy9G8AbO4NlpVknrnQS03zzF9PGAWgO3cgletO3VjV/P7VztA==",
"requires": {
"follow-redirects": "^1.14.4"
}
},
"babel-loader": {
"version": "8.2.3",
"resolved": "https://registry.npmjs.org/babel-loader/-/babel-loader-8.2.3.tgz",
@ -19558,8 +19583,7 @@
"follow-redirects": {
"version": "1.14.5",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.5.tgz",
"integrity": "sha512-wtphSXy7d4/OR+MvIFbCVBDzZ5520qV8XfPklSN5QtxuMUJZ+b0Wnst1e1lCDocfzuCkHqj8k0FpZqO+UIaKNA==",
"dev": true
"integrity": "sha512-wtphSXy7d4/OR+MvIFbCVBDzZ5520qV8XfPklSN5QtxuMUJZ+b0Wnst1e1lCDocfzuCkHqj8k0FpZqO+UIaKNA=="
},
"for-in": {
"version": "1.0.2",
@ -24983,6 +25007,12 @@
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=",
"dev": true
},
"vee-validate": {
"version": "3.4.14",
"resolved": "https://registry.npmjs.org/vee-validate/-/vee-validate-3.4.14.tgz",
"integrity": "sha512-Hqqic8G9WcRSIzCxiCPqMZv4qB8JE1lIQqIOLDm2K5BXUiL8d4a2+kqkanv8gQSGDzYpnCQZ7BO/T99Aj05T1Q==",
"requires": {}
},
"vendors": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/vendors/-/vendors-1.0.4.tgz",

@ -8,7 +8,9 @@
"watch": "vue-cli-service build --watch"
},
"dependencies": {
"axios": "^0.24.0",
"core-js": "^3.6.5",
"vee-validate": "^3.4.14",
"vue": "^2.6.11",
"vue-router": "^3.2.0",
"vuetify": "^2.5.14",
@ -19,8 +21,10 @@
"@vue/cli-plugin-router": "~4.5.0",
"@vue/cli-plugin-vuex": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"axios": "^0.18.0",
"sass": "~1.32.0",
"sass-loader": "^10.0.0",
"vue-cli-plugin-axios": "~0.0.4",
"vue-cli-plugin-vuetify": "~2.4.3",
"vue-template-compiler": "^2.6.11",
"vuetify-loader": "^1.7.0"

@ -1,4 +1,5 @@
import Vue from 'vue'
import './plugins/axios'
import App from './App.vue'
import router from './router'
import vuetify from './plugins/vuetify'

@ -0,0 +1,61 @@
"use strict";
import Vue from 'vue';
import axios from "axios";
// Full config: https://github.com/axios/axios#request-config
// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';
// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
let config = {
// baseURL: process.env.baseURL || process.env.apiUrl || ""
// timeout: 60 * 1000, // Timeout
// withCredentials: true, // Check cross-site Access-Control
};
const _axios = axios.create(config);
_axios.interceptors.request.use(
function(config) {
// Do something before request is sent
return config;
},
function(error) {
// Do something with request error
return Promise.reject(error);
}
);
// Add a response interceptor
_axios.interceptors.response.use(
function(response) {
// Do something with response data
return response;
},
function(error) {
// Do something with response error
return Promise.reject(error);
}
);
Plugin.install = function(Vue, options) {
Vue.axios = _axios;
window.axios = _axios;
Object.defineProperties(Vue.prototype, {
axios: {
get() {
return _axios;
}
},
$axios: {
get() {
return _axios;
}
},
});
};
Vue.use(Plugin)
export default Plugin;

@ -1,6 +1,7 @@
import Vue from 'vue'
import VueRouter from 'vue-router'
import Dashboard from '../views/Dashboard.vue'
import Login from '../views/Login.vue'
Vue.use(VueRouter)
@ -17,7 +18,12 @@ const routes = [
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
}
},
{
path: '/login',
name: 'Login',
component: Login,
},
]
const router = new VueRouter({

@ -0,0 +1,122 @@
<template>
<section class="section-container">
<v-row class="signin">
<v-spacer />
<v-col cols="10" sm="8" md="6" lg="4" class="text-center">
<h2 class="grey--text lighten-4">LOGIN</h2>
<validation-observer ref="observer">
<v-form @submit.prevent="submit">
<validation-provider
v-slot="{ errors }"
name="Username"
rules="required"
>
<v-text-field
v-model="username"
:error-messages="errors"
label="Username"
required
outlined
dark
filled
dense
></v-text-field>
</validation-provider>
<validation-provider
v-slot="{ errors }"
name="Password"
rules="required"
>
<v-text-field
v-model="password"
:error-messages="errors"
label="Password"
:append-icon="showPass ? 'mdi-eye' : 'mdi-eye-off'"
@click:append="showPass = !showPass"
required
outlined
dense
dark
filled
:type="showPass ? 'text' : 'password'"
></v-text-field>
</validation-provider>
<div class="text-center">
<v-btn class="signin-btn" type="submit" rounded color="white">
Sign In
</v-btn>
</div>
</v-form>
</validation-observer>
</v-col>
<v-spacer />
</v-row>
</section>
</template>
<script>
import { required } from "vee-validate/dist/rules";
import {
extend,
ValidationProvider,
setInteractionMode,
ValidationObserver,
} from "vee-validate";
setInteractionMode("eager");
extend("required", {
...required,
message: "{_field_} can not be empty",
});
export default {
name: "Login",
components: {
ValidationProvider,
ValidationObserver,
},
data: () => ({
username: "",
password: null,
showPass: false,
response: null,
}),
computed: {
params() {
return {
username: this.username,
password: this.password,
};
},
},
methods: {
async submit() {
const valid = await this.$refs.observer.validate();
if (valid) {
this.login(this.params); // action to login
}
},
async login(payload) {
axios
.post("http://localhost:8000/api/users/login", payload)
.then((response) => {
if (response.status == 200) {
this.$router.push({ name: "Dashboard" })
}
})
.catch((error) => {
if (error.response.status == 401) {
console.log("Bad login info")
}
})
},
clear() {
// you can use this method to clear login form
this.username = "";
this.password = null;
this.$refs.observer.reset();
},
},
};
</script>

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save