diff --git a/backend/apis/nodejs/src/app.js b/backend/apis/nodejs/src/app.js index 60718f0..6e94238 100644 --- a/backend/apis/nodejs/src/app.js +++ b/backend/apis/nodejs/src/app.js @@ -26,6 +26,7 @@ const organizationAdminRoutes = require('./routes/organization_admin_routes.js') const organizationPostRoutes = require('./routes/organization_post_routes.js'); const jobOffersRoutes = require('./routes/job_offer_routes.js'); const serverRoutes = require('./routes/server_routes.js'); +const resetPasswordRoutes = require('./routes/reset_password_routes.js'); /* ===== END IMPORTING MODULES ===== @@ -55,6 +56,7 @@ app.use('/api/organizations', organizationRoutes.routes); app.use('/api/organizations', jobOffersRoutes.routes); app.use('/api/organizations', organizationAdminRoutes.routes); app.use('/api/organizations', organizationPostRoutes.routes); +app.use('/api/resetpassword', resetPasswordRoutes.routes); /* ===== END ROUTE HANDLING ===== diff --git a/backend/apis/nodejs/src/models/reset_password_model.js b/backend/apis/nodejs/src/models/reset_password_model.js new file mode 100644 index 0000000..9a9551f --- /dev/null +++ b/backend/apis/nodejs/src/models/reset_password_model.js @@ -0,0 +1,26 @@ +/* + This code is part of Blink + licensed under GPLv3 + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +const knex = require('../utils/knex_config'); + +async function add(email, secret){ + await knex('RequestResetPassword') + .insert({ + email, + secret + }); +} + +module.exports = { + add +} \ No newline at end of file diff --git a/backend/apis/nodejs/src/routes/reset_password_routes.js b/backend/apis/nodejs/src/routes/reset_password_routes.js new file mode 100644 index 0000000..bcbba82 --- /dev/null +++ b/backend/apis/nodejs/src/routes/reset_password_routes.js @@ -0,0 +1,44 @@ +/* + This code is part of Blink + licensed under GPLv3 + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. +*/ + +const Person = require('../models/person_model'); +const mailUtils = require('../utils/mail_utils'); +const RequestResetPassword = require('../models/reset_password_model'); +const crypto = require('crypto'); +const express = require('express'); + +async function add(req, res) { + try { + const userExists = await Person.findByEmail(req.body.email); + // If the user does not exist, do not inform them of the absence + // of the user + if (userExists) { + const secret = crypto.randomBytes(16).toString('hex'); + await RequestResetPassword.add(req.body.email, secret); + mailUtils.sendMail(req.body.email, 'Blink Reset Password', secret, null); + } + return res.status(204).send(); + } catch (error) { + console.error(`Error in function ${registerPerson.name}: ${error}`); + res.status(500).json({ + error: 'Internal server error' + }); + } +} + +const routes = express.Router(); +routes.post('/request', add); + +module.exports = { + routes +}; \ No newline at end of file diff --git a/frontend/vanilla/html/register.html b/frontend/vanilla/html/register.html index 2b1882c..d8e0491 100644 --- a/frontend/vanilla/html/register.html +++ b/frontend/vanilla/html/register.html @@ -261,8 +261,7 @@ if (!isAgreeCheckBox.checked) { isFormValid = false; - } else { - } + } else {} return isFormValid; }