forked from verdnatura/salix-front
Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix-front into 6900-fineTunning
This commit is contained in:
commit
2afe9b445e
|
@ -0,0 +1,33 @@
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
function getCurrentBranchName(p = process.cwd()) {
|
||||||
|
if (!fs.existsSync(p)) return false;
|
||||||
|
|
||||||
|
const gitHeadPath = path.join(p, '.git', 'HEAD');
|
||||||
|
|
||||||
|
if (!fs.existsSync(gitHeadPath))
|
||||||
|
return getCurrentBranchName(path.resolve(p, '..'));
|
||||||
|
|
||||||
|
const headContent = fs.readFileSync(gitHeadPath, 'utf-8');
|
||||||
|
return headContent.trim().split('/')[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
const branchName = getCurrentBranchName();
|
||||||
|
|
||||||
|
if (branchName) {
|
||||||
|
const msgPath = `.git/COMMIT_EDITMSG`;
|
||||||
|
const msg = fs.readFileSync(msgPath, 'utf-8');
|
||||||
|
const reference = branchName.match(/^\d+/);
|
||||||
|
|
||||||
|
const referenceTag = `refs #${reference}`;
|
||||||
|
if (!msg.includes(referenceTag) && reference) {
|
||||||
|
const splitedMsg = msg.split(':');
|
||||||
|
|
||||||
|
if (splitedMsg.length > 1) {
|
||||||
|
const finalMsg = splitedMsg[0] + ': ' + referenceTag + splitedMsg.slice(1).join(':');
|
||||||
|
fs.writeFileSync(msgPath, finalMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
. "$(dirname -- "$0")/_/husky.sh"
|
||||||
|
|
||||||
|
echo "Running husky commit-msg hook"
|
||||||
|
npx --no-install commitlint --edit
|
||||||
|
echo "Adding reference tag to commit message"
|
||||||
|
node .husky/addReferenceTag.js
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
module.exports = { extends: ['@commitlint/config-conventional'] };
|
|
@ -13,7 +13,10 @@
|
||||||
"test:e2e:ci": "cd ../salix && gulp docker && cd ../salix-front && cypress run",
|
"test:e2e:ci": "cd ../salix && gulp docker && cd ../salix-front && cypress run",
|
||||||
"test": "echo \"See package.json => scripts for available tests.\" && exit 0",
|
"test": "echo \"See package.json => scripts for available tests.\" && exit 0",
|
||||||
"test:unit": "vitest",
|
"test:unit": "vitest",
|
||||||
"test:unit:ci": "vitest run"
|
"test:unit:ci": "vitest run",
|
||||||
|
"commitlint": "commitlint --edit",
|
||||||
|
"prepare": "npx husky install",
|
||||||
|
"addReferenceTag": "node .husky/addReferenceTag.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@quasar/cli": "^2.3.0",
|
"@quasar/cli": "^2.3.0",
|
||||||
|
@ -41,6 +44,7 @@
|
||||||
"eslint-config-prettier": "^8.8.0",
|
"eslint-config-prettier": "^8.8.0",
|
||||||
"eslint-plugin-cypress": "^2.13.3",
|
"eslint-plugin-cypress": "^2.13.3",
|
||||||
"eslint-plugin-vue": "^9.14.1",
|
"eslint-plugin-vue": "^9.14.1",
|
||||||
|
"husky": "^8.0.0",
|
||||||
"postcss": "^8.4.23",
|
"postcss": "^8.4.23",
|
||||||
"prettier": "^2.8.8",
|
"prettier": "^2.8.8",
|
||||||
"vitest": "^0.31.1"
|
"vitest": "^0.31.1"
|
||||||
|
|
14609
pnpm-lock.yaml
14609
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -60,7 +60,7 @@ if (props.baseUrl) {
|
||||||
</QScrollArea>
|
</QScrollArea>
|
||||||
</QDrawer>
|
</QDrawer>
|
||||||
<slot name="searchbar" v-if="props.searchDataKey">
|
<slot name="searchbar" v-if="props.searchDataKey">
|
||||||
<VnSearchbar :data-key="props.searchDataKey" v-bind="$attrs['searchbarProps']" />
|
<VnSearchbar :data-key="props.searchDataKey" v-bind="props.searchbarProps" />
|
||||||
</slot>
|
</slot>
|
||||||
<slot v-else name="searchbar" />
|
<slot v-else name="searchbar" />
|
||||||
<RightMenu>
|
<RightMenu>
|
||||||
|
|
|
@ -3,12 +3,14 @@ import { useRole } from './useRole';
|
||||||
import { useAcl } from './useAcl';
|
import { useAcl } from './useAcl';
|
||||||
import { useUserConfig } from './useUserConfig';
|
import { useUserConfig } from './useUserConfig';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
import useNotify from './useNotify';
|
import useNotify from './useNotify';
|
||||||
import { useTokenConfig } from './useTokenConfig';
|
import { useTokenConfig } from './useTokenConfig';
|
||||||
const TOKEN_MULTIMEDIA = 'tokenMultimedia';
|
const TOKEN_MULTIMEDIA = 'tokenMultimedia';
|
||||||
const TOKEN = 'token';
|
const TOKEN = 'token';
|
||||||
|
|
||||||
export function useSession() {
|
export function useSession() {
|
||||||
|
const router = useRouter();
|
||||||
const { notify } = useNotify();
|
const { notify } = useNotify();
|
||||||
let isCheckingToken = false;
|
let isCheckingToken = false;
|
||||||
let intervalId = null;
|
let intervalId = null;
|
||||||
|
@ -102,6 +104,31 @@ export function useSession() {
|
||||||
startInterval();
|
startInterval();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function setLogin(data) {
|
||||||
|
const {
|
||||||
|
data: { multimediaToken },
|
||||||
|
} = await axios.get('VnUsers/ShareToken', {
|
||||||
|
headers: { Authorization: data.token },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!multimediaToken) return;
|
||||||
|
|
||||||
|
await login({
|
||||||
|
...data,
|
||||||
|
created: Date.now(),
|
||||||
|
tokenMultimedia: multimediaToken.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
notify('login.loginSuccess', 'positive');
|
||||||
|
|
||||||
|
const currentRoute = router.currentRoute.value;
|
||||||
|
if (currentRoute.query?.redirect) {
|
||||||
|
router.push(currentRoute.query.redirect);
|
||||||
|
} else {
|
||||||
|
router.push({ name: 'Dashboard' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function isLoggedIn() {
|
function isLoggedIn() {
|
||||||
const localToken = localStorage.getItem(TOKEN);
|
const localToken = localStorage.getItem(TOKEN);
|
||||||
const sessionToken = sessionStorage.getItem(TOKEN);
|
const sessionToken = sessionStorage.getItem(TOKEN);
|
||||||
|
@ -163,6 +190,7 @@ export function useSession() {
|
||||||
setToken,
|
setToken,
|
||||||
destroy,
|
destroy,
|
||||||
login,
|
login,
|
||||||
|
setLogin,
|
||||||
isLoggedIn,
|
isLoggedIn,
|
||||||
checkValidity,
|
checkValidity,
|
||||||
setSession,
|
setSession,
|
||||||
|
|
|
@ -28,35 +28,10 @@ async function onSubmit() {
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const { data } = await axios.post('Accounts/login', params);
|
const { data } = await axios.post('Accounts/login', params);
|
||||||
|
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
const {
|
|
||||||
data: { multimediaToken },
|
|
||||||
} = await axios.get('VnUsers/ShareToken', {
|
|
||||||
headers: { Authorization: data.token },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!multimediaToken) return;
|
data.keepLogin = keepLogin.value;
|
||||||
|
await session.setLogin(data);
|
||||||
const login = {
|
|
||||||
...data,
|
|
||||||
created: Date.now(),
|
|
||||||
tokenMultimedia: multimediaToken.id,
|
|
||||||
keepLogin: keepLogin.value,
|
|
||||||
};
|
|
||||||
await session.login(login);
|
|
||||||
|
|
||||||
quasar.notify({
|
|
||||||
message: t('login.loginSuccess'),
|
|
||||||
type: 'positive',
|
|
||||||
});
|
|
||||||
|
|
||||||
const currentRoute = router.currentRoute.value;
|
|
||||||
if (currentRoute.query && currentRoute.query.redirect) {
|
|
||||||
router.push(currentRoute.query.redirect);
|
|
||||||
} else {
|
|
||||||
router.push({ name: 'Dashboard' });
|
|
||||||
}
|
|
||||||
} catch (res) {
|
} catch (res) {
|
||||||
if (res.response?.data?.error?.code === 'REQUIRES_2FA') {
|
if (res.response?.data?.error?.code === 'REQUIRES_2FA') {
|
||||||
Notify.create({
|
Notify.create({
|
||||||
|
|
|
@ -25,21 +25,10 @@ async function onSubmit() {
|
||||||
try {
|
try {
|
||||||
params.code = code.value;
|
params.code = code.value;
|
||||||
const { data } = await axios.post('VnUsers/validate-auth', params);
|
const { data } = await axios.post('VnUsers/validate-auth', params);
|
||||||
|
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
|
|
||||||
await session.login(data.token, params.keepLogin);
|
data.keepLogin = params.keepLogin;
|
||||||
quasar.notify({
|
await session.setLogin(data);
|
||||||
message: t('login.loginSuccess'),
|
|
||||||
type: 'positive',
|
|
||||||
});
|
|
||||||
|
|
||||||
const currentRoute = router.currentRoute.value;
|
|
||||||
if (currentRoute.query && currentRoute.query.redirect) {
|
|
||||||
router.push(currentRoute.query.redirect);
|
|
||||||
} else {
|
|
||||||
router.push({ name: 'Dashboard' });
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
quasar.notify({
|
quasar.notify({
|
||||||
message: e.response?.data?.error.message,
|
message: e.response?.data?.error.message,
|
||||||
|
|
|
@ -25,18 +25,20 @@ describe('Login', () => {
|
||||||
vi.spyOn(axios, 'post').mockResolvedValueOnce({ data: { token: 'token' } });
|
vi.spyOn(axios, 'post').mockResolvedValueOnce({ data: { token: 'token' } });
|
||||||
vi.spyOn(axios, 'get').mockImplementation((url) => {
|
vi.spyOn(axios, 'get').mockImplementation((url) => {
|
||||||
if (url === 'VnUsers/acls') return Promise.resolve({ data: [] });
|
if (url === 'VnUsers/acls') return Promise.resolve({ data: [] });
|
||||||
return Promise.resolve({data: { roles: [], user: expectedUser , multimediaToken: {id:'multimediaToken' }}});
|
return Promise.resolve({
|
||||||
|
data: {
|
||||||
|
roles: [],
|
||||||
|
user: expectedUser,
|
||||||
|
multimediaToken: { id: 'multimediaToken' },
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
vi.spyOn(vm.quasar, 'notify');
|
|
||||||
|
|
||||||
expect(vm.session.getToken()).toEqual('');
|
expect(vm.session.getToken()).toEqual('');
|
||||||
|
|
||||||
await vm.onSubmit();
|
await vm.onSubmit();
|
||||||
|
|
||||||
expect(vm.session.getToken()).toEqual('token');
|
expect(vm.session.getToken()).toEqual('token');
|
||||||
expect(vm.quasar.notify).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({ type: 'positive' })
|
|
||||||
);
|
|
||||||
await vm.session.destroy();
|
await vm.session.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue