ancora su Typescript...
suddiviso i ts dai html e scss
This commit is contained in:
5
src/validation/complexity.ts
Normal file
5
src/validation/complexity.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { Patterns } from '@/common'
|
||||
|
||||
export function complexity(password: string) {
|
||||
return Patterns.Password.test(password)
|
||||
}
|
||||
23
src/validation/duplicate.ts
Normal file
23
src/validation/duplicate.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
type t = string | number;
|
||||
type fn = () => t[];
|
||||
|
||||
export function duplicate(matches: t[] | fn, ignoreCase: boolean = false) {
|
||||
if (Array.isArray(matches)) return factory(matches, ignoreCase);
|
||||
|
||||
return value => {
|
||||
let cb = factory(matches(), ignoreCase);
|
||||
return cb(value);
|
||||
};
|
||||
}
|
||||
|
||||
function factory(values: t[], ignoreCase: boolean) {
|
||||
return value => {
|
||||
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;
|
||||
}
|
||||
};
|
||||
}
|
||||
3
src/validation/index.ts
Normal file
3
src/validation/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export { duplicate } from './duplicate'
|
||||
export { registered } from './registered'
|
||||
export { complexity } from './complexity'
|
||||
22
src/validation/registered.ts
Normal file
22
src/validation/registered.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { default as Axios, AxiosResponse } from 'axios';
|
||||
import { IPayload } from '../model';
|
||||
import { GlobalConfig, PayloadMessageTypes } from '../common';
|
||||
|
||||
const AUTH_URL = GlobalConfig.uri.auth;
|
||||
const VALIDATE_USER_URL = AUTH_URL + 'validateuser';
|
||||
|
||||
export function registered(userName: string) {
|
||||
|
||||
let config = {
|
||||
params: { userName: userName }
|
||||
};
|
||||
|
||||
let onSuccess = (res: AxiosResponse) => {
|
||||
let payload: IPayload<boolean> = res.data;
|
||||
return payload.message.messageTypeId !== PayloadMessageTypes.failure;
|
||||
}
|
||||
|
||||
return Axios.get(VALIDATE_USER_URL, config)
|
||||
.then(onSuccess);
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user