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.password =
loginServer.db.port = 3306 loginServer.db.port = 3306
frontend.checkEmailPath = http://localhost/account/checkEmail frontend.checkEmailPath = http://localhost/reset
email.disable = true email.disable = true

View File

@ -64,7 +64,6 @@ const loginAPI = {
return apiPost(CONFIG.LOGIN_API_URL + 'createUser', payload) return apiPost(CONFIG.LOGIN_API_URL + 'createUser', payload)
}, },
sendEmail: async (email, email_text = 7, email_verification_code_type = 'resetPassword') => { sendEmail: async (email, email_text = 7, email_verification_code_type = 'resetPassword') => {
//console.log('api email', email)
const payload = { const payload = {
email, email,
email_text, email_text,
@ -72,6 +71,23 @@ const loginAPI = {
} }
return apiPost(CONFIG.LOGIN_API_URL + 'sendEmail', payload) 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 export default loginAPI

View File

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

View File

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