Skip to content
Permalink
Browse files Browse the repository at this point in the history
Feature: Add data transfer object layer to validate and sanitize user…
… inputs (#2694)

* add sanitize-html to be used with dto

* add dto for controllers

* add vaalidation to check token not empty

* update test config

* add validation pipe on test setup

* fix spec

* fix params casing

* update dto for empt checks

* update reset password dto

* only check for options to be defined

* update specs

* update dto and spec

* Remove invalid decorator

* update package-lock

* update thread dto

* update user dto

* fix email

* make comment req params attributes as optional

* fix specs
  • Loading branch information
akshaysasidrn committed Apr 20, 2022
1 parent 6d7a923 commit 431dc96
Show file tree
Hide file tree
Showing 40 changed files with 10,663 additions and 8,291 deletions.
5,059 changes: 3,866 additions & 1,193 deletions frontend/package-lock.json

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions frontend/src/ResetPassword/ResetPasswordPage.jsx
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { Link } from 'react-router-dom';
import { toast } from 'react-hot-toast';
import config from 'config';
import { authenticationService } from '@/_services';

class ResetPassword extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -34,13 +35,8 @@ class ResetPassword extends React.Component {
this.setState({
isLoading: true,
});
fetch(`${config.apiUrl}/reset_password`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(this.state),
})
authenticationService
.resetPassword(this.state)
.then((res) => res.json())
.then((res) => {
if (res.error) {
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/_services/authentication.service.js
Expand Up @@ -14,6 +14,7 @@ export const authenticationService = {
return currentUserSubject.value;
},
signInViaOAuth,
resetPassword,
};

function login(email, password) {
Expand Down Expand Up @@ -55,6 +56,19 @@ function signup(email) {
});
}

function resetPassword(params) {
const { token, password } = params;
const body = JSON.stringify({ token, password });

const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body,
};

return fetch(`${config.apiUrl}/reset_password`, requestOptions);
}

function logout() {
// remove user from local storage to log user out
localStorage.removeItem('currentUser');
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/_services/user.service.js
Expand Up @@ -48,7 +48,7 @@ function setPasswordFromToken({ token, password, organization, role, newSignup,
}

function updateCurrentUser(firstName, lastName) {
const body = { firstName, lastName };
const body = { first_name: firstName, last_name: lastName };
const requestOptions = { method: 'PATCH', headers: authHeader(), body: JSON.stringify(body) };
return fetch(`${config.apiUrl}/users/update`, requestOptions).then(handleResponse);
}
Expand Down
1 change: 1 addition & 0 deletions server/jest.config.ts
Expand Up @@ -12,6 +12,7 @@ module.exports = async () => {
moduleNameMapper: {
'dist/src/entities/(.*)': '<rootDir>/dist/src/entities/$1',
'^src/(.*)': '<rootDir>/src/$1',
'@dto/(.*)': '<rootDir>/src/dto/$1',
'@plugins/(.*)': '<rootDir>/plugins/$1',
'@services/(.*)': '<rootDir>/src/services/$1',
'@controllers/(.*)': '<rootDir>/src/controllers/$1',
Expand Down

0 comments on commit 431dc96

Please sign in to comment.