check API to reset password

This commit is contained in:
Moriz Wahl 2021-04-20 20:38:40 +02:00
parent e45f79f927
commit 1023e8932a
4 changed files with 83 additions and 56 deletions

View File

@ -22,7 +22,7 @@ loginServer.db.user = root
loginServer.db.password =
loginServer.db.port = 3306
frontend.checkEmailPath = http://localhost/account/checkEmail
frontend.checkEmailPath = http://localhost/reset
email.disable = true

View File

@ -64,7 +64,6 @@ const loginAPI = {
return apiPost(CONFIG.LOGIN_API_URL + 'createUser', payload)
},
sendEmail: async (email, email_text = 7, email_verification_code_type = 'resetPassword') => {
//console.log('api email', email)
const payload = {
email,
email_text,
@ -72,6 +71,23 @@ const loginAPI = {
}
return apiPost(CONFIG.LOGIN_API_URL + 'sendEmail', payload)
},
loginViaEmailVerificationCode: async (optin) => {
return apiGet(
CONFIG.LOGIN_API_URL
+ 'loginViaEmailVerificationCode?emailVerificationCode='
+ optin
)
},
changePassword: async (session_id, email, password) => {
const payload = {
session_id,
email,
'update': {
'User.password': password,
},
}
return apiPost(CONFIG.LOGIN_API_URL + 'updateUserInfos', payload)
}
}
export default loginAPI

View File

@ -59,7 +59,7 @@ const routes = [
component: () => import('../views/Pages/ForgotPassword.vue'),
},
{
path: '/reset',
path: '/reset/:optin',
component: () => import('../views/Pages/ResetPassword.vue'),
},
{ path: '*', component: NotFound },

View File

@ -1,5 +1,5 @@
<template>
<div class="resetpwd-form">
<div class="resetpwd-form" v-if="authenticated">
<!-- Header -->
<div class="header p-4">
<b-container class="container">
@ -91,57 +91,68 @@
</div>
</template>
<script>
export default {
name: 'reset',
data() {
return {
rules: [
{ message: this.$t('site.signup.lowercase'), regex: /[a-z]+/ },
{ message: this.$t('site.signup.uppercase'), regex: /[A-Z]+/ },
{ message: this.$t('site.signup.minimum'), regex: /.{8,}/ },
{ message: this.$t('site.signup.one_number'), regex: /[0-9]+/ },
],
password: '',
checkPassword: '',
passwordVisible: false,
submitted: false,
}
},
methods: {
togglePasswordVisibility() {
this.passwordVisible = !this.passwordVisible
},
onSubmit() {
this.$store.dispatch('createUser', {
password: this.model.password,
})
this.model.password = ''
this.$router.push('/thx')
},
},
computed: {
samePasswords() {
return this.password === this.checkPassword
},
passwordsFilled() {
return this.password !== '' && this.checkPassword !== ''
},
passwordValidation() {
let errors = []
for (let condition of this.rules) {
if (!condition.regex.test(this.password)) {
errors.push(condition.message)
}
}
if (errors.length === 0) {
return { valid: true, errors }
}
return { valid: false, errors }
},
},
created() {
//console.log('resetpage', this.$route)
},
}
import loginAPI from '../../apis/loginAPI'
export default {
name: 'reset',
data() {
return {
rules: [
{ message: this.$t('site.signup.lowercase'), regex: /[a-z]+/ },
{ message: this.$t('site.signup.uppercase'), regex: /[A-Z]+/ },
{ message: this.$t('site.signup.minimum'), regex: /.{8,}/ },
{ message: this.$t('site.signup.one_number'), regex: /[0-9]+/ },
],
password: '',
checkPassword: '',
passwordVisible: false,
submitted: false,
authenticated: false,
session_id: null,
}
},
methods: {
togglePasswordVisibility() {
this.passwordVisible = !this.passwordVisible
},
onSubmit() {
this.$store.dispatch('createUser', {
password: this.model.password,
})
this.model.password = ''
this.$router.push('/thx')
},
},
computed: {
samePasswords() {
return this.password === this.checkPassword
},
passwordsFilled() {
return this.password !== '' && this.checkPassword !== ''
},
passwordValidation() {
let errors = []
for (let condition of this.rules) {
if (!condition.regex.test(this.password)) {
errors.push(condition.message)
}
}
if (errors.length === 0) {
return { valid: true, errors }
}
return { valid: false, errors }
},
},
async created() {
const optin = this.$route.params.optin
const result = await loginAPI.loginViaEmailVerificationCode(optin)
console.log('result', result)
if (result.success) {
this.authenticated = true
this.session_id = result.result.data.session_id
} else {
alert(result.result.message)
}
},
}
</script>
<style></style>