mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-04 20:34:52 +01:00
[API] Fix bug and extract validator
This commit is contained in:
parent
4b9067914e
commit
4f5928c575
2 changed files with 7 additions and 3 deletions
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
import * as mongo from 'mongodb';
|
||||
import User from '../../models/user';
|
||||
import { isValidBirthday } from '../../models/user';
|
||||
import { isValidName, isValidBirthday } from '../../models/user';
|
||||
import serialize from '../../serializers/user';
|
||||
import event from '../../event';
|
||||
import config from '../../../conf';
|
||||
|
@ -25,8 +25,8 @@ module.exports = async (params, user, _, isSecure) =>
|
|||
// Get 'name' parameter
|
||||
const name = params.name;
|
||||
if (name !== undefined && name !== null) {
|
||||
if (name.length > 50) {
|
||||
return rej('too long name');
|
||||
if (!isValidName(name)) {
|
||||
return rej('invalid name');
|
||||
}
|
||||
|
||||
user.name = name;
|
||||
|
|
|
@ -15,6 +15,10 @@ export function validatePassword(password: string): boolean {
|
|||
return typeof password == 'string' && password != '';
|
||||
}
|
||||
|
||||
export function isValidName(name: string): boolean {
|
||||
return typeof name == 'string' && name.length > 50 && name.trim() != '';
|
||||
}
|
||||
|
||||
export function isValidBirthday(birthday: string): boolean {
|
||||
return typeof birthday == 'string' && /^([0-9]{4})\-([0-9]{2})-([0-9]{2})$/.test(birthday);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue