@strapi/strapi 4.1.4-alpha.0 → 4.1.4-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/strapi.js CHANGED
@@ -174,6 +174,16 @@ program
174
174
  .action(getLocalScript('configurationRestore'));
175
175
 
176
176
  // Admin
177
+ program
178
+ .command('admin:create-user')
179
+ .alias('admin:create')
180
+ .description('Create a new admin')
181
+ .option('-e, --email <email>', 'Email of the new admin')
182
+ .option('-p, --password <password>', 'Password of the new admin')
183
+ .option('-f, --firstname <first name>', 'First name of the new admin')
184
+ .option('-l, --lastname <last name>', 'Last name of the new admin')
185
+ .action(getLocalScript('admin-create'));
186
+
177
187
  program
178
188
  .command('admin:reset-user-password')
179
189
  .alias('admin:reset-password')
@@ -0,0 +1,115 @@
1
+ 'use strict';
2
+
3
+ const { yup } = require('@strapi/utils');
4
+ const _ = require('lodash');
5
+ const inquirer = require('inquirer');
6
+ const strapi = require('../index');
7
+
8
+ const emailValidator = yup
9
+ .string()
10
+ .email('Invalid email address')
11
+ .lowercase();
12
+
13
+ const passwordValidator = yup
14
+ .string()
15
+ .min(8, 'Password must be at least 8 characters long')
16
+ .matches(/[a-z]/, 'Password must contain at least one lowercase character')
17
+ .matches(/[A-Z]/, 'Password must contain at least one uppercase character')
18
+ .matches(/\d/, 'Password must contain at least one number');
19
+
20
+ const adminCreateSchema = yup.object().shape({
21
+ email: emailValidator,
22
+ password: passwordValidator,
23
+ firstname: yup.string().required('First name is required'),
24
+ lastname: yup.string(),
25
+ });
26
+
27
+ const promptQuestions = [
28
+ {
29
+ type: 'input',
30
+ name: 'email',
31
+ message: 'Admin email?',
32
+ async validate(value) {
33
+ const validEmail = await emailValidator.validate(value);
34
+ return validEmail === value || validEmail;
35
+ },
36
+ },
37
+ {
38
+ type: 'password',
39
+ name: 'password',
40
+ message: 'Admin password?',
41
+ async validate(value) {
42
+ const validPassword = await passwordValidator.validate(value);
43
+ return validPassword === value || validPassword;
44
+ },
45
+ },
46
+ { type: 'input', name: 'firstname', message: 'First name?' },
47
+ { type: 'input', name: 'lastname', message: 'Last name?' },
48
+ {
49
+ type: 'confirm',
50
+ name: 'confirm',
51
+ message: 'Do you really want to create a new admin?',
52
+ },
53
+ ];
54
+
55
+ /**
56
+ * Create new admin user
57
+ * @param {Object} cmdOptions - command options
58
+ * @param {string} cmdOptions.email - new admin's email
59
+ * @param {string} [cmdOptions.password] - new admin's password
60
+ * @param {string} cmdOptions.firstname - new admin's first name
61
+ * @param {string} [cmdOptions.lastname] - new admin's last name
62
+ */
63
+ module.exports = async function(cmdOptions = {}) {
64
+ let { email, password, firstname, lastname } = cmdOptions;
65
+
66
+ if (
67
+ _.isEmpty(email) &&
68
+ _.isEmpty(password) &&
69
+ _.isEmpty(firstname) &&
70
+ _.isEmpty(lastname) &&
71
+ process.stdin.isTTY
72
+ ) {
73
+ const inquiry = await inquirer.prompt(promptQuestions);
74
+
75
+ if (!inquiry.confirm) {
76
+ process.exit(0);
77
+ }
78
+
79
+ ({ email, password, firstname, lastname } = inquiry);
80
+ }
81
+
82
+ try {
83
+ await adminCreateSchema.validate({ email, password, firstname, lastname });
84
+ } catch (err) {
85
+ console.error(err.errors[0]);
86
+ process.exit(1);
87
+ }
88
+
89
+ return createAdmin({ email, password, firstname, lastname });
90
+ };
91
+
92
+ async function createAdmin({ email, password, firstname, lastname }) {
93
+ const app = await strapi().load();
94
+
95
+ const user = await app.admin.services.user.exists({ email });
96
+
97
+ if (user) {
98
+ console.error(`User with email "${email}" already exists`);
99
+ process.exit(1);
100
+ }
101
+
102
+ const superAdminRole = await app.admin.services.role.getSuperAdmin();
103
+
104
+ await app.admin.services.user.create({
105
+ email,
106
+ firstname,
107
+ lastname,
108
+ isActive: true,
109
+ roles: [superAdminRole.id],
110
+ ...(password && { password, registrationToken: null }),
111
+ });
112
+
113
+ console.log(`Successfully created new admin`);
114
+ process.exit(0);
115
+ }
@@ -12,7 +12,7 @@ const defaults = {
12
12
  useDefaults: true,
13
13
  directives: {
14
14
  'connect-src': ["'self'", 'https:'],
15
- 'img-src': ["'self'", 'data:', 'blob:'],
15
+ 'img-src': ["'self'", 'data:', 'blob:', 'https://dl.airtable.com'],
16
16
  'media-src': ["'self'", 'data:', 'blob:'],
17
17
  upgradeInsecureRequests: null,
18
18
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/strapi",
3
- "version": "4.1.4-alpha.0",
3
+ "version": "4.1.4-alpha.3",
4
4
  "description": "An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite",
5
5
  "keywords": [
6
6
  "strapi",
@@ -80,16 +80,16 @@
80
80
  "dependencies": {
81
81
  "@koa/cors": "3.1.0",
82
82
  "@koa/router": "10.1.1",
83
- "@strapi/admin": "4.1.4-alpha.0",
84
- "@strapi/database": "4.1.4-alpha.0",
85
- "@strapi/generate-new": "4.1.4-alpha.0",
86
- "@strapi/generators": "4.1.4-alpha.0",
87
- "@strapi/logger": "4.1.4-alpha.0",
88
- "@strapi/plugin-content-manager": "4.1.4-alpha.0",
89
- "@strapi/plugin-content-type-builder": "4.1.4-alpha.0",
90
- "@strapi/plugin-email": "4.1.4-alpha.0",
91
- "@strapi/plugin-upload": "4.1.4-alpha.0",
92
- "@strapi/utils": "4.1.4-alpha.0",
83
+ "@strapi/admin": "4.1.4-alpha.3",
84
+ "@strapi/database": "4.1.4-alpha.3",
85
+ "@strapi/generate-new": "4.1.4-alpha.3",
86
+ "@strapi/generators": "4.1.4-alpha.3",
87
+ "@strapi/logger": "4.1.4-alpha.3",
88
+ "@strapi/plugin-content-manager": "4.1.4-alpha.3",
89
+ "@strapi/plugin-content-type-builder": "4.1.4-alpha.3",
90
+ "@strapi/plugin-email": "4.1.4-alpha.3",
91
+ "@strapi/plugin-upload": "4.1.4-alpha.3",
92
+ "@strapi/utils": "4.1.4-alpha.3",
93
93
  "bcryptjs": "2.4.3",
94
94
  "boxen": "5.1.2",
95
95
  "chalk": "4.1.2",
@@ -136,5 +136,5 @@
136
136
  "node": ">=12.22.0 <=16.x.x",
137
137
  "npm": ">=6.0.0"
138
138
  },
139
- "gitHead": "3be69154deba4ceaffa8642e3f9ebe3768a7f388"
139
+ "gitHead": "8f3ac1d80e0e3ebb56173fb1302afe74e545b658"
140
140
  }