repo_name stringlengths 5 122 | path stringlengths 3 232 | text stringlengths 6 1.05M |
|---|---|---|
lauslim12/attendance | web/components/Input/SelectInput.tsx | import {
FormControl,
FormHelperText,
FormLabel,
Select,
} from '@chakra-ui/react';
import type { Dispatch, SetStateAction } from 'react';
import { memo } from 'react';
/**
* Props.
*/
type Props = {
label: string;
value: string;
setValue: Dispatch<SetStateAction<string>>;
options: string[];
helper... |
lauslim12/attendance | api/modules/auth/validation.ts | import joi from '../../util/joi';
/**
* Special auth validations to sanitize and analyze request bodies and parameters.
*/
const AuthValidation = {
// POST /api/v1/auth/forgot-password
forgotPassword: {
body: joi.object().keys({
email: joi.string().trim().email().lowercase().required(),
username:... |
lauslim12/attendance | web/components/AuthRoute.tsx | import { useRouter } from 'next/router';
import type { ReactNode } from 'react';
import { memo, useEffect } from 'react';
import { useMe } from '../utils/hooks';
import routes from '../utils/routes';
import Spinner from './Spinner';
/**
* Props.
*/
type Props = {
children: ReactNode;
authRoutes: string[];
};
/... |
lauslim12/attendance | web/components/Pages/Profile/Attendancebox.tsx | import { Grid, Heading, Text, VStack } from '@chakra-ui/react';
import { memo } from 'react';
import type { Attendance } from '../../../utils/types';
import AttendanceCard from '../../Card/AttendanceCard';
/**
* Attendance box to show attendances.
*
* @param params - Props.
* @returns React functional component.
... |
lauslim12/attendance | api/modules/middleware/rate-limit.ts | <reponame>lauslim12/attendance
import type { NextFunction, Request, Response } from 'express';
import rateLimiter from 'express-rate-limit';
import RedisStore from 'rate-limit-redis';
import redis from '../../infra/redis';
import AppError from '../../util/app-error';
/**
* Prepares and configures a rate limiter to b... |
lauslim12/attendance | api/modules/auth/handler.ts | import { Router } from 'express';
import asyncHandler from '../../util/async-handler';
import validate from '../../util/validate';
import bodyParser from '../middleware/body-parser';
import hasJWT from '../middleware/has-jwt';
import hasSession from '../middleware/has-session';
import rateLimit from '../middleware/rat... |
lauslim12/attendance | web/components/Form/index.tsx | import { Heading, Text, useColorModeValue, VStack } from '@chakra-ui/react';
import type { FormEvent, ReactNode } from 'react';
import { memo } from 'react';
import ErrorAlert from './ErrorAlert';
/**
* Props.
*/
type Props = {
children: ReactNode;
title: string;
description: string;
error: string;
onSubm... |
lauslim12/attendance | api/util/joi.ts | <gh_stars>1-10
import defaultJoi from 'joi';
/**
* Default JOI for our application.
*/
const joi = defaultJoi.defaults((schema) =>
schema.options({
abortEarly: true,
convert: true,
stripUnknown: false,
errors: { escapeHtml: true },
})
);
export default joi;
|
lauslim12/attendance | web/components/MFAButton.tsx | <filename>web/components/MFAButton.tsx
import { Button } from '@chakra-ui/react';
import dynamic from 'next/dynamic';
import { memo, useState } from 'react';
import { FaBarcode, FaKey } from 'react-icons/fa';
import type { User } from '../utils/types';
/**
* Dynamic import.
*/
const OTPModal = dynamic(() => import(... |
lauslim12/attendance | web/components/Overlay/OTPModal.tsx | import {
Alert,
AlertDescription,
AlertIcon,
Button,
HStack,
Modal,
ModalBody,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
PinInput,
PinInputField,
Stack,
Text,
useToast,
VStack,
} from '@chakra-ui/react';
import { memo, useEffect, useState } from 'react';
import { FaGoogle, ... |
lauslim12/attendance | web/components/Form/SubmitButton.tsx | <gh_stars>1-10
import type { ThemingProps } from '@chakra-ui/react';
import { Button } from '@chakra-ui/react';
import { memo } from 'react';
import type { IconType } from 'react-icons';
/**
* Props.
*/
type Props = {
Icon: IconType;
inputs: string[];
isLoading: boolean;
text: string;
colorScheme?: Theming... |
lauslim12/attendance | api/modules/middleware/busy-handler.ts | import type { NextFunction, Request, Response } from 'express';
import toobusy from 'toobusy-js';
import AppError from '../../util/app-error';
/**
* Checks whether the server is too busy or not. If the server is busy
* handling a lot of requests, send back `503 Service Unavailable`.
*
* @returns Middleware functi... |
lauslim12/attendance | api/util/device-id.ts | import DeviceDetector from 'device-detector-js';
import type { Request } from 'express';
import { getClientIp } from 'request-ip';
/**
* Uses the 'Request' object of Express to parse the user's device information and their IP.
*
* @param req - Express.js's request object.
* @returns A user's device information and... |
lauslim12/attendance | web/pages/login.tsx | import { memo } from 'react';
import Layout from '../components/Layout';
import NotAuthRoute from '../components/NotAuthRoute';
import LoginForm from '../components/Pages/Login/LoginForm';
/**
* Login screen for the website.
*
* @returns React functional component.
*/
const Login = () => (
<NotAuthRoute>
<L... |
lauslim12/attendance | api/modules/middleware/slow-down.ts | import expressSlowDown from 'express-slow-down';
import RedisStore from 'rate-limit-redis';
import redis from '../../infra/redis';
/**
* Creates an instance of `express-slow-down` with Redis to be used globally.
*
* @param delayAfter - Number of requests before being throttled.
* @returns Instance of `express-slo... |
lauslim12/attendance | api/cli/otp-speed.ts | /* eslint-disable @typescript-eslint/no-explicit-any */
import fs from 'node:fs';
import path from 'node:path';
/**
* Get data by doing (your logs have to be populated):
* - `cd attendance/api/dist/logs`.
* - `grep "HTTP PUT /api/v1/auth/otp" traffic.log`
* - `touch file.json`
* - Copy the output to the `file.jso... |
lauslim12/attendance | api/modules/middleware/has-jwt.ts | import type { NextFunction, Request, Response } from 'express';
import AppError from '../../util/app-error';
import { extractJWT, verifyToken } from '../../util/jwt';
import CacheService from '../cache/service';
/**
* Validates whether a user is authorized/authenticated or not (via JWT).
* Checks whether the user's... |
lauslim12/attendance | web/components/Layout/Head.tsx | <reponame>lauslim12/attendance<filename>web/components/Layout/Head.tsx
import NextHead from 'next/head';
import { memo } from 'react';
/**
* Sets the HTML Head component for a single Layout.
*
* @param params - Props.
* @returns Next's document head component.
*/
const Head = ({ title }: { title?: string[] }) => ... |
lauslim12/attendance | api/modules/user/validation.ts | <gh_stars>1-10
import joi from '../../util/joi';
/**
* Special user validations to sanitize and analyze request bodies and parameters.
*/
const UserValidation = {
// POST /api/v1/users
createUser: {
body: joi.object().keys({
username: joi.string().normalize().trim().required().max(25),
email: joi... |
lauslim12/attendance | web/components/Layout/Footer.tsx | import { HStack, IconButton, Link, Spacer } from '@chakra-ui/react';
import { memo } from 'react';
import { FaGithub } from 'react-icons/fa';
/**
* The whole part of the Footer in the web application.
*
* @returns React functional component.
*/
const Footer = () => (
<HStack as="footer" p={4} spacing={2} fontSiz... |
lauslim12/attendance | web/pages/verify-email.tsx | <filename>web/pages/verify-email.tsx
import { Button, Heading, VStack } from '@chakra-ui/react';
import NextLink from 'next/link';
import { useRouter } from 'next/router';
import { memo, useEffect, useState } from 'react';
import { FaHome } from 'react-icons/fa';
import Layout from '../components/Layout';
import Spinn... |
lauslim12/attendance | api/modules/attendance/validation.ts | import joi from '../../util/joi';
/**
* Special attendance validations to sanitize and analyze request bodies and parameters.
*/
const AttendanceValidation = {
// GET /api/v1/attendances and/or /api/v1/users/{id}/attendances
getAttendances: {
params: joi.object().keys({
id: joi.string().guid({ version:... |
lauslim12/attendance | api/core/util/number-to-buf.ts | <gh_stars>1-10
/**
* Transforms a number to 'byte' array.
* Remember that 'byte' array is just a 'hexadecimal number split by whitespaces if console logged'.
*
* Algorithm:
* 1. Represent our input as 8-bytes array, can be done with ArrayBuffer.
* 2. Buffer starts from the right, so we read backwards.
* 3. Will ... |
lauslim12/attendance | api/cli/seed-data.ts | <filename>api/cli/seed-data.ts
import { Prisma, PrismaClient } from '@prisma/client';
import config from '../config';
import { generateTOTP } from '../core/rfc6238';
import { hashPassword } from '../util/passwords';
const prisma = new PrismaClient();
/**
* All sample users for development purposes.
*/
async functi... |
lauslim12/attendance | web/pages/register.tsx | import dynamic from 'next/dynamic';
import { memo, useRef, useState } from 'react';
import Layout from '../components/Layout';
import RegisterForm from '../components/Pages/Register/RegisterForm';
/**
* Dynamic import.
*/
const QRDialog = dynamic(() => import('../components/Overlay/QRDialog'));
/**
* Registration... |
lauslim12/attendance | api/modules/attendance/controller.ts | import type { NextFunction, Request, Response } from 'express';
import AppError from '../../util/app-error';
import getDeviceID from '../../util/device-id';
import sendResponse from '../../util/send-response';
import UserService from '../user/service';
import AttendanceService from './service';
/**
* Attendance cont... |
lauslim12/attendance | web/components/Pages/Login/LoginForm.tsx | import { Checkbox, Text, useToast } from '@chakra-ui/react';
import { useRouter } from 'next/router';
import type { FormEvent } from 'react';
import { memo, useState } from 'react';
import { FaKey } from 'react-icons/fa';
import { useStatusAndUser } from '../../../utils/hooks';
import axios from '../../../utils/http';... |
lauslim12/attendance | api/modules/session/validation.ts | import joi from '../../util/joi';
/**
* Special session validations to sanitize and analyze request bodies and parameters.
*/
const SessionValidation = {
// DELETE /api/v1/sessions/me/:id
deleteUserSession: {
params: joi.object().keys({
id: joi.string().required(),
}),
},
// DELETE /api/v1/ses... |
lauslim12/attendance | web/pages/_document.tsx | import Document, {
DocumentContext,
Head,
Html,
Main,
NextScript,
} from 'next/document';
/**
* AppDocument is used to set up initial color mode and to load Google Fonts.
*/
class AppDocument extends Document {
static async getInitialProps(ctx: DocumentContext) {
const initialProps = await Document.g... |
lauslim12/attendance | web/components/Layout/index.tsx | <filename>web/components/Layout/index.tsx
import { chakra, Flex } from '@chakra-ui/react';
import { memo, ReactNode } from 'react';
import Footer from './Footer';
import Head from './Head';
import Header from './Header';
/**
* Props typing that will handle below component's hydration process.
*/
type Props = {
ch... |
lauslim12/attendance | web/pages/reset-password.tsx | import { useRouter } from 'next/router';
import { memo } from 'react';
import Layout from '../components/Layout';
import NotAuthRoute from '../components/NotAuthRoute';
import ForgotPasswordForm from '../components/Pages/ResetPassword/ForgotPasswordForm';
import ResetPasswordForm from '../components/Pages/ResetPasswor... |
lauslim12/attendance | web/components/Card/SessionCard.tsx | <reponame>lauslim12/attendance
import {
Button,
Spacer,
Stack,
Text,
useColorModeValue,
useToast,
VStack,
} from '@chakra-ui/react';
import { useRouter } from 'next/router';
import { memo, useState } from 'react';
import { FaFire } from 'react-icons/fa';
import { useMe, useStatusAndUser } from '../../uti... |
lauslim12/attendance | api/util/jwt.ts | import type { Request } from 'express';
import type { JWTHeaderParameters, JWTPayload, JWTVerifyOptions } from 'jose';
import { importPKCS8, importSPKI, jwtVerify, SignJWT } from 'jose';
import config from '../config';
import isHTTPS from './is-https';
/**
* Signs a JWT token with EdDSA algorithm, will transform the... |
lauslim12/attendance | api/modules/user/service.ts | <filename>api/modules/user/service.ts
import { Prisma } from '@prisma/client';
import { nanoid } from 'nanoid/async';
import { generateDefaultTOTP } from '../../core/rfc6238';
import prisma from '../../infra/prisma';
import { hashPassword } from '../../util/passwords';
/**
* Almost all user operations return these a... |
lauslim12/attendance | api/index.ts | import type { Server } from 'http';
import toobusy from 'toobusy-js';
import config from './config';
import bull from './infra/bull';
import loadExpress from './infra/express';
import prisma from './infra/prisma';
import redis from './infra/redis';
import CacheService from './modules/cache/service';
import Email from ... |
lauslim12/attendance | api/util/logger.ts | <gh_stars>1-10
import path from 'path';
import winston from 'winston';
/**
* Convenient logger for almost anything.
*/
const logger = winston.createLogger({
// Log if level is 'info' or lower.
level: 'info',
// Logger format.
format: winston.format.combine(
winston.format.timestamp(),
winston.format... |
lauslim12/attendance | api/config/index.ts | <filename>api/config/index.ts
import dotenv from 'dotenv';
import { get } from 'env-var';
import path from 'path';
// Allow environment variables from a file for development.
dotenv.config({ path: path.join(__dirname, '..', '.env') });
// Helper constant to check whether the server is in production mode or not.
const... |
lauslim12/attendance | api/modules/cache/repository.ts | <filename>api/modules/cache/repository.ts
import type { SessionData } from 'express-session';
import redis from '../../infra/redis';
/**
* Session type from Express.js, plus the session ID for easier
* front-end processing.
*/
type Session = SessionData & { sid: string };
/**
* Fetches all related data that matc... |
lauslim12/attendance | web/components/MainHeading.tsx | <reponame>lauslim12/attendance
import type { As, SpaceProps, TypographyProps } from '@chakra-ui/react';
import { Heading, useColorModeValue } from '@chakra-ui/react';
import { memo } from 'react';
/**
* Props.
*/
type Props = {
text: string;
as?: As;
fontSize?: TypographyProps['fontSize'];
letterSpacing?: Ty... |
lauslim12/attendance | api/modules/session/handler.ts | <gh_stars>1-10
import { Router } from 'express';
import asyncHandler from '../../util/async-handler';
import validate from '../../util/validate';
import getMe from '../middleware/get-me';
import hasRole from '../middleware/has-role';
import hasSession from '../middleware/has-session';
import rateLimit from '../middlew... |
lauslim12/attendance | api/util/app-error.ts | import { getReasonPhrase } from 'http-status-codes';
import { nanoid } from 'nanoid';
/**
* Custom error class for operational errors (JSON:API standards).
*/
class AppError extends Error {
/**
* Unique error identifier.
*/
public id: string;
/**
* Response phrase (e.g. Internal Server Error).
*/
... |
lauslim12/attendance | api/infra/bull.ts | import type { ConnectionOptions, Job } from 'bullmq';
import { Queue, Worker } from 'bullmq';
import config from '../config';
import logger from '../util/logger';
/**
* Data type for our queue data.
*/
type BullData = {
task: Promise<void>;
};
/**
* Redis connection for the Bull Queue.
*/
const connection: Con... |
lauslim12/attendance | web/components/Pages/Home/Greetings.tsx | import { Text } from '@chakra-ui/react';
import { memo } from 'react';
/**
* Greetings component.
*
* @param params - Full name as prop.
* @returns Greetings component.
*/
const Greetings = ({ fullName }: { fullName: string }) => (
<Text fontSize="lg" textAlign="center" fontWeight="bold">
Welcome back, {ful... |
lauslim12/attendance | api/modules/health/handler.ts | <filename>api/modules/health/handler.ts
import type { Request, Response } from 'express';
import { Router } from 'express';
import sendResponse from '../../util/send-response';
/**
* Handler to check the health of the service.
*
* @returns Express router.
*/
const HealthHandler = () => {
const router = Router()... |
lauslim12/attendance | web/components/Form/ErrorAlert.tsx | <gh_stars>1-10
import {
Alert,
AlertDescription,
AlertIcon,
AlertTitle,
} from '@chakra-ui/react';
import { memo } from 'react';
/**
* Error alert to be rendered on top of a form if an error is found.
*
* @param params - Props.
* @returns Error alert component.
*/
const ErrorAlert = ({ error }: { error: s... |
lauslim12/attendance | web/components/Pages/ResetPassword/ResetPasswordForm.tsx | <reponame>lauslim12/attendance
import { Checkbox, Text, useToast } from '@chakra-ui/react';
import { useRouter } from 'next/router';
import type { FormEvent } from 'react';
import { memo, useState } from 'react';
import { FaKey } from 'react-icons/fa';
import axios from '../../../utils/http';
import routes from '../..... |
lauslim12/attendance | web/components/Pages/Home/Clock.tsx | import { VStack } from '@chakra-ui/react';
import { memo, useEffect, useState } from 'react';
import MainHeading from '../../MainHeading';
/**
* Clock component.
*
* @returns Clock component.
*/
const Clock = () => {
const [time, setTime] = useState(new Date());
useEffect(() => {
const timerUpdate = setI... |
lauslim12/attendance | api/cli/reminder.ts | import { PrismaClient } from '@prisma/client';
import AttendanceService from '../modules/attendance/service';
import Email from '../modules/email';
import UserService from '../modules/user/service';
/**
* An independent Prisma client, different from the one which the
* API uses.
*/
const prisma = new PrismaClient(... |
lauslim12/attendance | api/modules/email/index.ts | <reponame>lauslim12/attendance
import { convert } from 'html-to-text';
import nodemailer from 'nodemailer';
import path from 'path';
import { renderFile } from 'pug';
import config from '../../config';
import bull from '../../infra/bull';
/**
* Class for method reusability. Email is usually pushed to a Bull queue
*... |
lauslim12/attendance | api/cli/collision-test.ts | <filename>api/cli/collision-test.ts
import { nanoid } from 'nanoid/async';
/**
* Number of data to be generated.
*/
const numberOfData = 100000;
/**
* Finds the duplicates in a map and prints the colliding array to standard output.
*
* @param map - Map.
* @param name - Name of the function.
*/
function findDup... |
lauslim12/attendance | api/modules/middleware/session.ts | import connectRedis from 'connect-redis';
import type { NextFunction, Request, Response } from 'express';
import type { CookieOptions } from 'express-session';
import expressSession from 'express-session';
import config from '../../config';
import redis from '../../infra/redis';
import isHTTPS from '../../util/is-http... |
lauslim12/attendance | api/core/util/pad.ts | <reponame>lauslim12/attendance
/**
* This function will pad a string with leading zeroes.
*
* Algorithm:
* 1. Find how many times the loop should repeat if digits is more than the length of the string.
*
* @param num - Number of the OTP.
* @param digits - Digits of the OTP.
* @returns The TOTP.
*/
const pad = ... |
lauslim12/attendance | web/components/Pages/Profile/Infobox.tsx | import {
Button,
Grid,
Heading,
Stack,
Text,
useToast,
VStack,
} from '@chakra-ui/react';
import { useRouter } from 'next/router';
import { memo, useState } from 'react';
import { FaEraser, FaPencilRuler } from 'react-icons/fa';
import { useStatusAndUser } from '../../../utils/hooks';
import axios from '... |
lauslim12/attendance | web/components/Card/UserCard.tsx | <gh_stars>1-10
import {
Badge,
Button,
HStack,
Text,
useColorModeValue,
useToast,
VStack,
} from '@chakra-ui/react';
import dynamic from 'next/dynamic';
import { memo, useState } from 'react';
import { useUsers } from '../../utils/hooks';
import axios from '../../utils/http';
import type { User } from '.... |
lauslim12/attendance | api/modules/middleware/get-me.ts | <gh_stars>1-10
import type { NextFunction, Request, Response } from 'express';
import AppError from '../../util/app-error';
/**
* Moves a user's ID to the 'params' object.
*
* @param req - Express.js's request object.
* @param _ - Express.js's response object.
* @param next - Express.js's next function.
*/
cons... |
lauslim12/attendance | api/modules/middleware/x-powered-by.ts | import type { NextFunction, Request, Response } from 'express';
/**
* Override `X-Powered-By` with some other string.
*
* @returns Middleware function to override `X-Powered-By`.
*/
const xPoweredBy = () => (_: Request, res: Response, next: NextFunction) => {
res.setHeader('X-Powered-By', 'Nicholas');
next();
... |
lauslim12/attendance | api/modules/middleware/logger.ts | <filename>api/modules/middleware/logger.ts
import type { LoggerOptions } from 'express-winston';
import expressWinston from 'express-winston';
import path from 'path';
import winston from 'winston';
import getDeviceID from '../../util/device-id';
/**
* Options for the default loggers.
*
* @param filename - File na... |
lauslim12/attendance | web/components/Pages/Home/CurrentStatus.tsx | <filename>web/components/Pages/Home/CurrentStatus.tsx
import { Badge, VStack } from '@chakra-ui/react';
import { memo } from 'react';
import type { Status } from '../../../utils/types';
/**
* Current Status component.
*
* @param params - Status prop.
* @returns Current status component.
*/
const CurrentStatus = ... |
lauslim12/attendance | web/components/Pages/Profile/Topbox.tsx | import { Badge, Heading, useColorModeValue, VStack } from '@chakra-ui/react';
import { memo } from 'react';
import type { User } from '../../../utils/types';
/**
* Top part of the Profile page.
*
* @param params - Props.
* @returns React functional component.
*/
const Topbox = ({ user }: { user: User }) => (
<... |
lauslim12/attendance | web/components/Pages/Register/RegisterForm.tsx | import { Checkbox, Text } from '@chakra-ui/react';
import type { Dispatch, FormEvent, SetStateAction } from 'react';
import { memo, useState } from 'react';
import { FaKey } from 'react-icons/fa';
import axios from '../../../utils/http';
import routes from '../../../utils/routes';
import { User } from '../../../utils/... |
lauslim12/attendance | web/pages/_app.tsx | <reponame>lauslim12/attendance<gh_stars>1-10
import '@fontsource/inter/400.css';
import '@fontsource/inter/700.css';
import '@fontsource/nunito/400.css';
import '@fontsource/nunito/700.css';
import '@fontsource/nunito/800.css';
import 'focus-visible/dist/focus-visible';
import type { ThemeOverride } from '@chakra-ui/r... |
lauslim12/attendance | web/components/Card/AttendanceCard.tsx | import {
Badge,
Grid,
Heading,
List,
ListIcon,
ListItem,
useMediaQuery,
VStack,
} from '@chakra-ui/react';
import { memo } from 'react';
import { FaChild, FaFlagCheckered, FaHourglassStart } from 'react-icons/fa';
import type { Attendance } from '../../utils/types';
/**
* Props.
*/
type Props = {
... |
lauslim12/attendance | api/modules/auth/controller.ts | import type { NextFunction, Request, Response } from 'express';
import { nanoid } from 'nanoid/async';
import config from '../../config';
import { generateDefaultTOTP, validateDefaultTOTP } from '../../core/rfc6238';
import { parseBasicAuth } from '../../core/rfc7617';
import AppError from '../../util/app-error';
impo... |
lauslim12/attendance | api/core/rfc6238.ts | import * as OTPAuth from 'otpauth';
import config from '../config';
import safeCompare from '../util/safe-compare';
import { b32FromBuf, b32ToBuf } from './util/base32';
import hmacDigest from './util/hmac-digest';
import numberToBuf from './util/number-to-buf';
import pad from './util/pad';
/**
* Collection of para... |
lauslim12/attendance | api/util/send-response.ts | <reponame>lauslim12/attendance
import type { Request, Response } from 'express';
/**
* Options object parameters.
*/
interface Params<T> {
req: Request;
res: Response;
status: 'success' | 'fail' | 'error';
statusCode: number;
data: T;
message: string;
type: 'general' | 'users' | 'attendance' | 'auth' |... |
lauslim12/attendance | api/modules/attendance/service.ts | <filename>api/modules/attendance/service.ts
import { Prisma } from '@prisma/client';
import prisma from '../../infra/prisma';
/**
* All of the return types will return these attributes. This is the default
* for filtered queries, as we have no need to return sensitive attributes such
* as secrets and/or passwords.... |
lauslim12/attendance | web/components/NotAuthRoute.tsx | import { useRouter } from 'next/router';
import type { ReactNode } from 'react';
import { memo, useEffect } from 'react';
import { useMe } from '../utils/hooks';
import routes from '../utils/routes';
import Spinner from './Spinner';
/**
* Props.
*/
type Props = {
children: ReactNode;
};
/**
* The reverse of `Au... |
lauslim12/attendance | web/components/Pages/Admin/AdminRoute.tsx | <gh_stars>1-10
import { useRouter } from 'next/router';
import type { ReactNode } from 'react';
import { memo, useEffect } from 'react';
import { useMe } from '../../../utils/hooks';
import routes from '../../../utils/routes';
import Spinner from '../../Spinner';
/**
* Props.
*/
type Props = {
children: ReactNode... |
lauslim12/attendance | api/cli/gen-keys.ts | <reponame>lauslim12/attendance<filename>api/cli/gen-keys.ts
import crypto from 'node:crypto';
/**
* Generates a private key and a public key.
*
* @returns Array consisting of a public key and private key in string / buffer.
*/
function generateKeys() {
const { publicKey, privateKey } = crypto.generateKeyPairSync... |
lauslim12/attendance | api/extensions.d.ts | declare module 'express-session' {
interface SessionData {
userID?: string;
lastActive?: string;
sessionInfo?: {
device?: string;
ip?: string;
};
signedIn?: string;
}
}
export {};
|
lauslim12/attendance | web/components/Pages/Profile/Sessionbox.tsx | import { Grid, Heading, Text, VStack } from '@chakra-ui/react';
import { memo } from 'react';
import type { Session } from '../../../utils/types';
import SessionCard from '../../Card/SessionCard';
/**
* Session box to configure sessions.
*
* @returns React functional component.
*/
const Sessionbox = ({ sessions }... |
lauslim12/attendance | web/components/Input/TextInput.tsx | <reponame>lauslim12/attendance
import {
FormControl,
FormHelperText,
FormLabel,
Icon,
Input,
InputGroup,
InputLeftElement,
} from '@chakra-ui/react';
import type { Dispatch, HTMLInputTypeAttribute, SetStateAction } from 'react';
import { memo } from 'react';
import { FaEnvelope, FaLock, FaPen, FaPhone } f... |
lauslim12/attendance | api/util/validate.ts | <filename>api/util/validate.ts<gh_stars>1-10
import type { schema } from 'express-validation';
import { validate as expressValidation } from 'express-validation';
/**
* Allows to perform a customized validation with `express-validation`. We give
* `joi` access to the `context`, so `joi` can modify the request object... |
lauslim12/attendance | api/modules/session/controller.ts | <filename>api/modules/session/controller.ts
import type { NextFunction, Request, Response } from 'express';
import AppError from '../../util/app-error';
import sendResponse from '../../util/send-response';
import CacheService from '../cache/service';
/**
* Handle all requests from 'SessionHandler'.
*/
const Session... |
lauslim12/attendance | api/modules/user/handler.ts | <reponame>lauslim12/attendance<gh_stars>1-10
import { Router } from 'express';
import asyncHandler from '../../util/async-handler';
import validate from '../../util/validate';
import AttendanceHandler from '../attendance/handler';
import bodyParser from '../middleware/body-parser';
import getMe from '../middleware/get... |
lauslim12/attendance | web/pages/index.tsx | <reponame>lauslim12/attendance<filename>web/pages/index.tsx
import { VStack } from '@chakra-ui/react';
import { memo } from 'react';
import Layout from '../components/Layout';
import Clock from '../components/Pages/Home/Clock';
import CurrentStatus from '../components/Pages/Home/CurrentStatus';
import Greetings from '... |
lauslim12/attendance | web/pages/admin/attendances.tsx | import { Button, Grid, HStack, Spacer, Text, VStack } from '@chakra-ui/react';
import NextLink from 'next/link';
import { memo } from 'react';
import { FaArrowLeft } from 'react-icons/fa';
import AttendanceCard from '../../components/Card/AttendanceCard';
import Layout from '../../components/Layout';
import Spinner fr... |
lauslim12/attendance | api/util/send-error.ts | <filename>api/util/send-error.ts
import type { Request, Response } from 'express';
import AppError from './app-error';
/**
* Options object parameters.
*/
interface Params {
req: Request;
res: Response;
error: AppError;
stack?: string;
}
/**
* Sends an error response that conforms to JSON API.
*
* @para... |
lauslim12/attendance | api/modules/user/controller.ts | import type { NextFunction, Request, Response } from 'express';
import AppError from '../../util/app-error';
import sendResponse from '../../util/send-response';
import CacheService from '../cache/service';
import UserService from './service';
/**
* Create controller to handle all requests forwarded from 'UserHandle... |
lauslim12/attendance | web/utils/routes.ts | <gh_stars>1-10
/**
* All of the existent routes in the application.
*/
const routes = {
// Public routes.
home: '/',
login: '/login',
register: '/register',
profile: '/profile',
resetPassword: <PASSWORD>',
verifyEmail: '/verify-email',
// Admin routes.
admin: '/admin',
attendances: '/admin/attend... |
lauslim12/attendance | web/components/Form/FormLinks.tsx | <reponame>lauslim12/attendance
import type { ColorProps } from '@chakra-ui/react';
import { Link, VStack } from '@chakra-ui/react';
import NextLink from 'next/link';
import { memo } from 'react';
/**
* Props.
*/
type Props = {
routes: { href: string; text: string; color: ColorProps['color'] }[];
};
/**
* Renders... |
lauslim12/attendance | web/components/Pages/Profile/Passwordbox.tsx | import {
Button,
Checkbox,
Grid,
Heading,
Text,
useToast,
VStack,
} from '@chakra-ui/react';
import { useRouter } from 'next/router';
import { memo, useState } from 'react';
import { FaPassport } from 'react-icons/fa';
import { useStatusAndUser } from '../../../utils/hooks';
import axios from '../../../u... |
lauslim12/attendance | web/pages/404.tsx | import { Button, Text, VStack } from '@chakra-ui/react';
import NextLink from 'next/link';
import { memo } from 'react';
import { FaHome } from 'react-icons/fa';
import Layout from '../components/Layout';
import MainHeading from '../components/MainHeading';
import routes from '../utils/routes';
/**
* Renders a `404 ... |
lauslim12/attendance | web/components/Pages/ResetPassword/ForgotPasswordForm.tsx | import { useToast } from '@chakra-ui/react';
import type { FormEvent } from 'react';
import { memo, useState } from 'react';
import { FaLockOpen } from 'react-icons/fa';
import axios from '../../../utils/http';
import routes from '../../../utils/routes';
import Form from '../../Form';
import FormLinks from '../../Form... |
lauslim12/attendance | api/infra/redis.ts | <gh_stars>1-10
import { createNodeRedisClient } from 'handy-redis';
import config from '../config';
/**
* Creates a Redis instance to be used by the application.
*/
const redis = createNodeRedisClient({
host: config.REDIS_HOST,
password: config.REDIS_PASSWORD,
port: config.REDIS_PORT,
});
/**
* Set up pub/s... |
lauslim12/attendance | web/components/Overlay/AlertOverlay.tsx | import {
AlertDialog,
AlertDialogBody,
AlertDialogContent,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogOverlay,
Button,
} from '@chakra-ui/react';
import type { Dispatch, SetStateAction } from 'react';
import { memo, useRef } from 'react';
import { FaFire } from 'react-icons/fa';
/**
* Props.
*/
t... |
lauslim12/attendance | api/modules/middleware/xst.ts | import type { NextFunction, Request, Response } from 'express';
import AppError from '../../util/app-error';
/**
* Prevent Cross-Site Tracing by only allowing the following methods:
* [OPTIONS, HEAD, CONNECT, GET, POST, PATCH, PUT, DELETE].
*
* @returns A closure function to perform the middleware.
*/
const xst ... |
lauslim12/attendance | api/util/cookies.ts | <reponame>lauslim12/attendance
import type { Request, Response } from 'express';
import isHTTPS from './is-https';
/**
* Object parameters for our `setCookie` function.
*/
type Params = {
req: Request;
res: Response;
name: string;
value: string;
maxAge: number;
};
/**
* Sets a cookie according to the be... |
lauslim12/attendance | api/util/safe-compare.ts | <gh_stars>1-10
import { timingSafeEqual } from 'node:crypto';
/**
* Safely compares two strings with `timingSafeEqual` to prevent timing attacks.
* Allows to return 'false' if two strings are not at the same length.
*
* @param a - A string.
* @param b - A string.
* @returns A boolean value to check whether both ... |
lauslim12/attendance | api/util/passwords.ts | import argon2 from 'argon2';
/**
* Asynchronously hashes a user's password with Argon2 algorithm. Uses default
* settings: 3 iterations, 4096 memory cost, one parallelism, 32 hash length,
* 16 salt length, version 0x13 (19), and type is `argon2i`.
*
* @param password - <PASSWORD>.
* @returns Argon2 hashed passwo... |
lauslim12/attendance | web/components/Pages/Profile/Authenticatorbox.tsx | <reponame>lauslim12/attendance
import { Button, Heading, Text, useToast, VStack } from '@chakra-ui/react';
import dynamic from 'next/dynamic';
import { memo, useRef, useState } from 'react';
import { FaBarcode } from 'react-icons/fa';
import axios from '../../../utils/http';
import type { Status, User } from '../../..... |
lauslim12/attendance | api/modules/attendance/handler.ts | <filename>api/modules/attendance/handler.ts
import { Router } from 'express';
import asyncHandler from '../../util/async-handler';
import validate from '../../util/validate';
import bodyParser from '../middleware/body-parser';
import hasJWT from '../middleware/has-jwt';
import hasRole from '../middleware/has-role';
im... |
lauslim12/attendance | web/components/Pages/Admin/NotMFA.tsx | <filename>web/components/Pages/Admin/NotMFA.tsx
import { Button, Text, VStack } from '@chakra-ui/react';
import NextLink from 'next/link';
import { memo } from 'react';
import { FaBolt } from 'react-icons/fa';
import routes from '../../../utils/routes';
import MainHeading from '../../MainHeading';
/**
* NotMFA: A co... |
lauslim12/attendance | api/util/random-bytes.ts | import { randomBytes as rand } from 'node:crypto';
import { promisify } from 'node:util';
/**
* Generates a cryptographically-safe random generator as an alternative for
* NanoID.
*
* @param size - Size of bytes to generate. Defaults to 64.
* @returns Random bytes in the form of Buffer.
*/
const randomBytes = as... |
lauslim12/attendance | api/core/rfc7617.ts | <gh_stars>1-10
/**
* Creates a Basic Authorization string based on RFC 7617. This function
* is unused, but is left here for the sake of completeness, as the one who will process
* the creation of the authorization string will be at the front-end part of the application.
*
* {@link https://datatracker.ietf.org/doc... |
lauslim12/attendance | api/util/is-https.ts | import type { Request } from 'express';
/**
* Verifies whether the current connection is secure (HTTPS) or not.
*
* @param req - Express.js's request object.
* @returns A boolean value whether the connection is secure or not.
*/
const isHTTPS = (req: Request) => {
if (req.secure || req.headers['x-forwarded-prot... |
lauslim12/attendance | api/modules/middleware/x-requested-with.ts | <gh_stars>1-10
import type { NextFunction, Request, Response } from 'express';
import AppError from '../../util/app-error';
/**
* If consumer does not pass the `X-Requested-With` header, then
* we can assume that the request is forged with CSRF. `X-Requested-With`
* will force requests to enter preflight state fir... |
lauslim12/attendance | web/components/Overlay/QRDialog.tsx | <filename>web/components/Overlay/QRDialog.tsx<gh_stars>1-10
import {
AlertDialog,
AlertDialogBody,
AlertDialogContent,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogOverlay,
Button,
LightMode,
Text,
VStack,
} from '@chakra-ui/react';
import NextLink from 'next/link';
import { QRCodeCanvas } from ... |
lauslim12/attendance | web/components/Overlay/AttendanceModal.tsx | <gh_stars>1-10
import {
Alert,
AlertIcon,
Button,
chakra,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
Text,
Textarea,
useToast,
VStack,
} from '@chakra-ui/react';
import { memo, useEffect, useState } from 'react';
import { FaBolt, FaCube } from... |
lauslim12/attendance | web/pages/profile.tsx | <gh_stars>1-10
import { memo } from 'react';
import Layout from '../components/Layout';
import Attendancebox from '../components/Pages/Profile/Attendancebox';
import Authenticatorbox from '../components/Pages/Profile/Authenticatorbox';
import Infobox from '../components/Pages/Profile/Infobox';
import PasswordBox from ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.