mirror of
https://github.com/fleetbase/fleetbase.git
synced 2025-12-19 22:27:22 +00:00
- Fixed controller validation handling - Added microsoft365/graph mail driver - Improved password requirements (including breached password check) - Patched creating duplicate users by email in IAM - Patch env mapper - Vehicle/driver tracking API doesnt fire resource lifecycle events or log requests - only tracking events - Patched `<ModelCoordinatesInput />` component - Security patch on Storefront customers API - Styling updates on Storefront
115 lines
3.6 KiB
JavaScript
115 lines
3.6 KiB
JavaScript
import Service, { inject as service } from '@ember/service';
|
|
import { tracked } from '@glimmer/tracking';
|
|
import { action } from '@ember/object';
|
|
import { later } from '@ember/runloop';
|
|
import { task } from 'ember-concurrency';
|
|
|
|
export default class UserVerificationService extends Service {
|
|
@service fetch;
|
|
@service notifications;
|
|
@service modalsManager;
|
|
@service currentUser;
|
|
@service router;
|
|
@service session;
|
|
@service intl;
|
|
@tracked token;
|
|
@tracked code;
|
|
@tracked ready;
|
|
@tracked waiting = false;
|
|
|
|
@action start(options = {}) {
|
|
this.#wait(options?.timeout ?? 75000);
|
|
}
|
|
|
|
@action didntReceiveCode() {
|
|
this.waiting = true;
|
|
}
|
|
|
|
@action validateInput(event) {
|
|
const value = event instanceof HTMLElement ? event.value : (event?.target?.value ?? '');
|
|
this.ready = value?.length > 5;
|
|
}
|
|
|
|
@action resendBySms() {
|
|
this.modalsManager.show('modals/verify-by-sms', {
|
|
title: 'Verify Account by Phone',
|
|
acceptButtonText: 'Send',
|
|
phone: this.currentUser.phone,
|
|
confirm: async (modal) => {
|
|
modal.startLoading();
|
|
const phone = modal.getOption('phone');
|
|
if (!phone) {
|
|
this.notifications.error('No phone number provided.');
|
|
}
|
|
|
|
try {
|
|
await this.fetch.post('onboard/send-verification-sms', { phone, session: this.hello });
|
|
this.notifications.success('Verification code SMS sent!');
|
|
modal.done();
|
|
} catch (error) {
|
|
this.notifications.serverError(error);
|
|
modal.stopLoading();
|
|
}
|
|
},
|
|
});
|
|
}
|
|
|
|
@action resendEmail() {
|
|
this.modalsManager.show('modals/resend-verification-email', {
|
|
title: 'Resend Verification Code',
|
|
acceptButtonText: 'Send',
|
|
email: this.currentUser.email,
|
|
confirm: async (modal) => {
|
|
modal.startLoading();
|
|
const email = modal.getOption('email');
|
|
if (!email) {
|
|
this.notifications.error('No email number provided.');
|
|
}
|
|
|
|
try {
|
|
await this.fetch.post('onboard/send-verification-email', { email, session: this.hello });
|
|
this.notifications.success('Verification code email sent!');
|
|
modal.done();
|
|
} catch (error) {
|
|
this.notifications.serverError(error);
|
|
modal.stopLoading();
|
|
}
|
|
},
|
|
});
|
|
}
|
|
|
|
@task *verifyCode() {
|
|
try {
|
|
const { status, token } = yield this.fetch.post('auth/verify-email', { token: this.token, code: this.code, email: this.email, authenticate: true });
|
|
if (status === 'ok') {
|
|
this.notifications.success('Email successfully verified!');
|
|
|
|
if (token) {
|
|
this.notifications.info(`Welcome to ${this.intl.t('app.name')}`);
|
|
this.session.manuallyAuthenticate(token);
|
|
|
|
return this.router.transitionTo('console');
|
|
}
|
|
|
|
return this.router.transitionTo('auth.login');
|
|
}
|
|
} catch (error) {
|
|
this.notifications.serverError(error);
|
|
}
|
|
}
|
|
|
|
setToken(token) {
|
|
this.token = token;
|
|
}
|
|
|
|
setCode(code) {
|
|
this.code = code;
|
|
}
|
|
|
|
#wait(timeout = 75000) {
|
|
return later(this, () => {
|
|
this.waiting = true;
|
|
}, timeout);
|
|
}
|
|
}
|