-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from vim/user-authentication
User authentication
- Loading branch information
Showing
22 changed files
with
1,054 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
cms/src/extensions/users-permissions/content-types/user/schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// example migration | ||
const strapiUrl = "http://localhost:1337/api"; | ||
const axios = require("axios"); | ||
|
||
async function getUsersFromStrapi() { | ||
try { | ||
const response = await axios.get(`${strapiUrl}/users`); | ||
const users = response.data; | ||
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; | ||
} | ||
} | ||
|
||
const mysql = require("mysql2"); | ||
const connection = mysql.createConnection({ | ||
host: "localhost", | ||
user: "vim", | ||
database: "vim", | ||
password: "super-secret", | ||
}); | ||
|
||
connection.query("SELECT * FROM `vs_users`", function (err, results, fields) { | ||
console.log(results); | ||
|
||
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.