1
0

Move everything to models and services (#17)

This commit is contained in:
konrad
2019-03-02 10:25:10 +00:00
committed by Gitea
parent 8559d8bb97
commit 9b0c842ae1
50 changed files with 2165 additions and 1206 deletions

View File

@ -33,58 +33,59 @@
</template>
<script>
import auth from '../../auth'
import router from '../../router'
import {HTTP} from '../../http-common'
import auth from '../../auth'
import router from '../../router'
import {HTTP} from '../../http-common'
import message from '../../message'
export default {
data() {
return {
credentials: {
username: '',
password: ''
},
error: '',
confirmedEmailSuccess: false,
loading: false
}
},
beforeMount() {
// Try to verify the email
export default {
data() {
return {
credentials: {
username: '',
password: ''
},
error: '',
confirmedEmailSuccess: false,
loading: false
}
},
beforeMount() {
// Try to verify the email
// FIXME: Why is this here? Can we find a better place for this?
let emailVerifyToken = localStorage.getItem('emailConfirmToken')
if (emailVerifyToken) {
const cancel = message.setLoading(this)
HTTP.post(`user/confirm`, {token: emailVerifyToken})
.then(() => {
localStorage.removeItem('emailConfirmToken')
this.confirmedEmailSuccess = true
localStorage.removeItem('emailConfirmToken')
this.confirmedEmailSuccess = true
cancel()
})
.catch(e => {
cancel()
this.error = e.response.data.message
})
})
.catch(e => {
cancel()
this.error = e.response.data.message
})
}
// Check if the user is already logged in, if so, redirect him to the homepage
if (auth.user.authenticated) {
router.push({name: 'home'})
}
},
methods: {
submit() {
this.loading = true
this.error = ''
let credentials = {
username: this.credentials.username,
password: this.credentials.password
}
// Check if the user is already logged in, if so, redirect him to the homepage
if (auth.user.authenticated) {
router.push({name: 'home'})
}
},
methods: {
submit() {
this.loading = true
this.error = ''
let credentials = {
username: this.credentials.username,
password: this.credentials.password
}
auth.login(this, credentials, 'home')
}
}
}
auth.login(this, credentials, 'home')
}
}
}
</script>
<style scoped>

View File

@ -16,10 +16,10 @@
<div class="field is-grouped">
<div class="control">
<button type="submit" class="button is-primary" v-bind:class="{ 'is-loading': loading}">Reset your password</button>
<button type="submit" class="button is-primary" :class="{ 'is-loading': this.passwordResetService.loading}">Reset your password</button>
</div>
</div>
<div class="notification is-info" v-if="loading">
<div class="notification is-info" v-if="this.passwordResetService.loading">
Loading...
</div>
<div class="notification is-danger" v-if="error">
@ -37,56 +37,45 @@
</template>
<script>
import {HTTP} from '../../http-common'
import message from '../../message'
import PasswordResetModel from '../../models/passwordReset'
import PasswordResetService from '../../services/passwordReset'
export default {
data() {
return {
credentials: {
password: '',
password2: '',
},
error: '',
successMessage: '',
loading: false
}
},
methods: {
submit() {
const cancel = message.setLoading(this)
this.error = ''
export default {
data() {
return {
passwordResetService: PasswordResetService,
credentials: {
password: '',
password2: '',
},
error: '',
successMessage: ''
}
},
created() {
this.passwordResetService = new PasswordResetService()
},
methods: {
submit() {
this.error = ''
if (this.credentials.password2 !== this.credentials.password) {
cancel()
this.error = 'Passwords don\'t match'
return
}
let resetPasswordPayload = {
token: localStorage.getItem('passwordResetToken'),
new_password: this.credentials.password
if (this.credentials.password2 !== this.credentials.password) {
this.error = 'Passwords don\'t match'
return
}
HTTP.post(`user/password/reset`, resetPasswordPayload)
.then(response => {
this.handleSuccess(response)
localStorage.removeItem('passwordResetToken')
cancel()
})
.catch(e => {
this.error = e.response.data.message
cancel()
})
},
handleError(e) {
this.error = e.response.data.message
},
handleSuccess(e) {
this.successMessage = e.data.message
}
}
}
let passwordReset = new PasswordResetModel({new_password: this.credentials.password})
this.passwordResetService.resetPassword(passwordReset)
.then(response => {
this.successMessage = response.data.message
localStorage.removeItem('passwordResetToken')
})
.catch(e => {
this.error = e.response.data.message
})
}
}
}
</script>
<style scoped>

View File

@ -42,50 +42,50 @@
</template>
<script>
import auth from '../../auth'
import router from '../../router'
import auth from '../../auth'
import router from '../../router'
export default {
data() {
return {
credentials: {
username: '',
export default {
data() {
return {
credentials: {
username: '',
email: '',
password: '',
password2: '',
},
error: '',
loading: false
}
},
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
if (auth.user.authenticated) {
router.push({name: 'home'})
}
},
methods: {
submit() {
this.loading = true
password: '',
password2: '',
},
error: '',
loading: false
}
},
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
if (auth.user.authenticated) {
router.push({name: 'home'})
}
},
methods: {
submit() {
this.loading = true
this.error = ''
this.error = ''
if (this.credentials.password2 !== this.credentials.password) {
this.loading = false
this.error = 'Passwords don\'t match'
this.loading = false
this.error = 'Passwords don\'t match'
return
}
let credentials = {
username: this.credentials.username,
email: this.credentials.email,
password: this.credentials.password
}
let credentials = {
username: this.credentials.username,
email: this.credentials.email,
password: this.credentials.password
}
auth.register(this, credentials, 'home')
}
}
}
auth.register(this, credentials, 'home')
}
}
}
</script>
<style scoped>

View File

@ -5,13 +5,13 @@
<form id="loginform" @submit.prevent="submit" v-if="!isSuccess">
<div class="field">
<div class="control">
<input v-focus type="text" class="input" name="email" placeholder="Email-Adress" v-model="email" required>
<input v-focus type="text" class="input" name="email" placeholder="Email-Adress" v-model="passwordReset.email" required>
</div>
</div>
<div class="field is-grouped">
<div class="control">
<button type="submit" class="button is-primary" v-bind:class="{ 'is-loading': loading}">Send me a password reset link</button>
<button type="submit" class="button is-primary" v-bind:class="{ 'is-loading': passwordResetService.loading}">Send me a password reset link</button>
<router-link :to="{ name: 'login' }" class="button">Login</router-link>
</div>
</div>
@ -30,41 +30,35 @@
</template>
<script>
import {HTTP} from '../../http-common'
import message from '../../message'
import PasswordResetModel from '../../models/passwordReset'
import PasswordResetService from '../../services/passwordReset'
export default {
data() {
return {
email: '',
error: '',
isSuccess: false,
loading: false
}
},
methods: {
submit() {
const cancel = message.setLoading(this)
this.error = ''
let credentials = {
email: this.email,
}
HTTP.post(`user/password/token`, credentials)
.then(() => {
cancel()
export default {
data() {
return {
passwordResetService: PasswordResetService,
passwordReset: PasswordResetModel,
error: '',
isSuccess: false
}
},
created() {
this.passwordResetService = new PasswordResetService()
this.passwordReset = new PasswordResetModel()
},
methods: {
submit() {
this.error = ''
this.passwordResetService.requestResetPassword(this.passwordReset)
.then(() => {
this.isSuccess = true
})
.catch(e => {
cancel()
this.handleError(e)
})
},
handleError(e) {
this.error = e.response.data.message
},
}
}
})
.catch(e => {
this.error = e.response.data.message
})
},
}
}
</script>
<style scoped>