README
Register, login with mysql
Features:
Initializting:
const mlwm = require('@nyeduhu/nyedu-login-with-mysql');
mlwm.init("db's address", "user", "user's password", "database");
Getting all users:
const mlwm = require('@nyeduhu/nyedu-login-with-mysql');
mlwm.init("db's address", "user", "user's password", "database");
mlwm.getAll("users", (result) => {
console.log(`Current user(s): \n`);
result.forEach(u => {
console.log(u.username)
});
});
Registering a user:
const mlwm = require('@nyeduHu/nyedu-login-with-mysql');
mlwm.init("db's address", "user", "user's password", "database");
const myDummyUser = {
id: Math.floor(Math.random() * 100),
username: `dummyUser${Math.floor(Math.random() * 100)}`,
email: `dummy${Math.floor(Math.random() * 100)}@country${Math.floor(Math.random() * 100)}.com`,
password: "password"
};
mlwm.register("your users table", myDummyUser.username, myDummyUser.email, myDummyUser.password, myDummyUser.id);
Logging into a user:
const mlwm = require('@nyeduHu/nyedu-login-with-mysql');
mlwm.init("db's address", "user", "user's password", "database");
mlwm.login("your users table", "username", "password", (res) => {
console.log(`Logged in as ${res.username}`);
});
Example code:
console.log('Launched');
const mlwm = require('@nyeduhu/nyedu-login-with-mysql');
mlwm.init("your_DB's_address", "your user", "your password", "your database");
mlwm.getAll("users", (result) => {
console.log(`Current user(s): \n`);
result.forEach(u => {
console.log(u.username)
});
});
const myDummyUser = {
id: Math.floor(Math.random() * 100),
username: `dummyUser${Math.floor(Math.random() * 100)}`,
email: `dummy${Math.floor(Math.random() * 100)}@country${Math.floor(Math.random() * 100)}.com`,
password: "password"
};
mlwm.register("users", myDummyUser.username, myDummyUser.email, myDummyUser.password, myDummyUser.id);
mlwm.login("users" , myDummyUser.username, myDummyUser.password, (result) => {
let res = result;
console.log(`Logged in! \nHere's the user's name!\n-${res.username}`);
});