mirror of
				https://github.com/xfarrow/blink
				synced 2025-06-27 09:03:02 +02:00 
			
		
		
		
	create reset password route
This commit is contained in:
		| @@ -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 ===== | ||||
|   | ||||
							
								
								
									
										26
									
								
								backend/apis/nodejs/src/models/reset_password_model.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								backend/apis/nodejs/src/models/reset_password_model.js
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||
| } | ||||
							
								
								
									
										44
									
								
								backend/apis/nodejs/src/routes/reset_password_routes.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								backend/apis/nodejs/src/routes/reset_password_routes.js
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||
| }; | ||||
| @@ -261,8 +261,7 @@ | ||||
|  | ||||
|             if (!isAgreeCheckBox.checked) { | ||||
|                 isFormValid = false; | ||||
|             } else { | ||||
|             } | ||||
|             } else {} | ||||
|             return isFormValid; | ||||
|         } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user