diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-01-06 15:35:07 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-01-06 15:35:07 +0900 |
| commit | fe691bccbf0622c5f3756d338063354ec56af297 (patch) | |
| tree | ba9928273a4f4746385544dbc83a4fc3b384b27a /src/api | |
| parent | Better comment (diff) | |
| download | sharkey-fe691bccbf0622c5f3756d338063354ec56af297.tar.gz sharkey-fe691bccbf0622c5f3756d338063354ec56af297.tar.bz2 sharkey-fe691bccbf0622c5f3756d338063354ec56af297.zip | |
[API] Implement birthday setting
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/endpoints/i/update.js | 11 | ||||
| -rw-r--r-- | src/api/models/user.ts | 4 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/api/endpoints/i/update.js b/src/api/endpoints/i/update.js index a6b68cf01e..3a6b9da905 100644 --- a/src/api/endpoints/i/update.js +++ b/src/api/endpoints/i/update.js @@ -5,6 +5,7 @@ */ import * as mongo from 'mongodb'; import User from '../../models/user'; +import { isValidBirthday } from '../../models/user'; import serialize from '../../serializers/user'; import event from '../../event'; @@ -50,6 +51,16 @@ module.exports = async (params, user, _, isSecure) => user.bio = bio; } + // Get 'birthday' parameter + const birthday = params.birthday; + if (birthday != null) { + if (!isValidBirthday(birthday)) { + return rej('invalid birthday'); + } + + user.birthday = birthday; + } + // Get 'avatar_id' parameter const avatar = params.avatar_id; if (avatar !== undefined && avatar !== null) { diff --git a/src/api/models/user.ts b/src/api/models/user.ts index 1742f5cafb..ac59e2bfc3 100644 --- a/src/api/models/user.ts +++ b/src/api/models/user.ts @@ -8,3 +8,7 @@ export default collection; export function validateUsername(username: string): boolean { return /^[a-zA-Z0-9\-]{3,20}$/.test(username); } + +export function isValidBirthday(birthday: string): boolean { + return /^([0-9]{4})\-([0-9]{2})-([0-9]{2})$/.test(birthday); +} |