Skip to content

Commit

Permalink
Merge pull request #269 from piyushyadav1617/dev-branch
Browse files Browse the repository at this point in the history
pass error and encryption in widget
  • Loading branch information
moonlightnexus authored Feb 3, 2024
2 parents b35f535 + fc57ff0 commit 719e4f2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
25 changes: 16 additions & 9 deletions src/app/widget/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

'use client';
import { testPass, passMsg, testOTP, convertToApproxTime } from './utils';
import {
testPass,
passMsg,
testOTP,
convertToApproxTime,
encrypt
} from './utils';
import Image from 'next/image';
import React, { useEffect, useState } from 'react';
import { redirect, useSearchParams } from 'next/navigation';
import { useSearchParams } from 'next/navigation';
import { useRouter } from 'next/navigation';
import { OrgData, useOrgData, useUserData } from './widgetStore'; //import zustand store to store and update org data
import Spinner from '@/components/spinner';
Expand Down Expand Up @@ -131,6 +136,7 @@ export default function Widget() {
}

try {
const encryptedPass = encrypt(newPass);
const response = await fetch(`https://api.trustauthx.com/user/me/auth`, {
method: 'PUT',
headers: {
Expand All @@ -139,7 +145,7 @@ export default function Widget() {
body: JSON.stringify({
usr: {
forget_password: true,
new_password: newPass
new_password: encryptedPass
},
UserTokenBody: {
UserToken: currentUserToken
Expand Down Expand Up @@ -191,6 +197,7 @@ export default function Widget() {
});
return;
}
const encryptedPass = encrypt(newPass);
try {
const response = await fetch(`https://api.trustauthx.com/user/me/auth`, {
method: 'PUT',
Expand All @@ -199,7 +206,7 @@ export default function Widget() {
},
body: JSON.stringify({
usr: {
new_user_password: newPass
new_user_password: encryptedPass
},
UserTokenBody: {
UserToken: currentUserToken
Expand Down Expand Up @@ -369,7 +376,7 @@ export default function Widget() {
});
return;
}

const encryptedPass = encrypt(pass);
try {
let rcToken = '';
if (storeOrgData.bot_det) {
Expand All @@ -383,7 +390,7 @@ export default function Widget() {
body: JSON.stringify({
form_data: {
email: email,
password: pass,
password: encryptedPass,
mfa_totp: otp ? otp : 0,
rc_token: rcToken
},
Expand Down Expand Up @@ -461,7 +468,7 @@ export default function Widget() {
setLoading2(false);
return;
}

const encryptedPass = encrypt(pass);
try {
let rcToken = '';
if (storeOrgData.bot_det) {
Expand All @@ -475,7 +482,7 @@ export default function Widget() {
body: JSON.stringify({
form_data: {
email: email,
password: pass,
password: encryptedPass,
mfa_totp: otp ? otp : 0,
rc_token: rcToken
},
Expand Down
11 changes: 11 additions & 0 deletions src/app/widget/login/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ export const decryptCode = (mfa: string): string => {
const decoded = bytes.toString(CryptoJS.enc.Utf8);
return decoded;
};
export const encrypt = (pass: string) => {
// console.log(pass)
// try {
// const encrypted = CryptoJS.AES.encrypt(pass, process.env.NEXT_PUBLIC_AES_KEY ? process.env.NEXT_PUBLIC_AES_KEY : '');
// return encrypted
// } catch (error) {
// console.error('Encryption failed:', error);
// return;
// }
return pass;
};
//to test input password string
export const testPass = (password: string): boolean => {
// /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,1000}$/
Expand Down
5 changes: 4 additions & 1 deletion src/app/widget/profile/SecurityTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
testPass,
testOTP,
decryptCode,
encrypt,
convertToApproxTime
} from '../login/utils';
import Spinner from '@/components/spinner';
Expand Down Expand Up @@ -279,6 +280,7 @@ export default function Security() {

async function newPasswordRequest() {
setLoading1(true);
const encryptedPass = encrypt(pass);
try {
const response = await fetch(`https://api.trustauthx.com/user/me/auth`, {
method: 'PUT',
Expand All @@ -287,7 +289,8 @@ export default function Security() {
},
body: JSON.stringify({
usr: {
forget_password: pass
forget_password: true,
new_password: encryptedPass
},
UserTokenBody: {
UserToken: user_token
Expand Down
1 change: 0 additions & 1 deletion src/app/widget/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { getAccessToken } from './utils';
import { IoArrowBackOutline } from 'react-icons/io5';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { useRouter } from 'next/navigation';
import { get } from 'http';

export default function WidgetProfile() {
const searchParams = useSearchParams();
Expand Down

0 comments on commit 719e4f2

Please sign in to comment.