aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-12-28 15:49:23 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-12-28 15:49:23 +0100
commit67bf9b96bbcd92b069fe86d9223fe0f8b9c6e677 (patch)
treebae6a9b0c3133c9cc38a2972222b5991f0cf614e /server/initializers
parent552cc9d646e78edae8b0fe61564d4e49db0b6206 (diff)
downloadPeerTube-67bf9b96bbcd92b069fe86d9223fe0f8b9c6e677.tar.gz
PeerTube-67bf9b96bbcd92b069fe86d9223fe0f8b9c6e677.tar.zst
PeerTube-67bf9b96bbcd92b069fe86d9223fe0f8b9c6e677.zip
Server: add database field validations
Diffstat (limited to 'server/initializers')
-rw-r--r--server/initializers/constants.js2
-rw-r--r--server/initializers/installer.js10
2 files changed, 8 insertions, 4 deletions
diff --git a/server/initializers/constants.js b/server/initializers/constants.js
index fc501845a..0af7aca3c 100644
--- a/server/initializers/constants.js
+++ b/server/initializers/constants.js
@@ -69,7 +69,7 @@ const CONSTRAINTS_FIELDS = {
69 NAME: { min: 3, max: 50 }, // Length 69 NAME: { min: 3, max: 50 }, // Length
70 DESCRIPTION: { min: 3, max: 250 }, // Length 70 DESCRIPTION: { min: 3, max: 250 }, // Length
71 EXTNAME: [ '.mp4', '.ogv', '.webm' ], 71 EXTNAME: [ '.mp4', '.ogv', '.webm' ],
72 INFO_HASH: { min: 10, max: 50 }, // Length 72 INFO_HASH: { min: 40, max: 40 }, // Length, infohash is 20 bytes length but we represent it in hexa so 20 * 2
73 DURATION: { min: 1, max: 7200 }, // Number 73 DURATION: { min: 1, max: 7200 }, // Number
74 TAGS: { min: 1, max: 3 }, // Number of total tags 74 TAGS: { min: 1, max: 3 }, // Number of total tags
75 TAG: { min: 2, max: 10 }, // Length 75 TAG: { min: 2, max: 10 }, // Length
diff --git a/server/initializers/installer.js b/server/initializers/installer.js
index d5382364e..fb63b81ac 100644
--- a/server/initializers/installer.js
+++ b/server/initializers/installer.js
@@ -96,6 +96,7 @@ function createOAuthAdminIfNotExist (callback) {
96 96
97 const username = 'root' 97 const username = 'root'
98 const role = constants.USER_ROLES.ADMIN 98 const role = constants.USER_ROLES.ADMIN
99 const createOptions = {}
99 let password = '' 100 let password = ''
100 101
101 // Do not generate a random password for tests 102 // Do not generate a random password for tests
@@ -105,17 +106,20 @@ function createOAuthAdminIfNotExist (callback) {
105 if (process.env.NODE_APP_INSTANCE) { 106 if (process.env.NODE_APP_INSTANCE) {
106 password += process.env.NODE_APP_INSTANCE 107 password += process.env.NODE_APP_INSTANCE
107 } 108 }
109
110 // Our password is weak so do not validate it
111 createOptions.validate = false
108 } else { 112 } else {
109 password = passwordGenerator(8, true) 113 password = passwordGenerator(8, true)
110 } 114 }
111 115
112 const user = db.User.build({ 116 const userData = {
113 username, 117 username,
114 password, 118 password,
115 role 119 role
116 }) 120 }
117 121
118 user.save().asCallback(function (err, createdUser) { 122 db.User.create(userData, createOptions).asCallback(function (err, createdUser) {
119 if (err) return callback(err) 123 if (err) return callback(err)
120 124
121 logger.info('Username: ' + username) 125 logger.info('Username: ' + username)