diff --git a/API/data/TableCreation.js b/API/data/TableCreation.js index 7508f85..e8faa94 100644 --- a/API/data/TableCreation.js +++ b/API/data/TableCreation.js @@ -43,7 +43,7 @@ async function createUserTable(query) { id INT AUTO_INCREMENT PRIMARY KEY, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, - identifier VARCHAR(255) NOT NULL, + identifier VARCHAR(255) NOT NULL UNIQUE, archived_date Datetime default NULL )`; diff --git a/API/model/Managers/UserManager.js b/API/model/Managers/UserManager.js index 31b5c84..79e10e7 100644 --- a/API/model/Managers/UserManager.js +++ b/API/model/Managers/UserManager.js @@ -30,7 +30,11 @@ async function add(user) { assert(user.email, '[UserManager.add] The email is required'); assert(/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(user.email), '[UserManager.add] The email is not valid'); - return await UserQueries.add(user); + try { + return await UserQueries.add(user); + } catch (e) { + return e; + } } @@ -175,12 +179,11 @@ async function unarchive(id) { */ async function generateSigningToken(data, documentId) { - let userId; + const user = await UserQueries.getByEmail(data.email); - // check for the user / add it if needed - if (!await UserQueries.getByEmail(data.email)) { - userId = await UserQueries.add(data); - } + assert(user, '[UserManager.generateSigningToken] The user is required'); // may check the addUser from the front + + const userId = user.id; assert(data.email, '[UserManager.generateSigningToken] The email is required'); assert(documentId, '[UserManager.generateSigningToken] The documentId is required'); @@ -193,10 +196,6 @@ async function generateSigningToken(data, documentId) { token = utils.generateRandomToken(5, false); } - // Get the user and version IDs - if (!userId) { - userId = (await UserQueries.getByEmail(data.email)).id; - } const versionId = (await VersionQueries.getLatest(documentId)).id; // Add the token to the database diff --git a/FRONT/js/model/popups/SigningLinkPopup.js b/FRONT/js/model/popups/SigningLinkPopup.js index c988ef8..293ca32 100644 --- a/FRONT/js/model/popups/SigningLinkPopup.js +++ b/FRONT/js/model/popups/SigningLinkPopup.js @@ -151,7 +151,10 @@ class SigningLinkPopup extends Popup { // actions to be taken when the popup is clicked const actions = { - 'signing-link-copy': async (_, link) => await Utils.copyToClipboard(link), + 'signing-link-copy': async (_, link) => { + await Utils.copyToClipboard(link) + alert('Lien copié dans le presse-papier'); + }, 'signing-link-mailto': async (user, link) => { // send the mail window.location.href = `mailto:${user.identifier}?subject=Signature du document ${docName}&body=Bonjour ${user.first_name} ${user.last_name},%0D%0AMerci de signer ce document à l'adresse suivante : ${link}.%0D%0ACordialement.`;