Skip to content

Commit

Permalink
Add confirmation of registration (#85)
Browse files Browse the repository at this point in the history
* Add User to vuex

* Add confirmation of registration
  • Loading branch information
blackst0ne authored Mar 6, 2018
1 parent 634aa99 commit 19bdf10
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 99 deletions.
Empty file.
81 changes: 81 additions & 0 deletions src/components/users/Confirmation.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<template>
<div class="confirmation">
<b-row class="breadcrumbs" no-gutters>
<b-col cols="12">
<b-breadcrumb :items="breadcrumbs" />
</b-col>
</b-row>

<b-row>
<b-col cols="8" offset="2" align="center">
<h5 :class="status">{{ message }}</h5>

<router-link :to="{ name: 'UserAuthorization' }" key="authorization" v-if="status === 'success'">
Войти
<i class="fa fa-long-arrow-right align-middle" aria-hidden="true" />
</router-link>
</b-col>
</b-row>
</div>
</template>

<script>
export default {
data() {
return {
breadcrumbs: [
{
text: 'Главная',
href: this.$router.resolve({ name: 'Mainpage' }).href
}, {
text: 'Подтверждение емэйла',
active: true
}
],
message: '',
status: 'failure'
}
},
created() {
this.confirmEmail(this.$router.currentRoute.params.token)
},
methods: {
confirmEmail: function(token) {
this.$http.post(this.$root.$options.settings.api.endpointEmailConfirmation(token))
.then(response => {
this.status = 'success'
this.message = response.data.data
})
.catch(error => {
this.status = 'failure'
this.message = `Ошибка подтверждения: ${error.response.data.error.message.toLowerCase()}`
})
}
}
}
</script>

<style lang="scss" scoped>
@import '../../assets/scss/global';
.breadcrumbs {
.breadcrumb {
background-color: transparent;
margin-top: 4%;
padding-left: 0;
padding-top: 0;
.active {
color: $color-gray-dark;
}
}
}
.failure {
color: $color-red;
}
.success {
color: $color-green;
}
</style>
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Vue.use(BootstrapVue)
const apiSettings = new ApiSettings()

// Set axios authorization headers.
const apiToken = store.getters.apiAuthorizationToken
const apiToken = store.getters.user.token
const apiType = apiSettings.authorizationType

if (apiToken) axios.defaults.headers.common['Authorization'] = `${apiType} ${apiToken}`
Expand Down
12 changes: 12 additions & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Analytics from '@/components/Analytics'
import Event from '@/components/Event'
import Events from '@/components/Events'
import StaticPage from '@/components/StaticPage'
import UserAuthorization from '@/components/users/Authorization'
import UserEmailConfirmation from '@/components/users/Confirmation'
import UserRegistration from '@/components/users/Registration'

Vue.use(Router)
Expand All @@ -21,6 +23,16 @@ export default new Router({
name: 'UserRegistration',
component: UserRegistration
},
{
path: '/register/confirm/:token',
name: 'UserEmailConfirmation',
component: UserEmailConfirmation
},
{
path: '/sign_in',
name: 'UserAuthorization',
component: UserAuthorization
},
{
path: '/analytics',
name: 'Analytics',
Expand Down
4 changes: 4 additions & 0 deletions src/settings/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class Config {
this.endpointUserRegistration = `${this.baseURL}/${this.version}/user/register`
}

endpointEmailConfirmation(token) {
return `${this.baseURL}/${this.version}/user/emailConfirm/${token}`
}

endpointEventBuildings(id) {
return `${this.baseURL}/${this.version}/msk64/damagedBuildings/${id}`
}
Expand Down
100 changes: 100 additions & 0 deletions src/store/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
export default {
state: {
api: {
authorizationToken: ''
},
counters: {
totalEvents: 0
},
currentTileProvider: '',
msk64Config: {
configVersion: ''
},
pgaConfig: {
configVersion: ''
},
plateBoundaries: [],
srssCoreConfig: {
dbVersion: ''
}
},
getters: {
apiAuthorizationToken: state => { return state.api.authorizationToken },
currentTileProvider: state => { return state.currentTileProvider },
chartDataset: () => {
return {
datasets: [{
label: '',
data: [],
fill: true,
lineTension: 0.1,
backgroundColor: 'rgba(51,122,183,0.4)',
borderColor: 'rgba(51,122,183,1)',
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
pointBorderColor: 'rgba(51,122,183,1)',
pointBackgroundColor: 'rgba(51,122,183,1)',
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: 'rgba(51,122,183,1)',
pointHoverBorderColor: 'rgba(51,122,183,1)',
pointHoverBorderWidth: 2,
pointRadius: 1,
pointHitRadius: 10
}],
labels: []
}
},
msk64ConfigVersion: state => { return state.msk64Config.configVersion },
pgaConfigVersion: state => { return state.pgaConfig.configVersion },
plateBoundaries: state => { return state.plateBoundaries },
srssDBVersion: state => { return state.srssCoreConfig.dbVersion },
totalEventsCount: state => { return state.counters.totalEvents }
},
mutations: {
setCurrentTileProvider(state, { key, value }) {
state[key] = value
},
setPlateBoundaries(state, { key, value }) {
state[key] = value
},
setCounter(state, { key, value }) {
state.counters[key] = value
},
setMsk64Config(state, { key, value }) {
state.msk64Config[key] = value
},
setPgaConfig(state, { key, value }) {
state.pgaConfig[key] = value
},
setSrssDBVersion(state, { key, value }) {
state.srssCoreConfig[key] = value
}
},
actions: {
setCurrentTileProvider({ commit, state }, provider) {
if (provider !== state.currentTileProvider) {
commit('setCurrentTileProvider', { key: 'currentTileProvider', value: provider })
}
},
setPlateBoundaries({ commit, state }, value) {
if (value !== state.plateBoundaries) {
commit('setPlateBoundaries', { key: 'plateBoundaries', value: value })
}
},
setTotalEventsCount({ commit }, value) {
commit('setCounter', { key: 'totalEvents', value: value })
},
setMsk64ConfigVersion({ commit }, value) {
commit('setMsk64Config', { key: 'configVersion', value: value })
},
setPgaConfigVersion({ commit }, value) {
commit('setPgaConfig', { key: 'configVersion', value: value })
},
setSrssDBVersion({ commit }, value) {
commit('setSrssDBVersion', { key: 'dbVersion', value: value })
}
}
}
109 changes: 11 additions & 98 deletions src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,111 +1,24 @@
import Vue from 'vue'
import Vuex from 'vuex'

import app from './app'
import user from './user'

import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

export default new Vuex.Store({
state: {
api: {
authorizationToken: ''
},
counters: {
totalEvents: 0
},
currentTileProvider: '',
msk64Config: {
configVersion: ''
},
pgaConfig: {
configVersion: ''
},
plateBoundaries: [],
srssCoreConfig: {
dbVersion: ''
}
},
getters: {
apiAuthorizationToken: state => { return state.api.authorizationToken },
currentTileProvider: state => { return state.currentTileProvider },
chartDataset: () => {
return {
datasets: [{
label: '',
data: [],
fill: true,
lineTension: 0.1,
backgroundColor: 'rgba(51,122,183,0.4)',
borderColor: 'rgba(51,122,183,1)',
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
pointBorderColor: 'rgba(51,122,183,1)',
pointBackgroundColor: 'rgba(51,122,183,1)',
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: 'rgba(51,122,183,1)',
pointHoverBorderColor: 'rgba(51,122,183,1)',
pointHoverBorderWidth: 2,
pointRadius: 1,
pointHitRadius: 10
}],
labels: []
}
},
msk64ConfigVersion: state => { return state.msk64Config.configVersion },
pgaConfigVersion: state => { return state.pgaConfig.configVersion },
plateBoundaries: state => { return state.plateBoundaries },
srssDBVersion: state => { return state.srssCoreConfig.dbVersion },
totalEventsCount: state => { return state.counters.totalEvents }
},
mutations: {
set(state, { key, value }) {
state[key] = value
},
setCounter(state, { key, value }) {
state.counters[key] = value
},
setMsk64Config(state, { key, value }) {
state.msk64Config[key] = value
},
setPgaConfig(state, { key, value }) {
state.pgaConfig[key] = value
},
setSrssDBVersion(state, { key, value }) {
state.srssCoreConfig[key] = value
}
},
actions: {
setCurrentTileProvider({ commit, state }, provider) {
if (provider !== state.currentTileProvider) {
commit('set', { key: 'currentTileProvider', value: provider })
}
},
setPlateBoundaries({ commit, state }, value) {
if (value !== state.plateBoundaries) {
commit('set', { key: 'plateBoundaries', value: value })
}
},
setTotalEventsCount({ commit }, value) {
commit('setCounter', { key: 'totalEvents', value: value })
},
setMsk64ConfigVersion({ commit }, value) {
commit('setMsk64Config', { key: 'configVersion', value: value })
},
setPgaConfigVersion({ commit }, value) {
commit('setPgaConfig', { key: 'configVersion', value: value })
},
setSrssDBVersion({ commit }, value) {
commit('setSrssDBVersion', { key: 'dbVersion', value: value })
}
modules: {
app: app,
user: user
},
plugins: [createPersistedState({
filter: (mutation) => {
// Store in localStorage only currentTileProvider or plateBoundaries.
switch (mutation.payload.key) {
case 'currentTileProvider':
case 'plateBoundaries': return true
switch (mutation.type) {
case 'setCurrentTileProvider':
case 'setPlateBoundaries':
case 'setUser': return true
default: return false
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/store/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export default {
state: {
authorized: false,
token: null,
refreshToken: null
},
getters: {
user: state => {
return {
authorized: state.authorized,
token: state.token,
refreshToken: state.refreshToken
}
}
},
mutations: {
setUser(state, { key, value }) {
state[key] = value
}
},
actions: {
setUserAuthorized({ commit, state }, value) {
commit('setUser', { key: 'authorized', value: value })
},
setUserTokens({ commit, state }, value) {
commit('setUser', { key: 'token', value: value.token })
commit('setUser', { key: 'refreshToken', value: value.refreshToken })
commit('setUser', { key: 'authorized', value: true })
}
}
}

0 comments on commit 19bdf10

Please sign in to comment.