Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: on account_status add Reason #19

Open
wants to merge 4 commits into
base: release/hp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions captcha-service/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ db.defaults({ captchas: [] }).write();
app.listen(port, host, () => console.log(`listening on port: ${port}`));

app.get("/", (request, response) => {
const captchaParsed = Math.random().toString(36).substr(2,6).toUpperCase();
const captchaParsed = parseInt(Math.random() * 900000 + 100000);
var p = new captchapng(120, 30, captchaParsed); // width,height,numeric captcha
p.color(0, 0, 0, 0); // First color: background (red, green, blue, alpha)
p.color(80, 80, 80, 255); // Second color: paint (red, green, blue, alpha)
Expand Down Expand Up @@ -83,7 +83,7 @@ app.get("/verify", (request, response) => {
}

deleteUsedCaptcha(token);
if (userResponse === (captcha && captcha.captchaParsed)) {
if (parseInt(userResponse) === (captcha && captcha.captchaParsed)) {
response.status(200).send({ status: "Success" });
} else {
response.status(400).send({ status: "Code Incorrect" });
Expand All @@ -95,4 +95,4 @@ app.get("/verify", (request, response) => {
});
function deleteUsedCaptcha(token) {
db.get("captchas").remove({ token: token }).write();
}
}
41 changes: 26 additions & 15 deletions portal/components/login/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import controls from "./form.config";
import styles from "../../styles/Login.module.css";
import axios from "axios";
import Image from "next/image";
const CryptoJS = require('crypto-js');
const CryptoJS = require("crypto-js");

export default function Login(props) {
const { persona } = props;
Expand Down Expand Up @@ -53,7 +53,6 @@ export default function Login(props) {
setCaptchaToken(token);
})
.catch((err) => {
console.log(err)
addToast(err.response?.data?.errors || err.message, {
appearance: "error",
});
Expand All @@ -64,7 +63,7 @@ export default function Login(props) {
e.preventDefault();
let rightNow = new Date();

try{
try {
const result = await axios({
method: "POST",
url: `${process.env.NEXT_PUBLIC_CAPTCHA_URL}`,
Expand All @@ -73,22 +72,34 @@ export default function Login(props) {
token: captchaToken,
},
});
} catch (err) {
addToast('Incorect Captcha/ Captcha कोड गलत है!', { appearance: "error" });
} catch (err) {
addToast("Incorect Captcha/ Captcha कोड गलत है!", {
appearance: "error",
});
setRefreshToken(rightNow.toISOString());
return false;
}

const parsedBase64Key = CryptoJS.enc.Base64.parse(process.env.NEXT_PUBLIC_BASE64_KEY);
let encryptedUsername = CryptoJS.AES.encrypt(input.username, parsedBase64Key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
})
encryptedUsername = encryptedUsername.toString();
const encryptedPassword = CryptoJS.AES.encrypt(input.password, parsedBase64Key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
}).toString();
const parsedBase64Key = CryptoJS.enc.Base64.parse(
process.env.NEXT_PUBLIC_BASE64_KEY
);
let encryptedUsername = CryptoJS.AES.encrypt(
input.username,
parsedBase64Key,
{
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
}
);
encryptedUsername = encryptedUsername.toString();
const encryptedPassword = CryptoJS.AES.encrypt(
input.password,
parsedBase64Key,
{
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
}
).toString();

const { error, url } = await signIn("fusionauth", {
loginId: encryptedUsername,
Expand Down
26 changes: 16 additions & 10 deletions portal/components/react-admin/base/resources/teachers.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ export const TeacherEdit = (props) => {
const response = await sendSMS(template, templateId, data.user.mobile_phone);
if (response?.success) notify(response.success, "info");
else if (response?.error) notify(response.error, "warning");
redirect("list", props.basePath, data.id, data);
}
redirect("list", props.basePath, data.id, data);
}
};

Expand Down Expand Up @@ -284,20 +284,26 @@ export const TeacherEdit = (props) => {
</div>

<span className={classes.heading}>Update Status</span>
<div className={`${classes.grid}`}>
{/* <SelectInput
source="delivery_status"
label="Grades Taught"
/>
<SelectInput
source="delivery_status"
label="Subjects Taught"
/> */}
<div className={`${classes.grid} ${classes.fullWidthGrid}`}>
<SelectInput
source="account_status"
label="Account Status"
choices={config.statusChoices}
/>
<FormDataConsumer>
{({ formData, ...rest }) =>
formData?.account_status === "DEACTIVATED" ? (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this be picked from the config file?

<>
<h2 className={classes.heading}>Reason</h2>
<div className={classes.grid}>
<TextInput label="Reason" source="deactivation_reason" />
</div>
</>
) : (
<></>
)
}
</FormDataConsumer>
</div>
<p className={classes.warning}>
Changing status will trigger an SMS notification to the teacher upon
Expand Down
38 changes: 25 additions & 13 deletions portal/pages/api/auth/[...nextauth].js
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
import NextAuth from "next-auth";
import Providers from "next-auth/providers";
import axios from "axios";
const CryptoJS = require('crypto-js');
const CryptoJS = require("crypto-js");

const fusionAuthLogin = async (path, credentials) => {
const base64Key = CryptoJS.enc.Base64.parse(process.env.NEXT_PUBLIC_BASE64_KEY);
let byteEncodedUsername = CryptoJS.AES.decrypt(credentials.loginId, base64Key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
const base64Key = CryptoJS.enc.Base64.parse(
process.env.NEXT_PUBLIC_BASE64_KEY
);
let byteEncodedUsername = CryptoJS.AES.decrypt(
credentials.loginId,
base64Key,
{
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
}
);
let decryptedLoginId = byteEncodedUsername.toString(CryptoJS.enc.Utf8);

let byteEncodedPassword = CryptoJS.AES.decrypt(credentials.password, base64Key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
let byteEncodedPassword = CryptoJS.AES.decrypt(
credentials.password,
base64Key,
{
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
}
);
let decryptedPassword = byteEncodedPassword.toString(CryptoJS.enc.Utf8);

const options = {
headers: { Authorization: process.env.FUSIONAUTH_API_KEY },
};
Expand Down Expand Up @@ -45,7 +55,9 @@ export default NextAuth({
process.env.FUSIONAUTH_DOMAIN,
credentials
);
if (response) {
if (response.data?.responseCode == "FAILURE") {
throw new Error(response.data?.params?.errMsg);
} else {
return response.data?.result?.data?.user;
}
} catch (err) {
Expand Down Expand Up @@ -81,4 +93,4 @@ export default NextAuth({
return session;
},
},
});
});