Skip to content
Merged
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
1 change: 0 additions & 1 deletion src/IsaacAppTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
| { type: ACTION_TYPE.CONSTANTS_SEGUE_ENVIRONMENT_RESPONSE_SUCCESS; segueEnvironment: string }
| { type: ACTION_TYPE.NOTIFICATIONS_REQUEST }
| { type: ACTION_TYPE.NOTIFICATIONS_RESPONSE_FAILURE }
| { type: ACTION_TYPE.NOTIFICATIONS_RESPONSE_SUCCESS; notifications: any[] }

Check warning on line 189 in src/IsaacAppTypes.tsx

View workflow job for this annotation

GitHub Actions / Build, Lint and Test

Unexpected any. Specify a different type
| { type: ACTION_TYPE.DOCUMENT_REQUEST; documentType: DOCUMENT_TYPE; documentId: string }
| { type: ACTION_TYPE.DOCUMENT_RESPONSE_SUCCESS; doc: ApiTypes.ContentDTO }
| { type: ACTION_TYPE.DOCUMENT_RESPONSE_FAILURE }
Expand Down Expand Up @@ -292,7 +292,7 @@
}
| { type: ACTION_TYPE.EVENT_BOOKINGS_FOR_ALL_GROUPS_RESPONSE_FAILURE }
| { type: ACTION_TYPE.EVENT_BOOKING_CSV_REQUEST }
| { type: ACTION_TYPE.EVENT_BOOKING_CSV_RESPONSE_SUCCESS; eventBookingCSV: any }

Check warning on line 295 in src/IsaacAppTypes.tsx

View workflow job for this annotation

GitHub Actions / Build, Lint and Test

Unexpected any. Specify a different type
| { type: ACTION_TYPE.EVENT_BOOKING_CSV_RESPONSE_FAILURE }
| { type: ACTION_TYPE.EVENT_BOOKING_REQUEST }
| { type: ACTION_TYPE.EVENT_BOOKING_RESPONSE_SUCCESS }
Expand Down Expand Up @@ -507,8 +507,8 @@
closeLabelOverride?: string;
size?: string;
title?: string;
body: any;

Check warning on line 510 in src/IsaacAppTypes.tsx

View workflow job for this annotation

GitHub Actions / Build, Lint and Test

Unexpected any. Specify a different type
buttons?: any[];

Check warning on line 511 in src/IsaacAppTypes.tsx

View workflow job for this annotation

GitHub Actions / Build, Lint and Test

Unexpected any. Specify a different type
overflowVisible?: boolean;
isCloseable?: boolean;
}
Expand Down Expand Up @@ -553,12 +553,12 @@
}

export interface AdminStatsResponse {
activeUsersOverPrevious: any;

Check warning on line 556 in src/IsaacAppTypes.tsx

View workflow job for this annotation

GitHub Actions / Build, Lint and Test

Unexpected any. Specify a different type
answeredQuestionEvents: number;
answeringUsersOverPrevious: any;

Check warning on line 558 in src/IsaacAppTypes.tsx

View workflow job for this annotation

GitHub Actions / Build, Lint and Test

Unexpected any. Specify a different type
userGenders: any;

Check warning on line 559 in src/IsaacAppTypes.tsx

View workflow job for this annotation

GitHub Actions / Build, Lint and Test

Unexpected any. Specify a different type
userRoles: any;

Check warning on line 560 in src/IsaacAppTypes.tsx

View workflow job for this annotation

GitHub Actions / Build, Lint and Test

Unexpected any. Specify a different type
userSchoolInfo: any;

Check warning on line 561 in src/IsaacAppTypes.tsx

View workflow job for this annotation

GitHub Actions / Build, Lint and Test

Unexpected any. Specify a different type
viewQuestionEvents: number;
viewConceptEvents: number;
}
Expand Down Expand Up @@ -705,7 +705,6 @@
export interface CredentialsAuthDTO {
email: string;
password: string;
rememberMe: boolean;
}

