5 Incheckningar d7b00729bf ... f3460d34ee

Upphovsman SHA1 Meddelande Datum
  Ecconia f3460d34ee Adding help functions to Core 7 år sedan
  Ecconia e4f9fba1cc Letting core set user from backend object 7 år sedan
  Ecconia e6ea2c1562 Adding Axios API for web requests 7 år sedan
  Ecconia 74adb76403 Add Login form and Core 7 år sedan
  Ecconia 775c20555f Moving user to Vuex, add app create button 7 år sedan
8 ändrade filer med 173 tillägg och 12 borttagningar
  1. 1 0
      package.json
  2. 19 4
      src/App.vue
  3. 4 0
      src/main.js
  4. 4 0
      src/router.js
  5. 50 0
      src/scripts/core.js
  6. 11 8
      src/store.js
  7. 10 0
      src/views/Applications.vue
  8. 74 0
      src/views/Login.vue

+ 1 - 0
package.json

@@ -8,6 +8,7 @@
     "lint": "vue-cli-service lint"
     "lint": "vue-cli-service lint"
   },
   },
   "dependencies": {
   "dependencies": {
+    "axios": "^0.18.0",
     "vue": "^2.5.17",
     "vue": "^2.5.17",
     "vue-router": "^3.0.1",
     "vue-router": "^3.0.1",
     "vuex": "^3.0.1"
     "vuex": "^3.0.1"

+ 19 - 4
src/App.vue

@@ -13,7 +13,7 @@
 				<div v-if="user">
 				<div v-if="user">
 					<span>Username: {{ user.username }}</span>
 					<span>Username: {{ user.username }}</span>
 				</div>
 				</div>
-				<span v-else>Login</span>
+				<router-link class="rl" to="/login" v-else>Login</router-link>
 			</div>
 			</div>
 		</header>
 		</header>
 
 
@@ -31,15 +31,20 @@
 	export default {
 	export default {
 		data () {
 		data () {
 			return {
 			return {
-				user: null,
 				menu_entries: {
 				menu_entries: {
 					'Startpage': '/',
 					'Startpage': '/',
 					'Applications': '/applications',
 					'Applications': '/applications',
 					'Development Blog': '/devblog',
 					'Development Blog': '/devblog',
-				}
+				},
 			}
 			}
 		},
 		},
 
 
+		computed: {
+			user() {
+				return this.$store.state.user
+			},
+		},
+
 		components: {
 		components: {
 			MenuContainer
 			MenuContainer
 		},
 		},
@@ -73,7 +78,6 @@
 
 
 	header .logo {
 	header .logo {
 		display: inline-block;
 		display: inline-block;
-		padding: 0.2em 1em;
 	}
 	}
 
 
 	header .menu-container {
 	header .menu-container {
@@ -89,4 +93,15 @@
 		margin-left: 8px;
 		margin-left: 8px;
 		margin-right: 8px;
 		margin-right: 8px;
 	}
 	}
+
+	.rl {
+		text-decoration: none;
+		color: #aaa;
+		padding: 0.2em 1em;
+	}
+
+	.rl:hover {
+		color: #ddd;
+		background-color: #333;
+	}
 </style>
 </style>

+ 4 - 0
src/main.js

@@ -2,9 +2,13 @@ import Vue from 'vue'
 import App from './App.vue'
 import App from './App.vue'
 import router from './router'
 import router from './router'
 import store from './store'
 import store from './store'
+import Core from './scripts/core.js'
 
 
 Vue.config.productionTip = true
 Vue.config.productionTip = true
 
 
+const core = new Core(store)
+Vue.prototype.core = core
+
 new Vue({
 new Vue({
   router,
   router,
   store,
   store,

+ 4 - 0
src/router.js

@@ -15,6 +15,10 @@ export default new Router({
 			path: '/',
 			path: '/',
 			component: load('Mainpage')
 			component: load('Mainpage')
 		},
 		},
+		{
+			path: '/login',
+			component: load('Login'),
+		},
 		{
 		{
 			path: '/impressum',
 			path: '/impressum',
 			component: load('Impressum')
 			component: load('Impressum')

+ 50 - 0
src/scripts/core.js

@@ -0,0 +1,50 @@
+import axios from "axios";
+
+export default class {
+	constructor(vuex) {
+		this.vuex = vuex
+	}
+
+	commit(method, data)
+	{
+		this.vuex.commit(method, data)
+	}
+
+	post(path, data)
+	{
+		return axios
+				.post('https://live.ecconia.de' + path, data)
+				.catch((error) => {
+					console.error('Error: ', error)
+				})
+	}
+
+	get(path)
+	{
+		return axios
+				.get('https://live.ecconia.de' + path)
+				.catch((error) => {
+					console.error('Error: ', error)
+				})
+	}
+
+	lol(username, password) {
+		//TODO: return promise somehow
+		//alert('Login attempt as user \'' + username + '\' with password \'' + password + '\'')
+
+		/*
+		this.get('/soos')
+			.then(function (response) {
+				console.log('Response: ', response.data)
+			})
+		*/
+
+		this.post('/login', {
+			username: username,
+			password: password,
+		}).then((response) => {
+			console.log('Response: ', response.data)
+			this.commit('setUser', response.data)
+		})
+	}
+}

+ 11 - 8
src/store.js

@@ -4,13 +4,16 @@ import Vuex from 'vuex'
 Vue.use(Vuex)
 Vue.use(Vuex)
 
 
 export default new Vuex.Store({
 export default new Vuex.Store({
-  state: {
+	strict: process.env.NODE_ENV !== 'production',
+	state: {
+		user: null,
+	},
+	mutations: {
+		setUser(state, user) {
+			state.user = user
+		}
+	},
+	actions: {
 
 
-  },
-  mutations: {
-
-  },
-  actions: {
-
-  }
+	}
 })
 })

+ 10 - 0
src/views/Applications.vue

@@ -3,6 +3,11 @@
 		<h1>Applications:</h1>
 		<h1>Applications:</h1>
 		<p>This area is basically the first big GOAL of the final product. Creating and Judging apps. The path to get here is quite long though, many other issues have to be solved first.</p>
 		<p>This area is basically the first big GOAL of the final product. Creating and Judging apps. The path to get here is quite long though, many other issues have to be solved first.</p>
 
 
+		<div v-if="getUser && getUser.rank === undefined">
+			<router-link to="/myapp" v-if="getUser.appstate === 0">Create application.</router-link>
+			<router-link to="/myapp" v-else-if="getUser.appstate === 1">Edit application.</router-link>
+		</div>
+
 		<div class="app-container">
 		<div class="app-container">
 			<router-link class="app-entry" :to="{ name: 'application', params: { id: app.id }}" v-for="app in apps" :key="app.id">
 			<router-link class="app-entry" :to="{ name: 'application', params: { id: app.id }}" v-for="app in apps" :key="app.id">
 				<p>Name: {{ app.playername }} </p>
 				<p>Name: {{ app.playername }} </p>
@@ -52,6 +57,11 @@
 		},
 		},
 		created () {
 		created () {
 		},
 		},
+		computed: {
+			getUser() {
+				return this.$store.state.user
+			},
+		},
 		methods: {
 		methods: {
 			readableTime(timestamp) {
 			readableTime(timestamp) {
 				let date = new Date(timestamp * 1000)
 				let date = new Date(timestamp * 1000)

+ 74 - 0
src/views/Login.vue

@@ -0,0 +1,74 @@
+<template>
+	<div>
+		<h1>Login</h1>
+
+		<div v-if="!user">
+			<span>Username: </span>
+			<input @keyup.enter="usernameDone()" v-model="username" placeholder="username" ref="username"><br>
+
+			<span>Password: </span>
+			<input @keyup.enter="passwordDone()" v-model="password" placeholder="password" type="password" ref="password"><br>
+
+			<button @click="buttonDone()">Login</button><span class="error">{{ error }}</span><br>
+		</div>
+		<span v-else>You are logged in.</span>
+	</div>
+</template>
+
+<script>
+	export default {
+		data() {
+			return {
+				error: '',
+				username: '',
+				password: '',
+			}
+		},
+		mounted() {
+			this.$refs.username.focus()
+		},
+		computed: {
+			user() {
+				return this.$store.state.user
+			},
+		},
+		methods: {
+			usernameDone() {
+				if(this.username !== '' || this.validateData()) {
+					this.$refs.password.focus()
+				}
+			},
+			passwordDone() {
+				if(this.validateData()) {
+					this.attemptLogin()
+				}
+			},
+			buttonDone() {
+				if(this.validateData()) {
+					this.attemptLogin()
+				}
+			},
+			validateData() {
+				if(this.username === '') {
+					this.error = 'Please input a username'
+					this.$refs.username.focus()
+				} else if(this.password === '') {
+					this.error = 'Please input a password'
+					this.$refs.password.focus()
+				} else {
+					return true
+				}
+				return false
+			},
+			attemptLogin() {
+				this.core.lol(this.username, this.password)
+			},
+		}
+	}
+</script>
+
+<style scoped>
+	.error {
+		color: #d00;
+	}
+</style>