other components... (2)

This commit is contained in:
Paolo Arena
2021-09-16 21:08:02 +02:00
parent fcc4f61f07
commit f351673917
276 changed files with 17183 additions and 3371 deletions

13
src/validation/alfanum.ts Executable file
View File

@@ -0,0 +1,13 @@
export function alfanum(username: string) {
let code, i, len
for (i = 0, len = username.length; i < len; i++) {
code = username.charCodeAt(i)
if (!(code > 47 && code < 58) && // numeric (0-9)
!(code > 64 && code < 91) && // upper alpha (A-Z)
!(code > 96 && code < 123)) { // lower alpha (a-z)
return false
}
}
return true
}

View File

@@ -0,0 +1,25 @@
import { default as Axios, AxiosResponse } from 'axios'
// import { IPayload } from 'model'
import { GlobalConfig, PayloadMessageTypes } from '../common'
import { tools } from '../store/Modules/tools'
// const SITE_URL = GlobalConfig.uri.site
const VALIDATE_USER_URL = process.env.MONGODB_HOST + '/users/'
export function aportadorexist(userName: string) {
if (userName === tools.APORTADOR_NONE)
return true
let onSuccess = (res: AxiosResponse) => {
// console.log('res.status', res.status)
return res.status === PayloadMessageTypes.statusfound
}
return Axios.get(VALIDATE_USER_URL + process.env.APP_ID + '/' + userName)
.then(onSuccess)
.catch((err) => {
// console.log('err', err)
return false
})
}

5
src/validation/complexity.ts Executable file
View File

@@ -0,0 +1,5 @@
import { Patterns } from '@/common'
export function complexity(password: string) {
return Patterns.Password.test(password)
}

23
src/validation/duplicate.ts Executable file
View File

@@ -0,0 +1,23 @@
type t = string | number
type fn = () => t[]
export function duplicate(matches: t[] | fn, ignoreCase: boolean): any {
if (Array.isArray(matches)) return factory(matches, ignoreCase)
return (value: any) => {
let cb = factory(matches(), ignoreCase)
return cb(value)
}
}
function factory(values: t[], ignoreCase: boolean): any {
return (value: any) => {
if (value === undefined || value === null || values.length === 0)
return true
else {
let flags = ignoreCase ? 'i' : ''
let exp = new RegExp(`^(${value})$`, flags)
return values.find(o => exp.test(o.toString())) === undefined
}
}
}

6
src/validation/index.ts Executable file
View File

@@ -0,0 +1,6 @@
export { duplicate } from './duplicate'
export { registereduser } from './registereduser'
export { aportadorexist } from './aportadorexist'
export { registeredemail } from './registeredemail'
export { complexity } from './complexity'
export { alfanum } from './alfanum'

View File

@@ -0,0 +1,24 @@
import { default as Axios, AxiosResponse } from 'axios'
import { GlobalConfig, PayloadMessageTypes } from '../common'
import { helpers } from '@vuelidate/validators'
const { withAsync } = helpers
// const SITE_URL = GlobalConfig.uri.site
const VALIDATE_USER_URL = process.env.MONGODB_HOST + '/email/'
export const registeredemail = withAsync(_registeredemail)
export function _registeredemail(email: string) {
let onSuccess = (res: AxiosResponse) => {
return res.status !== PayloadMessageTypes.statusfound
}
return Axios.get(VALIDATE_USER_URL + process.env.APP_ID + '/' + email)
.then(onSuccess)
.catch((err) => {
return true
})
}

View File

@@ -0,0 +1,25 @@
import { default as Axios, AxiosResponse } from 'axios'
// import { IPayload } from 'model'
import { GlobalConfig, PayloadMessageTypes } from '../common'
import { helpers } from '@vuelidate/validators'
const { withAsync } = helpers
// const SITE_URL = GlobalConfig.uri.site
const VALIDATE_USER_URL = process.env.MONGODB_HOST + '/users/'
export const registereduser = withAsync(_registereduser)
export function _registereduser (userName: string) {
const onSuccess = (res: AxiosResponse) => {
return res.status !== PayloadMessageTypes.statusfound
}
return Axios.get(VALIDATE_USER_URL + process.env.APP_ID + '/' + userName)
.then(onSuccess)
.catch((err) => {
return true
})
}