diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-04-02 04:52:11 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-04-02 04:52:11 +0900 |
| commit | 6b6adeaa68a92d128179f97e40102d4d869ccebf (patch) | |
| tree | e31023776e38827dfb9f7df42fb1fce74760e9d7 /src | |
| parent | Refactor (diff) | |
| download | misskey-6b6adeaa68a92d128179f97e40102d4d869ccebf.tar.gz misskey-6b6adeaa68a92d128179f97e40102d4d869ccebf.tar.bz2 misskey-6b6adeaa68a92d128179f97e40102d4d869ccebf.zip | |
Refactor
Diffstat (limited to 'src')
| -rw-r--r-- | src/models/user.ts | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/src/models/user.ts b/src/models/user.ts index bbe9b5a533..2d1693573d 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -15,30 +15,6 @@ User.createIndex('account.token'); export default User; -export function validateUsername(username: string): boolean { - return typeof username == 'string' && /^[a-zA-Z0-9\-]{3,20}$/.test(username); -} - -export function validatePassword(password: string): boolean { - return typeof password == 'string' && password != ''; -} - -export function isValidName(name: string): boolean { - return typeof name == 'string' && name.length < 30 && name.trim() != ''; -} - -export function isValidDescription(description: string): boolean { - return typeof description == 'string' && description.length < 500 && description.trim() != ''; -} - -export function isValidLocation(location: string): boolean { - return typeof location == 'string' && location.length < 50 && location.trim() != ''; -} - -export function isValidBirthday(birthday: string): boolean { - return typeof birthday == 'string' && /^([0-9]{4})\-([0-9]{2})-([0-9]{2})$/.test(birthday); -} - type IUserBase = { _id: mongo.ObjectID; createdAt: Date; @@ -61,8 +37,6 @@ type IUserBase = { hostLower: string; }; -export type IUser = ILocalUser | IRemoteUser; - export interface ILocalUser extends IUserBase { host: null; account: { @@ -108,12 +82,38 @@ export interface IRemoteUser extends IUserBase { }; } +export type IUser = ILocalUser | IRemoteUser; + export const isLocalUser = (user: any): user is ILocalUser => user.host === null; export const isRemoteUser = (user: any): user is IRemoteUser => !isLocalUser(user); +export function validateUsername(username: string): boolean { + return typeof username == 'string' && /^[a-zA-Z0-9\-]{3,20}$/.test(username); +} + +export function validatePassword(password: string): boolean { + return typeof password == 'string' && password != ''; +} + +export function isValidName(name: string): boolean { + return typeof name == 'string' && name.length < 30 && name.trim() != ''; +} + +export function isValidDescription(description: string): boolean { + return typeof description == 'string' && description.length < 500 && description.trim() != ''; +} + +export function isValidLocation(location: string): boolean { + return typeof location == 'string' && location.length < 50 && location.trim() != ''; +} + +export function isValidBirthday(birthday: string): boolean { + return typeof birthday == 'string' && /^([0-9]{4})\-([0-9]{2})-([0-9]{2})$/.test(birthday); +} + export function init(user): IUser { user._id = new mongo.ObjectID(user._id); user.avatarId = new mongo.ObjectID(user.avatarId); |