add forgot view + action

ref #30
This commit is contained in:
Philipp Dormann 2021-04-01 19:22:23 +02:00
parent 60dea511b9
commit 30f3a51ef8
1 changed files with 37 additions and 68 deletions

View File

@ -27,23 +27,25 @@
<span class="font-bold">*</span>
</label>
<input
v-model="userdetails.mail"
v-model="user_email"
name="email_address"
id="email_address"
autocomplete="off"
:placeholder="[[$t('e_mail_adress')]]"
type="email"
:class="{ 'border-red-500': (!isEmail(userdetails.mail)), 'border-green-300': (isEmail(userdetails.mail)) }"
:class="{ 'border-red-500': (!isEmail(user_email)), 'border-green-300': (isEmail(user_email)) }"
class="dark:bg-gray-800 mt-1 block w-full shadow-sm sm:text-sm border-2 bg-gray-50 text-gray-500 rounded-md p-2"
/>
<p
v-if="!isEmail(userdetails.mail)"
v-if="!isEmail(user_email)"
class="text-sm"
>{{ $t('please_provide_valid_mail') }}</p>
</div>
<div class="mt-2">
<a
href="./login"
:disabled="(!state.submit_enabled)"
:class="{ 'opacity-50': (!state.submit_enabled), 'cursor-not-allowed': (!state.submit_enabled) }"
@click="resendMail"
class="block w-full text-center py-2 px-3 border-2 border-gray-300 rounded-md p-1 dark:bg-gray-800 font-medium hover:border-gray-400 focus:outline-none focus:border-gray-400 sm:text-sm"
>{{ $t('resend_the_registration_mail') }}</a>
</div>
@ -76,77 +78,44 @@ import isMobilePhone from 'validator/es/lib/isMobilePhone';
import isPostalCode from 'validator/es/lib/isPostalCode';
import { useToast } from "vue-toastification";
const props = defineProps({
token: String
})
if (props.token) {
axios.get(`${config.baseurl}api/organizations/selfservice/${props.token}`)
.then(({ data }) => {
state.org_name = data.name;
state.org_teams = data.teams;
org_team.value = data.teams[0]?.id;
})
.catch((error) => {
console.log(error);
});
}
// const props = defineProps({
// token: String
// })
// if (props.token) {
// axios.get(`${config.baseurl}api/organizations/selfservice/${props.token}`)
// .then(({ data }) => {
// state.org_name = data.name;
// state.org_teams = data.teams;
// org_team.value = data.teams[0]?.id;
// })
// .catch((error) => {
// console.log(error);
// });
// }
let userdetails = ref({ firstname: "", lastname: "", middlename: "", mail: "", phone: "", address: { street: "", address2: "", city: "", zipcode: "" } });
let provide_address = ref(false);
let agb_accepted = ref(false);
let data_confirmed = ref(false);
let org_team = ref("");
let user_email = ref("");
//
const state = reactive({
org_name: "",
org_teams: [],
submit_enabled: computed(() => agb_accepted.value === true && data_confirmed.value === true && (isMobilePhone(userdetails.value.phone) || !userdetails.value.phone.trim()) && isEmail(userdetails.value.mail)
&& userdetails.value.firstname
&& userdetails.value.lastname && (provide_address.value === false || provide_address.value === true && (userdetails.value.address.street.trim() && userdetails.value.address.city.trim() && isPostalCode(userdetails.value.address.zipcode, "DE"))))
submit_enabled: computed(() => isEmail(user_email.value))
})
const toast = useToast();
function login() {
userdetails = userdetails.value;
if (userdetails.phone === "" || isMobilePhone(userdetails.phone)) {
if (isEmail(userdetails.mail)) {
let postdata = {
"email": userdetails.mail,
"firstname": userdetails.firstname,
"middlename": userdetails.middlename,
"lastname": userdetails.lastname,
"address": {}
}
if (isMobilePhone(userdetails.phone)) {
postdata.phone = userdetails.phone;
}
if (provide_address.value === true) {
postdata.address = {
address1: userdetails.address.street,
address2: userdetails.address.address2 || "",
city: userdetails.address.city,
postalcode: userdetails.address.zipcode,
country: "DE",
}
}
if (state.org_name !== '' && state.org_teams.length > 0) {
postdata.team = org_team.value;
}
toast("registration in progress...");
const browserlocale = ((navigator.languages && navigator.languages[0]) || '').substr(0, 2);
let url = `${config.baseurl}api/runners/register/?locale=${browserlocale}`;
if (props.token) {
url = `${config.baseurl}api/runners/register/${props.token}/?locale=${browserlocale}`
}
axios.post(url, postdata)
.then(({ data }) => {
const token = btoa(data.token);
// alert(token);
location.replace(`${config.baseurl_selfservice}profile/${token}`);
})
.catch((error) => {
console.log(error);
});
}
function resendMail() {
if (isEmail(user_email.value)) {
toast("sending password reset mail...");
const browserlocale = ((navigator.languages && navigator.languages[0]) || '').substr(0, 2);
axios.post(`${config.baseurl}api/runners/forgot/?locale=${browserlocale}`, {
"mail": user_email.value
})
.then(({ data }) => {
console.log(data);
toast("sent password reset mail to " + user_email.value + "!");
})
.catch((error) => {
console.log(error);
toast("user does not exist...");
});
}
}
</script>