Skip to content

Commit

Permalink
Created new RSC Create Account component.
Browse files Browse the repository at this point in the history
Created new RSC Register Form component.
Created new RSC Register Form Style component.
Reverted Register Form component.
Updated App.tsx to include new RSC components and routes.
Updated app.ts to include new register route.
Updated users.ts with amended RSC Register end point.
  • Loading branch information
hawkishpolicy committed Apr 2, 2024
1 parent 1faea44 commit 3a8712e
Show file tree
Hide file tree
Showing 10 changed files with 9,296 additions and 8,637 deletions.
13,576 changes: 6,788 additions & 6,788 deletions backend/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/src/api/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ app.get('/', handlerToExpress(healthcheck));
app.post('/auth/login', handlerToExpress(auth.login));
app.post('/auth/callback', handlerToExpress(auth.callback));
app.post('/users/register', handlerToExpress(users.register));
app.post('/readysetcyber/register', handlerToExpress(users.RSCRegister));

const checkUserLoggedIn = async (req, res, next) => {
req.requestContext = {
Expand Down Expand Up @@ -276,7 +277,6 @@ app.use(
const authenticatedNoTermsRoute = express.Router();
authenticatedNoTermsRoute.use(checkUserLoggedIn);
authenticatedNoTermsRoute.get('/users/me', handlerToExpress(users.me));
// authenticatedNoTermsRoute.post('/users/register', handlerToExpress(users.register));
authenticatedNoTermsRoute.post(
'/users/me/acceptTerms',
handlerToExpress(users.acceptTerms)
Expand Down
99 changes: 99 additions & 0 deletions backend/src/api/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ class UpdateUser {
role: string;
}

// class NewRSCUser {
// @IsString()
// firstName: string;

// @IsString()
// lastName: string;

// @IsEmail()
// email: string;

// @IsEnum(UserType)
// userType: UserType;
// }

/**
* @swagger
*
Expand Down Expand Up @@ -254,6 +268,34 @@ If you encounter any difficulties, please feel free to reply to this email (or s
);
};

const sendRSCInviteEmail = async (email: string) => {
const staging = process.env.NODE_ENV !== 'production';

await sendEmail(
email,
'ReadySetCyber Dashboard Invitation',
`Hi there,
You've been invited to join ReadySetCyber Dashboard. To accept the invitation and start using your Dashboard, sign on at ${
process.env.FRONTEND_DOMAIN
}/readysetcyber/create-account.
Crossfeed access instructions:
1. Visit ${process.env.FRONTEND_DOMAIN}/readysetcyber/create-account.
2. Select "Create Account."
3. Enter your email address and a new password for Crossfeed.
4. A confirmation code will be sent to your email. Enter this code when you receive it.
5. You will be prompted to enable MFA. Scan the QR code with an authenticator app on your phone, such as Microsoft Authenticator. Enter the MFA code you see after scanning.
6. After configuring your account, you will be redirected to Crossfeed.
For more information on using Crossfeed, view the Crossfeed user guide at https://docs.crossfeed.cyber.dhs.gov/user-guide/quickstart/.
If you encounter any difficulties, please feel free to reply to this email (or send an email to ${
process.env.CROSSFEED_SUPPORT_EMAIL_REPLYTO
}).`
);
};
/**
* @swagger
*
Expand Down Expand Up @@ -892,3 +934,60 @@ export const updateV2 = wrapHandler(async (event) => {
}
return NotFound;
});

/**
* @swagger
*
* /readysetcyber/register:
* post:
* description: New ReadySetCyber user registration.
* tags:
* - RSCUsers
*/
export const RSCRegister = wrapHandler(async (event) => {
const body = await validateBody(NewUser, event.body);
const newRSCUser = {
firstName: body.firstName,
lastName: body.lastName,
email: body.email.toLowerCase(),
userType: UserType.READY_SET_CYBER,
invitePending: true
};
console.log(JSON.stringify(newRSCUser));

await connectToDatabase();


// Check if user already exists
let user = await User.findOne({
email: newRSCUser.email
});
if (user) {
console.log('User already exists.');
return {
statusCode: 422,
body: 'User email already exists. Registration failed.'
};
}

// Create if user does not exist
if (!user) {
user = await User.create(
newRSCUser
);
await User.save(user);
console.log(JSON.stringify(user));
// Send email notification
if (process.env.IS_LOCAL!) {
console.log('Cannot send invite email while running on local.');
} else {
await sendRSCInviteEmail(user.email);
}
}

const savedUser = await User.findOne(user.id);
return {
statusCode: 200,
body: JSON.stringify(savedUser)
};
})
12 changes: 10 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { Authenticator } from '@aws-amplify/ui-react';
import { RSCDashboard } from 'components/ReadySetCyber/RSCDashboard';
import { RSCDetail } from 'components/ReadySetCyber/RSCDetail';
import { RSCLogin } from 'components/ReadySetCyber/RSCLogin';
import { RSCAuthLoginCreate } from 'components/ReadySetCyber/RSCAuthLoginCreate';

API.configure({
endpoints: [
Expand Down Expand Up @@ -214,22 +215,29 @@ const App: React.FC = () => (
<RouteGuard
exact
path="/readysetcyber"
render={() => <Redirect to="/readysetcyber/dashboard" />}
unauth={RSCLogin}
component={RSCDashboard}
/>
<RouteGuard
exact
path="/readysetcyber/create-account"
render={() => <Redirect to="/readysetcyber/dashboard" />}
unauth={RSCAuthLoginCreate}
component={RSCDashboard}
/>
<RouteGuard
exact
path="/readysetcyber/dashboard"
component={RSCDashboard}
render={() => <Redirect to="/readysetcyber/dashboard" />}
permissions={['standard', 'globalView', 'regionalAdmin']}
permissions={['readySetCyber']}
unauth={RSCLogin}
/>
<RouteGuard
path="/readysetcyber/result/:id"
component={RSCDetail}
permissions={['standard', 'globalView', 'regionalAdmin']}
permissions={['readySetCyber']}
unauth={RSCLogin}
/>
</Switch>
Expand Down
Loading

0 comments on commit 3a8712e

Please sign in to comment.