export interface PaddedCredentialsAuthDTO extends CredentialsAuthDTO {
Expand All @@ -716,7 +715,7 @@
calc_time: number;
crack_times_display: { [key: string]: string };
crack_times_seconds: { [key: string]: number };
feedback: { [key: string]: any };

Check warning on line 718 in src/IsaacAppTypes.tsx

View workflow job for this annotation

GitHub Actions / Build, Lint and Test

Unexpected any. Specify a different type
guesses: number;
guesses_log10: number;
password: string;
Expand Down
11 changes: 5 additions & 6 deletions src/app/components/elements/modals/LoginOrSignUpModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from "react";
import { Button, Col, CustomInput, Form, Row } from "reactstrap";
import { Button, Col, Form, Row } from "reactstrap";
import { closeActiveModal, selectors, store, useAppDispatch, useAppSelector } from "../../../state";
import { useLocation } from "react-router-dom";
import {
Expand All @@ -20,14 +20,13 @@ const LoginOrSignUpBody = () => {

const { loginFunctions, setStateFunctions, loginValues } = useLoginLogic();
const { attemptLogIn, signUp, validateAndLogIn } = loginFunctions;
const { setEmail, setPassword, setRememberMe, setPasswordResetAttempted } = setStateFunctions;
const { setEmail, setPassword, setPasswordResetAttempted } = setStateFunctions;
const {
email,
totpChallengePending,
errorMessage,
logInAttempted,
passwordResetAttempted,
rememberMe,
isValidEmail,
isValidPassword,
} = loginValues;
Expand Down Expand Up @@ -84,7 +83,7 @@ const LoginOrSignUpBody = () => {
)}
<Form name="login" onSubmit={validateAndLogIn} noValidate>
{totpChallengePending ? (
<TFAInput rememberMe={rememberMe} />
<TFAInput />
) : (
<>
<EmailPasswordInputs
Expand All @@ -105,13 +104,13 @@ const LoginOrSignUpBody = () => {
small
/>

<CustomInput
{/* <CustomInput
id="login-remember-me"
className={"mb-2"}
type="checkbox"
label="Remember me"
onChange={(e) => setRememberMe(e.target.checked)}
/>
/> */}
<div className="text-right">
<h4 role="alert" className="text-danger text-right mb-0">
{errorMessage}
Expand Down
27 changes: 6 additions & 21 deletions src/app/components/pages/LogIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
CardBody,
Col,
Container,
CustomInput,
Form,
FormFeedback,
FormGroup,
Expand All @@ -42,7 +41,6 @@ export const useLoginLogic = () => {
const errorMessage = useAppSelector(selectors.error.general);
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [rememberMe, setRememberMe] = useState<boolean>(false);
const [logInAttempted, setLoginAttempted] = useState(false);

const isValidEmail = email.length > 0 && email.includes("@");
Expand All @@ -54,7 +52,7 @@ export const useLoginLogic = () => {
event.preventDefault();
// Password check here will have to remain on old requirements as existing accounts will not be able to log in otherwise
if (password.length > 6 && isValidEmail) {
dispatch(logInUser("SEGUE", { email: email, password: password, rememberMe: rememberMe }));
dispatch(logInUser("SEGUE", { email: email, password: password }));
}
};

Expand All @@ -69,14 +67,13 @@ export const useLoginLogic = () => {

return {
loginFunctions: { attemptLogIn, signUp, validateAndLogIn },
setStateFunctions: { setEmail, setPassword, setRememberMe, setPasswordResetAttempted },
setStateFunctions: { setEmail, setPassword, setPasswordResetAttempted },
loginValues: {
email,
totpChallengePending,
errorMessage,
logInAttempted,
passwordResetAttempted,
rememberMe,
isValidEmail,
isValidPassword,
},
Expand All @@ -99,10 +96,7 @@ export const GoogleSignInButton = () => {
};

// Handles display and logic of the two-factor authentication form (usually shown after the first login step)
export const TFAInput = React.forwardRef(function TFAForm(
{ rememberMe }: { rememberMe: boolean },
ref: React.Ref<HTMLHeadingElement>,
) {
export const TFAInput = React.forwardRef<HTMLHeadingElement>(function TFAForm(_props, ref) {
const dispatch = useAppDispatch();
const [mfaVerificationCode, setMfaVerificationCode] = useState("");

Expand Down Expand Up @@ -139,7 +133,7 @@ export const TFAInput = React.forwardRef(function TFAForm(
disabled={isNaN(Number(mfaVerificationCode))}
onClick={(event) => {
event.preventDefault();
if (mfaVerificationCode) dispatch(submitTotpChallengeResponse(mfaVerificationCode, rememberMe));
if (mfaVerificationCode) dispatch(submitTotpChallengeResponse(mfaVerificationCode));
}}
/>
</FormGroup>
Expand Down Expand Up @@ -255,14 +249,13 @@ export const LogIn = () => {

const { loginFunctions, setStateFunctions, loginValues } = useLoginLogic();
const { attemptLogIn, signUp, validateAndLogIn } = loginFunctions;
const { setEmail, setPassword, setRememberMe, setPasswordResetAttempted } = setStateFunctions;
const { setEmail, setPassword, setPasswordResetAttempted } = setStateFunctions;
const {
email,
totpChallengePending,
errorMessage,
logInAttempted,
passwordResetAttempted,
rememberMe,
isValidEmail,
isValidPassword,
} = loginValues;
Expand Down Expand Up @@ -311,7 +304,7 @@ export const LogIn = () => {
Log in or sign up:
</h2>
{totpChallengePending ? (
<TFAInput ref={subHeadingRef} rememberMe={rememberMe} />
<TFAInput ref={subHeadingRef} />
) : (
<React.Fragment>
<EmailPasswordInputs
Expand All @@ -326,14 +319,6 @@ export const LogIn = () => {
/>

<Row className="mb-4">
<Col className={"col-5 mt-1"}>
<CustomInput
id="login-remember-me"
type="checkbox"
label="Remember me"
onChange={(e) => setRememberMe(e.target.checked)}
/>
</Col>
<Col className="text-right">
<div>
<h4 role="alert" className="text-danger text-right mb-0">
Expand Down
4 changes: 2 additions & 2 deletions src/app/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ export const api = {
): AxiosPromise<ApiTypes.RegisteredUserDTO> => {
return endpoint.post(`/auth/${provider}/authenticate`, securePadCredentials(credentials));
},
mfaCompleteLogin: (mfaVerificationCode: string, rememberMe: boolean): AxiosPromise => {
return endpoint.post(`/auth/mfa/challenge`, { mfaVerificationCode: mfaVerificationCode, rememberMe });
mfaCompleteLogin: (mfaVerificationCode: string): AxiosPromise => {
return endpoint.post(`/auth/mfa/challenge`, { mfaVerificationCode: mfaVerificationCode });
},
getCurrentUserAuthSettings: (): AxiosPromise<ApiTypes.UserAuthenticationSettingsDTO> => {
return endpoint.get(`/auth/user_authentication_settings`);
Expand Down
29 changes: 14 additions & 15 deletions src/app/state/actions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,20 @@ export const unlinkAccount = (provider: AuthenticationProvider) => async (dispat
}
};

export const submitTotpChallengeResponse =
(mfaVerificationCode: string, rememberMe: boolean) => async (dispatch: Dispatch<Action>) => {
dispatch({ type: ACTION_TYPE.USER_AUTH_MFA_CHALLENGE_REQUEST });
try {
const result = await api.authentication.mfaCompleteLogin(mfaVerificationCode, rememberMe);
// Request user preferences, as we do in the requestCurrentUser action:
await Promise.all([dispatch(getUserAuthSettings() as any), dispatch(getUserPreferences() as any)]);
dispatch({ type: ACTION_TYPE.USER_AUTH_MFA_CHALLENGE_SUCCESS });
dispatch({ type: ACTION_TYPE.USER_LOG_IN_RESPONSE_SUCCESS, user: result.data });
history.replace(persistence.pop(KEY.AFTER_AUTH_PATH) || "/");
} catch (e: any) {
dispatch({ type: ACTION_TYPE.USER_AUTH_MFA_CHALLENGE_FAILURE, errorMessage: extractMessage(e) });
dispatch(showAxiosErrorToastIfNeeded("Error with verification code.", e));
}
};
export const submitTotpChallengeResponse = (mfaVerificationCode: string) => async (dispatch: Dispatch<Action>) => {
dispatch({ type: ACTION_TYPE.USER_AUTH_MFA_CHALLENGE_REQUEST });
try {
const result = await api.authentication.mfaCompleteLogin(mfaVerificationCode);
// Request user preferences, as we do in the requestCurrentUser action:
await Promise.all([dispatch(getUserAuthSettings() as any), dispatch(getUserPreferences() as any)]);
dispatch({ type: ACTION_TYPE.USER_AUTH_MFA_CHALLENGE_SUCCESS });
dispatch({ type: ACTION_TYPE.USER_LOG_IN_RESPONSE_SUCCESS, user: result.data });
history.replace(persistence.pop(KEY.AFTER_AUTH_PATH) || "/");
} catch (e: any) {
dispatch({ type: ACTION_TYPE.USER_AUTH_MFA_CHALLENGE_FAILURE, errorMessage: extractMessage(e) });
dispatch(showAxiosErrorToastIfNeeded("Error with verification code.", e));
}
};

export const getUserPreferences = () => async (dispatch: Dispatch<Action>) => {
dispatch({ type: ACTION_TYPE.USER_PREFERENCES_REQUEST });
Expand Down
Loading