Skip to content

Commit

Permalink
Merge pull request #279 from EATSTEAK/dev
Browse files Browse the repository at this point in the history
0.10.2
  • Loading branch information
EATSTEAK authored Sep 11, 2022
2 parents 7e078e9 + 0e89341 commit d823d51
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lockerweb",
"version": "0.10.1",
"version": "0.10.2",
"description": "SSU IT Collage Locker system.",
"private": true,
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "client",
"version": "0.10.1",
"version": "0.10.2",
"scripts": {
"dev": "cross-env VITE_BASE_URL=http://localhost:3000 vite dev --port 5002 --host 0.0.0.0",
"build": "vite build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
export let collapsable = true;
export let disableBlock = false;
let serviceName = '사물함 예약 시스템';
$: if ($config && $config.success) {
Expand All @@ -32,7 +34,7 @@
}
</script>

<Shell class={clazz} {navigationClass} {mainClass}>
<Shell class={clazz} {navigationClass} {mainClass} {disableBlock}>
<Navigation
slot='navigation'
class='flex-row w-full'
Expand Down
11 changes: 9 additions & 2 deletions packages/client/src/components/molecule/Shell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import { getDepartmentConfig, getServiceConfig } from '$lib/api/config';
import { isActivated } from '$lib/utils';
import Info from '../../icons/Info.svelte';
import { extractLockerInfoFromId } from '$lib/utils.js';
let clazz = '';
export { clazz as class };
Expand Down Expand Up @@ -94,9 +95,15 @@
</section>
</main>

<Modal title='예약 불가 알림' bind:open={blockedModalOpen} preventOutclick on:cancel={() => console.log('hello')}
<!--suppress JSUnresolvedVariable -->
<Modal title='예약 불가 알림' bind:open={blockedModalOpen} preventOutclick on:cancel={() => {}}
secondaryClass='hidden'
primaryText='로그아웃' isPrimaryBtnIconRight on:click={() => goto('/logout')}>
현재 예약 가능한 시간이 아닙니다.
<p>현재 예약 가능한 시간이 아닙니다.</p>
{#if $user && $user.success && $user.result.lockerId}
{@const lockerInfo = extractLockerInfoFromId($user.result.lockerId)}
<p>내가 예약한 사물함: <span class='bg-gray-200 rounded-lg py-1 px-2'>{lockerInfo.floor}층 | {lockerInfo.sectionId}구역
- {lockerInfo.lockerNum}번</span></p>
{/if}
<ArrowExportLtr slot='primaryIcon' />
</Modal>
6 changes: 4 additions & 2 deletions packages/client/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
$: errorData = apiResponse && apiResponse.success === false ? apiResponse.error : undefined;
$: serviceConfig = $config && $config.success ? getServiceConfig($config.result) : undefined;
$: if ($config && $config.success && countData) {
lockerCount = updateLockerCount($config.result, countData);
}
Expand Down Expand Up @@ -117,7 +119,7 @@
<Navigation slot='navigation' class='w-full h-full min-h-screen' collapsable={false}>
<NavigationContent>
<Entry class='grow h-full justify-center' name='SOONGSIL UNIV. IT'>
{#if $config && $config.success && !isActivated($config.result.activateFrom, $config.result.activateTo)}
{#if serviceConfig && !isActivated(serviceConfig.activateFrom, serviceConfig.activateTo)}
<Button
disabled={callbackUrl ? undefined : true}
href='https://class.ssu.ac.kr/xn-sso/gw.php?login_type=sso&callback_url={encodeURIComponent(
Expand All @@ -127,7 +129,7 @@
class='bg-red-800 text-white w-full h-16 text-xl'
isIconRight
>
서비스 이용 불가
예약 불가(열람만 가능)
<ErrorCircle class='w-8 h-8' slot='icon' />
</Button>
{:else}
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/routes/admin/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@

<svelte:window bind:innerWidth />

<NavigationShell bind:navigationCollapsed collapsable={innerWidth && innerWidth <= 768}>
<NavigationShell bind:navigationCollapsed collapsable={innerWidth && innerWidth <= 768} disableBlock>
<section class='flex flex-col gap-1' slot='navigation_content'>
{#if $user && $user.success}
<h3>설정</h3>
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "server",
"version": "0.10.1",
"version": "0.10.2",
"description": "Backend Lambda script for lockerweb",
"license": "MIT",
"scripts": {
Expand Down
9 changes: 6 additions & 3 deletions packages/server/src/auth/data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { GetItemInput, UpdateItemInput, UpdateItemOutput } from 'aws-sdk/clients/dynamodb';
import { ForbiddenError, UnauthorizedError } from '../util/error';
import { BlockedError, ForbiddenError, UnauthorizedError } from '../util/error';
import { adminId, dynamoDB, TableName } from '../util/database';
import type { AWSError } from 'aws-sdk';

Expand Down Expand Up @@ -40,7 +40,8 @@ export const revokeToken = async function (

export const issueToken = async function (
id: string,
token: string
token: string,
isServiceBlocked: boolean
): Promise<{ id: string; expires: number }> {
const expires = Date.now() + 3600 * 1000 * 24;
const condition = 'attribute_exists(d)';
Expand All @@ -66,11 +67,13 @@ export const issueToken = async function (
res = await dynamoDB.updateItem(req).promise();
} catch (e) {
if ((e as AWSError).name === 'ConditionalCheckFailedException') {
throw new ForbiddenError('This user cannot login to service');
throw new BlockedError('This user cannot login to service');
}
throw e;
}
if (res.Attributes.hasOwnProperty('aT') && res.Attributes.aT.S === token) {
if (res.Attributes.iA?.BOOL !== true && isServiceBlocked)
throw new BlockedError('This user cannot login to service');
return { id, expires };
} else {
throw new ForbiddenError('Cannot issue token', { id, expires });
Expand Down
14 changes: 3 additions & 11 deletions packages/server/src/auth/handler/ssu_login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ import https from 'https';
import type { APIGatewayProxyHandler } from 'aws-lambda';
import * as jwt from 'jsonwebtoken';
import { createResponse, JWT_SECRET } from '../../common';
import {
BlockedError,
errorResponse,
responseAsLockerError,
UnauthorizedError
} from '../../util/error';
import { errorResponse, responseAsLockerError, UnauthorizedError } from '../../util/error';
import { issueToken } from '../data';
import { queryConfig } from '../../config/data';
import { adminId } from '../../util/database';
import { getBlockedDepartments } from '../../util/access';

function requestBody(result: string): Promise<string> {
Expand Down Expand Up @@ -48,13 +42,11 @@ export const ssuLoginHandler: APIGatewayProxyHandler = async (event) => {
const id = await obtainId(result);
const configs = await queryConfig();
const blockedDepartments = getBlockedDepartments(configs);
if (adminId !== id && blockedDepartments.includes('SERVICE')) {
return errorResponse(new BlockedError('Service unavailable'));
}
const isServiceBlocked = blockedDepartments.includes('SERVICE');
const accessToken = jwt.sign({ aud: id }, JWT_SECRET, {
expiresIn: 3600 * 1000
});
const issued = await issueToken(id, accessToken);
const issued = await issueToken(id, accessToken, isServiceBlocked);
const left = Math.floor((issued.expires - Date.now()) / 1000);
const res = {
success: true,
Expand Down
14 changes: 6 additions & 8 deletions packages/server/src/locker/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
UpdateItemOutput
} from 'aws-sdk/clients/dynamodb';
import { adminId, dynamoDB, TableName } from '../util/database';
import { CantClaimError, CantUnclaimError, ForbiddenError, NotFoundError } from '../util/error';
import { BlockedError, CantClaimError, CantUnclaimError, NotFoundError } from '../util/error';
import type { AWSError } from 'aws-sdk';

export const claimLocker = async function (
Expand Down Expand Up @@ -39,7 +39,7 @@ export const claimLocker = async function (
blockedDepartments.map((d) => [`:${d}`, { S: d }])
);
conditionValues[':true'] = { BOOL: true };
const condition = blockedDepartments.map((d) => `(NOT d = :${d})`).join(' AND ');
const condition = blockedDepartments.map((d) => `NOT d = :${d}`).join(' AND ');
const req: UpdateItemInput = {
TableName,
Key: { type: { S: 'user' }, id: { S: id } },
Expand All @@ -62,7 +62,7 @@ export const claimLocker = async function (
res = await dynamoDB.updateItem(req).promise();
} catch (e) {
if ((e as AWSError).name === 'ConditionalCheckFailedException') {
throw new ForbiddenError();
throw new BlockedError();
}
throw e;
}
Expand All @@ -86,14 +86,12 @@ export const unclaimLocker = async function (
blockedDepartments.map((d) => [`:${d}`, { S: d }])
);
conditionValues[':true'] = { BOOL: true };
const condition = blockedDepartments.map((d) => `(NOT d = :${d})`).join(' AND ');
const condition = blockedDepartments.map((d) => `NOT d = :${d}`).join(' AND ');
const req: UpdateItemInput = {
TableName,
Key: { type: { S: 'user' }, id: { S: id } },
UpdateExpression: 'REMOVE #lockerId',
ConditionExpression: `#aT = :token AND attribute_exists(#lockerId)${
condition ? ` AND ((${condition}) OR iA = true)` : ''
}`,
ConditionExpression: `#aT = :token ${condition ? ` AND ((${condition}) OR iA = :true)` : ''}`,
ExpressionAttributeNames: {
'#lockerId': 'lockerId',
'#aT': 'aT'
Expand All @@ -109,7 +107,7 @@ export const unclaimLocker = async function (
res = await dynamoDB.updateItem(req).promise();
} catch (e) {
if ((e as AWSError).name === 'ConditionalCheckFailedException') {
throw new ForbiddenError();
throw new BlockedError();
}
throw e;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@types/lockerweb",
"version": "0.10.1",
"version": "0.10.2",
"types": "index.d.ts",
"license": "MIT",
"dependencies": {
Expand Down

0 comments on commit d823d51

Please sign in to comment.