37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
import grabDbFullName from "../../../../utils/grab-db-full-name";
|
|
import varDatabaseDbHandler from "../../../backend/varDatabaseDbHandler";
|
|
/**
|
|
* # API Login
|
|
*/
|
|
export default async function apiSendResetPasswordLink({ database, email, dbUserId, debug, }) {
|
|
const dbFullName = grabDbFullName({ dbName: database, userId: dbUserId });
|
|
if (!dbFullName) {
|
|
return {
|
|
success: false,
|
|
msg: `Couldn't get database full name`,
|
|
};
|
|
}
|
|
if (email === null || email === void 0 ? void 0 : email.match(/ /)) {
|
|
return {
|
|
success: false,
|
|
msg: "Invalid Email/Password format",
|
|
};
|
|
}
|
|
let foundUser = await varDatabaseDbHandler({
|
|
queryString: `SELECT * FROM ${dbFullName}.users WHERE email = ? OR username = ?`,
|
|
queryValuesArray: [email, email],
|
|
database: dbFullName,
|
|
debug,
|
|
});
|
|
if (debug) {
|
|
console.log("apiSendResetPassword:foundUser:", foundUser);
|
|
}
|
|
const targetUser = foundUser === null || foundUser === void 0 ? void 0 : foundUser[0];
|
|
if (!targetUser)
|
|
return {
|
|
success: false,
|
|
msg: "No user found",
|
|
};
|
|
return { success: true };
|
|
}
|