Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build/webpack.dev.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const devWebpackConfig = merge(baseWebpackConfig, {
quiet: true, // necessary for FriendlyErrorsPlugin
watchOptions: {
poll: config.dev.poll,
}
},
disableHostCheck: true
},
plugins: [
new webpack.DefinePlugin({
Expand Down
2 changes: 1 addition & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {

// Various Dev Server settings
host: '0.0.0.0', // can be overwritten by process.env.HOST
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
port: 82, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"dependencies": {
"vue": "^2.5.2",
"vue-router": "^3.0.1",
"vuex": "^3.0.1"
"vuex": "^3.0.1",
"axios": "^0.17.1"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
Expand Down
2 changes: 2 additions & 0 deletions src/components/AddsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<div v-for="item in list" :key="item.id">
<router-link :to="{name: 'AddForm', params: {id: item.id}}">{{ item.name }}</router-link>
</div>
<br /><br /><br />
<router-link :to="{name: 'Login'}">Login</router-link>
</div>
</template>

Expand Down
30 changes: 25 additions & 5 deletions src/components/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<h1>Login page</h1>
<div>{{ login }}</div>
<div>
<div style="color: red" v-if="hasError">
Something went wrong
</div>
<div>
<input type="text" name="login" v-model="login">
</div>
Expand All @@ -17,22 +20,39 @@
</template>

<script>
import { mapState } from 'vuex'

export default {
name: 'Login',
data () {
return {
login: 'test',
pass: 'test'
pass: 'test',
hasError: false,
limit: 10,
page: 1
}
},
computed: {
...mapState(['isAuth'])
},
methods: {
loginAction: function () {
console.log('Login: ' + this.login)
console.log('Pass: ' + this.pass)
this.$store.dispatch('login', {login: this.login, pass: this.pass})
.then(() => {
this.hasError = false
this.$router.push({name: 'AddsList'})
}).catch(err => {
if (err.response.status !== 200) {
this.hasError = true
}
})
}
},
beforeCreate: function () {
console.log('beforeCreate')
created () {
if (this.isAuth) {
this.$router.push({name: 'Page404'})
}
}
}
</script>
3 changes: 3 additions & 0 deletions src/store/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
login: 'http://api.stud.hz/?action=login'
}
26 changes: 24 additions & 2 deletions src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

import API from './api'

Vue.use(Vuex)

Expand All @@ -16,17 +19,29 @@ const Store = new Vuex.Store({
},
{
id: '3',
name: 'test3'
name: 'test3' {
path: '/',
name: 'AddsList',
component: AddsList
},
}
],
addItem: {}
addItem: {},
user: {},
isAuth: false
},
mutations: {
updateAddsList (state, data) {
state.addsList = data
},
updateAddItem (state, data) {
state.addItem = data
},
updateAuth (state, data) {
state.isAuth = data
},
updateUser (state, data) {
state.user = data
}
},
actions: {
Expand All @@ -50,6 +65,13 @@ const Store = new Vuex.Store({
})

context.commit('updateAddsList', context.state.addsList)
},
login (context, params) {
return axios.post(API.login, params, {withCredentials: true})
.then(responce => {
context.commit('updateUser', responce.data)
context.commit('updateAuth', true)
})
}
}
})
Expand Down