Skip to content

Commit

Permalink
wip: will squash, rename commits
Browse files Browse the repository at this point in the history
  • Loading branch information
izzyyhh committed May 7, 2024
1 parent 69747e6 commit 7ce4efa
Show file tree
Hide file tree
Showing 5 changed files with 372 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"kind": "collectionType",
"collectionName": "up_users",
"info": {
"name": "user",
"description": "",
"singularName": "user",
"pluralName": "users",
"displayName": "User"
},
"options": {
"draftAndPublish": false
},
"attributes": {
"username": {
"type": "string",
"minLength": 3,
"unique": true,
"configurable": false,
"required": true
},
"email": {
"type": "email",
"minLength": 6,
"configurable": false,
"required": true
},
"provider": {
"type": "string",
"configurable": false
},
"password": {
"type": "password",
"minLength": 6,
"configurable": false,
"private": true,
"searchable": false
},
"resetPasswordToken": {
"type": "string",
"configurable": false,
"private": true,
"searchable": false
},
"confirmationToken": {
"type": "string",
"configurable": false,
"private": true,
"searchable": false
},
"confirmed": {
"type": "boolean",
"default": false,
"configurable": false
},
"blocked": {
"type": "boolean",
"default": false,
"configurable": false
},
"role": {
"type": "relation",
"relation": "manyToOne",
"target": "plugin::users-permissions.role",
"inversedBy": "users",
"configurable": false
},
"old_pw_hash": {
"type": "string"
},
"migrated_pw": {
"type": "boolean",
"default": false
}
}
}
3 changes: 3 additions & 0 deletions cms/src/extensions/users-permissions/strapi-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = plugin => {
const x =
};
207 changes: 207 additions & 0 deletions scripts/user-migration/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions scripts/user-migration/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "user-migration",
"version": "1.0.0",
"description": "",
"main": "user-migration.js",
"scripts": {
"migrate": "node user-migration.js"
},
"author": "izzy",
"license": "ISC",
"dependencies": {
"axios": "^1.6.8",
"mysql2": "^3.9.3"
}
}
71 changes: 71 additions & 0 deletions scripts/user-migration/user-migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const strapiUrl = "http://localhost:1337/api";

const axios = require("axios");

async function getUsersFromStrapi() {
try {
// Make a GET request to the Strapi API to fetch users
const response = await axios.get(`${strapiUrl}/users`);

// Extract user data from the response
const users = response.data;

// Output user data
console.log("Users:");
console.log(users);
} catch (error) {
console.error("Error fetching users:", error.message);
}
}

async function createUser(username, email, password, old_password) {
try {
const response = await fetch(`${strapiUrl}/auth/local/register`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
username: username,
email: email,
password: password,
old_pw_hash: old_password,
}),
});
console.log(response);

return await response.json();
} catch (e) {
console.log("something went wrong");
console.log(e);
return null;
}
}

// Get the client
const mysql = require("mysql2");
// Create the connection to database
const connection = mysql.createConnection({
host: "localhost",
user: "vim",
database: "vim",
password: "super-secret",
});

// A simple SELECT query
connection.query("SELECT * FROM `vs_users`", function (err, results, fields) {
console.log(results); // results contains rows returned by server

results.forEach((user) => {
createUser(user.user_name, user.email, "123gege321", "old_hash")
.then((a) => {
console.log(a);
})
.catch((err) => {
console.log(err);
});
});

console.log(fields); // fields contains extra meta data about results, if available
});

0 comments on commit 7ce4efa

Please sign in to comment.