Skip to content
This repository was archived by the owner on Jun 28, 2025. It is now read-only.

Commit f5c892d

Browse files
authored
Merge pull request #24 from vim/user-authentication
User authentication
2 parents 2750083 + 2ff10a6 commit f5c892d

File tree

22 files changed

+1054
-24
lines changed

22 files changed

+1054
-24
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ DATABASE_PASSWORD=super-secret
44
DATABASE_PORT=3306
55
DATABASE_SSL=false
66

7-
APP_DATABASE_NAME=vim
7+
WEB_DATABASE_NAME=vim
88
CMS_DATABASE_NAME=vim_cms
99

1010
CMS_PORT=1337
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"kind": "collectionType",
3+
"collectionName": "up_users",
4+
"info": {
5+
"name": "user",
6+
"description": "",
7+
"singularName": "user",
8+
"pluralName": "users",
9+
"displayName": "User"
10+
},
11+
"options": {
12+
"draftAndPublish": false
13+
},
14+
"attributes": {
15+
"username": {
16+
"type": "string",
17+
"minLength": 3,
18+
"unique": true,
19+
"configurable": false,
20+
"required": true
21+
},
22+
"email": {
23+
"type": "email",
24+
"minLength": 6,
25+
"configurable": false,
26+
"required": true
27+
},
28+
"provider": {
29+
"type": "string",
30+
"configurable": false
31+
},
32+
"password": {
33+
"type": "password",
34+
"minLength": 6,
35+
"configurable": false,
36+
"private": true,
37+
"searchable": false
38+
},
39+
"resetPasswordToken": {
40+
"type": "string",
41+
"configurable": false,
42+
"private": true,
43+
"searchable": false
44+
},
45+
"confirmationToken": {
46+
"type": "string",
47+
"configurable": false,
48+
"private": true,
49+
"searchable": false
50+
},
51+
"confirmed": {
52+
"type": "boolean",
53+
"default": false,
54+
"configurable": false
55+
},
56+
"blocked": {
57+
"type": "boolean",
58+
"default": false,
59+
"configurable": false
60+
},
61+
"role": {
62+
"type": "relation",
63+
"relation": "manyToOne",
64+
"target": "plugin::users-permissions.role",
65+
"inversedBy": "users",
66+
"configurable": false
67+
},
68+
"old_pw_hash": {
69+
"type": "string"
70+
},
71+
"migrated_pw": {
72+
"type": "boolean",
73+
"default": false
74+
}
75+
}
76+
}

scripts/user-migration/package-lock.json

Lines changed: 207 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/user-migration/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "user-migration",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "user-migration.js",
6+
"scripts": {
7+
"migrate": "node user-migration.js"
8+
},
9+
"author": "izzy",
10+
"license": "ISC",
11+
"dependencies": {
12+
"axios": "^1.6.8",
13+
"mysql2": "^3.9.3"
14+
}
15+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// example migration
2+
const strapiUrl = "http://localhost:1337/api";
3+
const axios = require("axios");
4+
5+
async function getUsersFromStrapi() {
6+
try {
7+
const response = await axios.get(`${strapiUrl}/users`);
8+
const users = response.data;
9+
console.log(users);
10+
} catch (error) {
11+
console.error("Error fetching users:", error.message);
12+
}
13+
}
14+
15+
async function createUser(username, email, password, old_password) {
16+
try {
17+
const response = await fetch(`${strapiUrl}/auth/local/register`, {
18+
method: "POST",
19+
headers: {
20+
"Content-Type": "application/json",
21+
Accept: "application/json",
22+
},
23+
body: JSON.stringify({
24+
username: username,
25+
email: email,
26+
password: password,
27+
old_pw_hash: old_password,
28+
}),
29+
});
30+
console.log(response);
31+
32+
return await response.json();
33+
} catch (e) {
34+
console.log("something went wrong");
35+
console.log(e);
36+
return null;
37+
}
38+
}
39+
40+
const mysql = require("mysql2");
41+
const connection = mysql.createConnection({
42+
host: "localhost",
43+
user: "vim",
44+
database: "vim",
45+
password: "super-secret",
46+
});
47+
48+
connection.query("SELECT * FROM `vs_users`", function (err, results, fields) {
49+
console.log(results);
50+
51+
results.forEach((user) => {
52+
createUser(user.user_name, user.email, "123gege321", "old_hash")
53+
.then((a) => {
54+
console.log(a);
55+
})
56+
.catch((err) => {
57+
console.log(err);
58+
});
59+
});
60+
61+
console.log(fields);
62+
});

web/Dockerfile.dev

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ COPY next.config.js .
1717
COPY tsconfig.json .
1818
COPY postcss.config.js .
1919
COPY tailwind.config.ts .
20+
COPY .env .
2021

2122
ENV NEXT_TELEMETRY_DISABLED 1
2223

0 commit comments

Comments
 (0)