├── src ├── assets │ ├── .gitkeep │ └── icons │ │ ├── icon-72x72.png │ │ ├── icon-96x96.png │ │ ├── icon-128x128.png │ │ ├── icon-144x144.png │ │ ├── icon-152x152.png │ │ ├── icon-192x192.png │ │ ├── icon-384x384.png │ │ └── icon-512x512.png ├── @types │ └── jsencrypt │ │ └── index.d.ts ├── app │ ├── qr │ │ ├── scan │ │ │ ├── scan-success-dialog │ │ │ │ ├── scan-success-dialog.component.scss │ │ │ │ ├── scan-success-dialog.component.html │ │ │ │ ├── scan-success-dialog.component.spec.ts │ │ │ │ └── scan-success-dialog.component.ts │ │ │ ├── guest-register-dialog │ │ │ │ ├── guest-register-dialog.component.scss │ │ │ │ ├── guest-register-dialog.component.spec.ts │ │ │ │ ├── guest-register-dialog.component.html │ │ │ │ └── guest-register-dialog.component.ts │ │ │ ├── scan.component.scss │ │ │ ├── scan.component.spec.ts │ │ │ ├── scan.component.html │ │ │ └── scan.component.ts │ │ ├── models │ │ │ ├── visit.spec.ts │ │ │ ├── nhi-user.spec.ts │ │ │ ├── follower.spec.ts │ │ │ ├── location.spec.ts │ │ │ ├── tcpass-visit.spec.ts │ │ │ ├── nhi-user.ts │ │ │ ├── follower.ts │ │ │ ├── tcpass-visit.ts │ │ │ ├── location.ts │ │ │ └── visit.ts │ │ ├── rsa.service.spec.ts │ │ ├── qr-routing.module.ts │ │ ├── show │ │ │ ├── show.component.scss │ │ │ ├── show.component.spec.ts │ │ │ ├── show.component.html │ │ │ └── show.component.ts │ │ ├── qr.module.ts │ │ └── rsa.service.ts │ ├── app.component.html │ ├── svg │ │ ├── tccg-logo │ │ │ ├── tccg-logo.component.scss │ │ │ ├── tccg-logo.component.ts │ │ │ ├── tccg-logo.component.spec.ts │ │ │ └── tccg-logo.component.svg │ │ └── svg.module.ts │ ├── app.component.scss │ ├── user │ │ ├── model │ │ │ ├── user.spec.ts │ │ │ ├── guest.spec.ts │ │ │ ├── token.spec.ts │ │ │ ├── employee.spec.ts │ │ │ ├── department.spec.ts │ │ │ ├── department-employee.spec.ts │ │ │ ├── token.ts │ │ │ ├── department.ts │ │ │ ├── department-employee.ts │ │ │ ├── employee.ts │ │ │ ├── guest.ts │ │ │ └── user.ts │ │ ├── login │ │ │ ├── duplicate-verification-dialog │ │ │ │ ├── duplicate-verification-dialog.component.html │ │ │ │ ├── duplicate-verification-dialog.component.ts │ │ │ │ └── duplicate-verification-dialog.component.spec.ts │ │ │ ├── login.component.scss │ │ │ ├── login.component.spec.ts │ │ │ ├── login.component.html │ │ │ └── login.component.ts │ │ ├── user-routing.module.ts │ │ ├── user.service.spec.ts │ │ ├── user.module.ts │ │ └── user.service.ts │ ├── model │ │ ├── result.spec.ts │ │ └── result.ts │ ├── check-update-bottom-sheet │ │ ├── check-update-bottom-sheet.component.html │ │ ├── check-update-bottom-sheet.component.ts │ │ └── check-update-bottom-sheet.component.spec.ts │ ├── auth.guard.spec.ts │ ├── app-routing.module.ts │ ├── app.component.spec.ts │ ├── auth.guard.ts │ ├── app.module.ts │ └── app.component.ts ├── favicon.ico ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── main.ts ├── styles.scss ├── index.html ├── test.ts ├── manifest.webmanifest └── polyfills.ts ├── README.md ├── tsconfig.app.json ├── e2e ├── tsconfig.json ├── src │ ├── app.po.ts │ └── app.e2e-spec.ts └── protractor.conf.js ├── .editorconfig ├── tsconfig.spec.json ├── .browserslistrc ├── tsconfig.json ├── ngsw-config.json ├── .gitignore ├── LICENSE ├── karma.conf.js ├── package.json ├── tslint.json └── angular.json /src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/@types/jsencrypt/index.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'jsencrypt'; -------------------------------------------------------------------------------- /src/app/qr/scan/scan-success-dialog/scan-success-dialog.component.scss: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirror520/tiwenpass/HEAD/src/favicon.ico -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
-------------------------------------------------------------------------------- /src/app/svg/tccg-logo/tccg-logo.component.scss: -------------------------------------------------------------------------------- 1 | svg { 2 | height: 100%; 3 | width: 100%; 4 | } -------------------------------------------------------------------------------- /src/assets/icons/icon-72x72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirror520/tiwenpass/HEAD/src/assets/icons/icon-72x72.png -------------------------------------------------------------------------------- /src/assets/icons/icon-96x96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirror520/tiwenpass/HEAD/src/assets/icons/icon-96x96.png -------------------------------------------------------------------------------- /src/assets/icons/icon-128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirror520/tiwenpass/HEAD/src/assets/icons/icon-128x128.png -------------------------------------------------------------------------------- /src/assets/icons/icon-144x144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirror520/tiwenpass/HEAD/src/assets/icons/icon-144x144.png -------------------------------------------------------------------------------- /src/assets/icons/icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirror520/tiwenpass/HEAD/src/assets/icons/icon-152x152.png -------------------------------------------------------------------------------- /src/assets/icons/icon-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirror520/tiwenpass/HEAD/src/assets/icons/icon-192x192.png -------------------------------------------------------------------------------- /src/assets/icons/icon-384x384.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirror520/tiwenpass/HEAD/src/assets/icons/icon-384x384.png -------------------------------------------------------------------------------- /src/assets/icons/icon-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mirror520/tiwenpass/HEAD/src/assets/icons/icon-512x512.png -------------------------------------------------------------------------------- /src/app/app.component.scss: -------------------------------------------------------------------------------- 1 | .app-view { 2 | height: 100vh; 3 | max-height: 100vh; 4 | width: 100vw; 5 | max-width: 100vw; 6 | } -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | 4 | baseUrl: 'https://tiwengo.tccgov.tw', 5 | }; 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tiwenpass 2 | 3 | ## 這個專案已經封存 4 | 5 | 請切換到[民間版防疫追蹤溯源實名登記 Cloud APP](https://github.com/mirror520/twpass),將實現 Cloud and Edge Computing 架構 6 | -------------------------------------------------------------------------------- /src/app/user/model/user.spec.ts: -------------------------------------------------------------------------------- 1 | import { User } from './user'; 2 | 3 | describe('User', () => { 4 | it('should create an instance', () => { 5 | expect(new User()).toBeTruthy(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /src/app/model/result.spec.ts: -------------------------------------------------------------------------------- 1 | import { Result } from './result'; 2 | 3 | describe('Result', () => { 4 | it('should create an instance', () => { 5 | expect(new Result()).toBeTruthy(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /src/app/qr/models/visit.spec.ts: -------------------------------------------------------------------------------- 1 | import { Visit } from './visit'; 2 | 3 | describe('Visit', () => { 4 | it('should create an instance', () => { 5 | expect(new Visit()).toBeTruthy(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /src/app/user/model/guest.spec.ts: -------------------------------------------------------------------------------- 1 | import { Guest } from './guest'; 2 | 3 | describe('Guest', () => { 4 | it('should create an instance', () => { 5 | expect(new Guest()).toBeTruthy(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /src/app/user/model/token.spec.ts: -------------------------------------------------------------------------------- 1 | import { Token } from './token'; 2 | 3 | describe('Token', () => { 4 | it('should create an instance', () => { 5 | expect(new Token()).toBeTruthy(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /src/app/qr/models/nhi-user.spec.ts: -------------------------------------------------------------------------------- 1 | import { NhiUser } from './nhi-user'; 2 | 3 | describe('NhiUser', () => { 4 | it('should create an instance', () => { 5 | expect(new NhiUser()).toBeTruthy(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /src/app/qr/models/follower.spec.ts: -------------------------------------------------------------------------------- 1 | import { Follower } from './follower'; 2 | 3 | describe('Follower', () => { 4 | it('should create an instance', () => { 5 | expect(new Follower()).toBeTruthy(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /src/app/qr/models/location.spec.ts: -------------------------------------------------------------------------------- 1 | import { Location } from './location'; 2 | 3 | describe('Location', () => { 4 | it('should create an instance', () => { 5 | expect(new Location()).toBeTruthy(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /src/app/user/model/employee.spec.ts: -------------------------------------------------------------------------------- 1 | import { Employee } from './employee'; 2 | 3 | describe('Employee', () => { 4 | it('should create an instance', () => { 5 | expect(new Employee()).toBeTruthy(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /src/app/user/model/department.spec.ts: -------------------------------------------------------------------------------- 1 | import { Department } from './department'; 2 | 3 | describe('Department', () => { 4 | it('should create an instance', () => { 5 | expect(new Department()).toBeTruthy(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /src/app/qr/models/tcpass-visit.spec.ts: -------------------------------------------------------------------------------- 1 | import { TcpassVisit } from './tcpass-visit'; 2 | 3 | describe('TcpassVisit', () => { 4 | it('should create an instance', () => { 5 | expect(new TcpassVisit()).toBeTruthy(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /src/app/check-update-bottom-sheet/check-update-bottom-sheet.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 確認 4 | 已有新的版本,確認後將更新系統,請稍後... 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/app/user/model/department-employee.spec.ts: -------------------------------------------------------------------------------- 1 | import { DepartmentEmployee } from './department-employee'; 2 | 3 | describe('DepartmentEmployee', () => { 4 | it('should create an instance', () => { 5 | expect(new DepartmentEmployee()).toBeTruthy(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.d.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es2018", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/app/svg/tccg-logo/tccg-logo.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-tccg-logo', 5 | templateUrl: './tccg-logo.component.svg', 6 | styleUrls: ['./tccg-logo.component.scss'] 7 | }) 8 | export class TccgLogoComponent { 9 | } 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /src/app/qr/scan/guest-register-dialog/guest-register-dialog.component.scss: -------------------------------------------------------------------------------- 1 | .login-field { 2 | width: 100%; 3 | } 4 | 5 | .login-form { 6 | display: flex; 7 | flex-direction: column; 8 | margin: 10px 0; 9 | } 10 | 11 | .close-button{ 12 | float: right; 13 | top: -24px; 14 | right: -24px; 15 | } 16 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo(): Promise { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText(): Promise { 9 | return element(by.css('app-root .content span')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /src/app/svg/svg.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | 4 | import { TccgLogoComponent } from './tccg-logo/tccg-logo.component'; 5 | 6 | @NgModule({ 7 | declarations: [TccgLogoComponent], 8 | imports: [ 9 | CommonModule 10 | ], 11 | exports: [ 12 | TccgLogoComponent 13 | ] 14 | }) 15 | export class SvgModule { } 16 | -------------------------------------------------------------------------------- /src/app/auth.guard.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { AuthGuard } from './auth.guard'; 4 | 5 | describe('AuthGuard', () => { 6 | let guard: AuthGuard; 7 | 8 | beforeEach(() => { 9 | TestBed.configureTestingModule({}); 10 | guard = TestBed.inject(AuthGuard); 11 | }); 12 | 13 | it('should be created', () => { 14 | expect(guard).toBeTruthy(); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /src/app/qr/rsa.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { RsaService } from './rsa.service'; 4 | 5 | describe('RsaService', () => { 6 | let service: RsaService; 7 | 8 | beforeEach(() => { 9 | TestBed.configureTestingModule({}); 10 | service = TestBed.inject(RsaService); 11 | }); 12 | 13 | it('should be created', () => { 14 | expect(service).toBeTruthy(); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /src/app/user/login/duplicate-verification-dialog/duplicate-verification-dialog.component.html: -------------------------------------------------------------------------------- 1 |

您好

2 |
3 |

您已經驗證過了,是否需要再次驗證?

4 | 提醒:您可使用最後的驗證簡訊再次登入 5 |
6 |
7 | 8 | 9 |
10 | -------------------------------------------------------------------------------- /src/app/user/user-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | import { LoginComponent } from './login/login.component'; 5 | 6 | const routes: Routes = [ 7 | { path: 'login', component: LoginComponent }, 8 | ] 9 | 10 | @NgModule({ 11 | imports: [RouterModule.forChild(routes)], 12 | exports: [RouterModule] 13 | }) 14 | export class UserRoutingModule { } 15 | -------------------------------------------------------------------------------- /src/app/user/user.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { UserService } from './user.service'; 4 | 5 | describe('UserService', () => { 6 | let service: UserService; 7 | 8 | beforeEach(() => { 9 | TestBed.configureTestingModule({}); 10 | service = TestBed.inject(UserService); 11 | }); 12 | 13 | it('should be created', () => { 14 | expect(service).toBeTruthy(); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /src/app/user/model/token.ts: -------------------------------------------------------------------------------- 1 | export class Token { 2 | private _token: string; 3 | private _expire: Date; 4 | 5 | public get token(): string { 6 | return this._token; 7 | } 8 | public set token(value: string) { 9 | this._token = value; 10 | } 11 | 12 | public get expire(): Date { 13 | return this._expire; 14 | } 15 | public set expire(value: Date) { 16 | this._expire = value; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/app/qr/models/nhi-user.ts: -------------------------------------------------------------------------------- 1 | export class NhiUser { 2 | private _name: string; 3 | private _id_card: string; 4 | 5 | public get name(): string { 6 | return this._name; 7 | } 8 | public set name(value: string) { 9 | this._name = value.trim(); 10 | } 11 | 12 | public get id_card(): string { 13 | return this._id_card; 14 | } 15 | public set id_card(value: string) { 16 | this._id_card = value; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /src/app/user/model/department.ts: -------------------------------------------------------------------------------- 1 | export class Department { 2 | private _id; number; 3 | private _department: string; 4 | 5 | public get id(): number { 6 | return this._id; 7 | } 8 | public set id(value: number) { 9 | this._id = value; 10 | } 11 | 12 | public get department(): string { 13 | return this._department; 14 | } 15 | public set department(value: string) { 16 | this._department = value; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | import { LoginComponent } from './user/login/login.component'; 5 | 6 | const routes: Routes = [ 7 | { path: '', component: LoginComponent }, 8 | { path: 't/:token', component: LoginComponent }, 9 | ]; 10 | 11 | @NgModule({ 12 | imports: [RouterModule.forRoot(routes)], 13 | exports: [RouterModule] 14 | }) 15 | export class AppRoutingModule { } 16 | -------------------------------------------------------------------------------- /src/app/qr/scan/scan.component.scss: -------------------------------------------------------------------------------- 1 | @import '~@angular/material/theming'; 2 | 3 | #toolbar { 4 | @include mat-elevation(4); 5 | height: 10vh; 6 | } 7 | 8 | .form-field { 9 | width: 100%; 10 | } 11 | 12 | .scan-page { 13 | height: auto; 14 | width: 80%; 15 | max-width: 800px; 16 | margin: 20px auto; 17 | } 18 | 19 | .toolbar-text { 20 | font-size: 5vmin; 21 | } 22 | 23 | .spacer { 24 | flex: 1 1 auto; 25 | } 26 | 27 | .info-container { 28 | display: flex; 29 | width: 100%; 30 | } 31 | -------------------------------------------------------------------------------- /src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | 3 | html, body { height: 100%; } 4 | body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; } 5 | 6 | @import '~@angular/material/theming'; 7 | 8 | // Include material core styles. 9 | @include mat-core(); 10 | 11 | // Define the light theme 12 | $primary: mat-palette($mat-cyan); 13 | $accent: mat-palette($mat-amber, A200, A100, A400); 14 | 15 | $theme: mat-light-theme($primary, $accent); 16 | 17 | @include angular-material-theme($theme); -------------------------------------------------------------------------------- /src/app/check-update-bottom-sheet/check-update-bottom-sheet.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { MatBottomSheetRef } from '@angular/material/bottom-sheet'; 3 | 4 | @Component({ 5 | selector: 'app-check-update-bottom-sheet', 6 | templateUrl: './check-update-bottom-sheet.component.html', 7 | }) 8 | export class CheckUpdateBottomSheetComponent { 9 | 10 | constructor( 11 | private bottomSheetRef: MatBottomSheetRef 12 | ) { } 13 | 14 | confirm() { 15 | this.bottomSheetRef.dismiss(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "es2020", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "lib": [ 15 | "es2018", 16 | "dom" 17 | ] 18 | }, 19 | "angularCompilerOptions": { 20 | "fullTemplateTypeCheck": true, 21 | "strictInjectionParameters": true 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/app/user/login/login.component.scss: -------------------------------------------------------------------------------- 1 | .login-page { 2 | height: 100%; 3 | width: 100%; 4 | margin: auto; 5 | overflow-y: auto; 6 | } 7 | 8 | .logo-container { 9 | height: auto; 10 | width: 250px; 11 | font-size: 20px; 12 | font-weight: bold; 13 | text-align: center; 14 | } 15 | 16 | .login-container { 17 | max-width: 85%; 18 | } 19 | 20 | .login-field { 21 | width: 100%; 22 | } 23 | 24 | .login-form { 25 | display: flex; 26 | flex-direction: column; 27 | margin: 10px 0; 28 | } 29 | 30 | .login-form .mat-action-row { 31 | padding-left: 0; 32 | } 33 | -------------------------------------------------------------------------------- /src/app/qr/qr-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | import { AuthGuard } from '../auth.guard'; 5 | import { ScanComponent } from './scan/scan.component'; 6 | import { ShowComponent } from './show/show.component'; 7 | 8 | const routes: Routes = [ 9 | { path: 'qr/scan', component: ScanComponent, canActivate: [AuthGuard] }, 10 | { path: 'qr/show', component: ShowComponent, canActivate: [AuthGuard] }, 11 | ] 12 | 13 | @NgModule({ 14 | imports: [RouterModule.forChild(routes)], 15 | exports: [RouterModule] 16 | }) 17 | export class QrRoutingModule { } 18 | -------------------------------------------------------------------------------- /src/app/user/login/duplicate-verification-dialog/duplicate-verification-dialog.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Inject } from '@angular/core'; 2 | import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; 3 | 4 | import { User } from '../../model/user'; 5 | 6 | @Component({ 7 | selector: 'app-duplicate-verification-dialog', 8 | templateUrl: './duplicate-verification-dialog.component.html' 9 | }) 10 | export class DuplicateVerificationDialogComponent { 11 | 12 | constructor( 13 | public dialogRef: MatDialogRef, 14 | @Inject(MAT_DIALOG_DATA) public data: User 15 | ) { } 16 | } 17 | -------------------------------------------------------------------------------- /src/app/qr/show/show.component.scss: -------------------------------------------------------------------------------- 1 | @import '~@angular/material/theming'; 2 | 3 | #toolbar { 4 | @include mat-elevation(4); 5 | height: 10vh; 6 | } 7 | 8 | .form-field { 9 | width: 100%; 10 | } 11 | 12 | .qrcode-page { 13 | height: auto; 14 | width: 90%; 15 | max-width: 800px; 16 | margin: 20px auto; 17 | } 18 | 19 | .qrcode-image { 20 | width: 100%; 21 | max-width: 800px; 22 | } 23 | 24 | .toolbar-text { 25 | font-size: 5vmin; 26 | } 27 | 28 | .spacer { 29 | flex: 1 1 auto; 30 | } 31 | 32 | .mat-fab-bottom-right { 33 | position: fixed; 34 | top: auto; 35 | right: 20px; 36 | bottom: 20px; 37 | left: auto; 38 | } 39 | -------------------------------------------------------------------------------- /src/app/qr/models/follower.ts: -------------------------------------------------------------------------------- 1 | export class Follower { 2 | private _visit_id: number; 3 | private _name: string; 4 | 5 | constructor(name?: string) { 6 | this.visit_id = 0; 7 | this.name = name; 8 | } 9 | 10 | public get visit_id(): number { 11 | return this._visit_id; 12 | } 13 | public set visit_id(value: number) { 14 | this._visit_id = value; 15 | } 16 | 17 | public get name(): string { 18 | return this._name; 19 | } 20 | public set name(value: string) { 21 | this._name = value; 22 | } 23 | 24 | public toJSON() { 25 | return { 26 | id: this.visit_id, 27 | name: this.name 28 | }; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/app/qr/scan/scan.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ScanComponent } from './scan.component'; 4 | 5 | describe('ScanComponent', () => { 6 | let component: ScanComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ScanComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ScanComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/qr/show/show.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ShowComponent } from './show.component'; 4 | 5 | describe('ShowComponent', () => { 6 | let component: ShowComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ShowComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ShowComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('tiwenpass app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /ngsw-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/service-worker/config/schema.json", 3 | "index": "/index.html", 4 | "assetGroups": [ 5 | { 6 | "name": "app", 7 | "installMode": "prefetch", 8 | "resources": { 9 | "files": [ 10 | "/favicon.ico", 11 | "/index.html", 12 | "/manifest.webmanifest", 13 | "/*.css", 14 | "/*.js" 15 | ] 16 | } 17 | }, { 18 | "name": "assets", 19 | "installMode": "lazy", 20 | "updateMode": "prefetch", 21 | "resources": { 22 | "files": [ 23 | "/assets/**", 24 | "/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)" 25 | ] 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /src/app/user/login/login.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { LoginComponent } from './login.component'; 4 | 5 | describe('LoginComponent', () => { 6 | let component: LoginComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ LoginComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(LoginComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/svg/tccg-logo/tccg-logo.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { TccgLogoComponent } from './tccg-logo.component'; 4 | 5 | describe('TccgLogoComponent', () => { 6 | let component: TccgLogoComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ TccgLogoComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(TccgLogoComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false, 7 | 8 | baseUrl: 'https://tiwengo.linyc.idv.tw', 9 | }; 10 | 11 | /* 12 | * For easier debugging in development mode, you can import the following file 13 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 14 | * 15 | * This import should be commented out in production mode because it will have a negative impact 16 | * on performance if an error is thrown. 17 | */ 18 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 19 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 臺中市政府防疫追蹤溯源實名登記 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /src/app/model/result.ts: -------------------------------------------------------------------------------- 1 | export class Result { 2 | private _status: string; 3 | private _info: string[]; 4 | private _data: T; 5 | private _time: number; 6 | 7 | public get status(): string { 8 | return this._status; 9 | } 10 | public set status(value: string) { 11 | this._status = value; 12 | } 13 | 14 | public get info(): string[] { 15 | return this._info; 16 | } 17 | public set info(value: string[]) { 18 | this._info = value; 19 | } 20 | 21 | public get data(): T { 22 | return this._data; 23 | } 24 | public set data(value: T) { 25 | this._data = value; 26 | } 27 | 28 | public get time(): number { 29 | return this._time; 30 | } 31 | public set time(value: number) { 32 | this._time = value * 1000; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/app/qr/scan/scan-success-dialog/scan-success-dialog.component.html: -------------------------------------------------------------------------------- 1 |

登錄成功

2 |
3 | 實名登記 APP
4 | 訪客:{{ visit.guest.name }}
5 | 洽公單位:{{ visit.department_employee.department.department }}
6 | 接待人員:{{ visit.department_employee.employee.name }}
7 | 地點:{{ visit.location?.building.building }} {{ visit.location?.location }}
8 | 同行者人數:{{ visit?.followers.length }} 人 9 |
10 |
11 | 臺中 e 指通
12 | 洽公單位:{{ tcpass.department_employee.department.department }}
13 | 接待人員:{{ tcpass.department_employee.employee.name }}
14 | 地點:{{ tcpass.location?.building.building }} {{ tcpass.location?.location }}
15 |
16 |
17 | {{ closeTime }} 秒後關閉視窗 18 |
19 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | keys(): string[]; 13 | (id: string): T; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting() 21 | ); 22 | // Then we find all the tests. 23 | const context = require.context('./', true, /\.spec\.ts$/); 24 | // And load the modules. 25 | context.keys().map(context); 26 | -------------------------------------------------------------------------------- /src/app/qr/scan/scan-success-dialog/scan-success-dialog.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ScanSuccessDialogComponent } from './scan-success-dialog.component'; 4 | 5 | describe('ScanSuccessDialogComponent', () => { 6 | let component: ScanSuccessDialogComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ScanSuccessDialogComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ScanSuccessDialogComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/qr/scan/guest-register-dialog/guest-register-dialog.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { GuestRegisterDialogComponent } from './guest-register-dialog.component'; 4 | 5 | describe('GuestRegisterDialogComponent', () => { 6 | let component: GuestRegisterDialogComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ GuestRegisterDialogComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(GuestRegisterDialogComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/check-update-bottom-sheet/check-update-bottom-sheet.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { CheckUpdateBottomSheetComponent } from './check-update-bottom-sheet.component'; 4 | 5 | describe('CheckUpdateBottomSheetComponent', () => { 6 | let component: CheckUpdateBottomSheetComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ CheckUpdateBottomSheetComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(CheckUpdateBottomSheetComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /src/app/user/login/duplicate-verification-dialog/duplicate-verification-dialog.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { DuplicateVerificationDialogComponent } from './duplicate-verification-dialog.component'; 4 | 5 | describe('DuplicateVerificationDialogComponent', () => { 6 | let component: DuplicateVerificationDialogComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ DuplicateVerificationDialogComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(DuplicateVerificationDialogComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/app/user/model/department-employee.ts: -------------------------------------------------------------------------------- 1 | import { Department } from './department'; 2 | import { User } from './user'; 3 | 4 | export class DepartmentEmployee { 5 | private _id; number; 6 | private _department: Department; 7 | private _employee: User; 8 | 9 | public get id(): number { 10 | return this._id; 11 | } 12 | public set id(value: number) { 13 | this._id = value; 14 | } 15 | 16 | public get department(): Department { 17 | return this._department; 18 | } 19 | public set department(value: Department) { 20 | if (value.id == 0) 21 | this._department = null; 22 | 23 | this._department = Object.assign(new Department(), value) 24 | } 25 | 26 | public get employee(): User { 27 | return this._employee; 28 | } 29 | public set employee(value: User) { 30 | if (value.id == 0) 31 | this._employee = null; 32 | 33 | this._employee = Object.assign(new User(), value) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 臺中市政府秘書處 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/tiwenpass'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | })); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'tiwenpass'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.componentInstance; 26 | expect(app.title).toEqual('tiwenpass'); 27 | }); 28 | 29 | it('should render title', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.nativeElement; 33 | expect(compiled.querySelector('.content span').textContent).toContain('tiwenpass app is running!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /src/app/qr/scan/guest-register-dialog/guest-register-dialog.component.html: -------------------------------------------------------------------------------- 1 | 4 | 5 |

第一次進行身分驗證,需先完成資料登錄

6 | 28 | -------------------------------------------------------------------------------- /src/app/auth.guard.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router'; 3 | import { Observable } from 'rxjs'; 4 | 5 | import { UserService } from './user/user.service'; 6 | import { UserType } from './user/model/user'; 7 | 8 | @Injectable({ 9 | providedIn: 'root' 10 | }) 11 | export class AuthGuard implements CanActivate { 12 | constructor( 13 | private router: Router, 14 | private userService: UserService, 15 | ) {} 16 | 17 | canActivate( 18 | next: ActivatedRouteSnapshot, 19 | state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { 20 | 21 | const currentUser = this.userService.currentUser; 22 | if (!currentUser) { 23 | console.log('必須先登入使用者'); 24 | 25 | this.userService.redirectUrl = state.url; 26 | this.router.navigate(['/login']); 27 | 28 | return false; 29 | } 30 | 31 | if (state.url === '/qr/scan') 32 | return currentUser.type == UserType.Employee; 33 | 34 | if (state.url === '/qr/show') 35 | return currentUser.type == UserType.Guest || 36 | currentUser.type == UserType.Employee; 37 | 38 | return true; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/manifest.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "臺中市政府防疫追蹤溯源實名登記", 3 | "short_name": "防疫實名登記", 4 | "theme_color": "#1976d2", 5 | "background_color": "#fafafa", 6 | "display": "standalone", 7 | "scope": "./", 8 | "start_url": "./", 9 | "icons": [ 10 | { 11 | "src": "assets/icons/icon-72x72.png", 12 | "sizes": "72x72", 13 | "type": "image/png" 14 | }, 15 | { 16 | "src": "assets/icons/icon-96x96.png", 17 | "sizes": "96x96", 18 | "type": "image/png" 19 | }, 20 | { 21 | "src": "assets/icons/icon-128x128.png", 22 | "sizes": "128x128", 23 | "type": "image/png" 24 | }, 25 | { 26 | "src": "assets/icons/icon-144x144.png", 27 | "sizes": "144x144", 28 | "type": "image/png" 29 | }, 30 | { 31 | "src": "assets/icons/icon-152x152.png", 32 | "sizes": "152x152", 33 | "type": "image/png" 34 | }, 35 | { 36 | "src": "assets/icons/icon-192x192.png", 37 | "sizes": "192x192", 38 | "type": "image/png" 39 | }, 40 | { 41 | "src": "assets/icons/icon-384x384.png", 42 | "sizes": "384x384", 43 | "type": "image/png" 44 | }, 45 | { 46 | "src": "assets/icons/icon-512x512.png", 47 | "sizes": "512x512", 48 | "type": "image/png" 49 | } 50 | ] 51 | } -------------------------------------------------------------------------------- /src/app/qr/models/tcpass-visit.ts: -------------------------------------------------------------------------------- 1 | import { Location } from './location'; 2 | import { DepartmentEmployee } from '../../user/model/department-employee'; 3 | 4 | export class TcpassVisit { 5 | private _id: number; 6 | private _uuid: string; 7 | private _department_employee: DepartmentEmployee; 8 | private _location: Location; 9 | 10 | public get id(): number { 11 | return this._id; 12 | } 13 | public set id(value: number) { 14 | this._id = value; 15 | } 16 | 17 | public get uuid(): string { 18 | return this._uuid; 19 | } 20 | public set uuid(value: string) { 21 | this._uuid = value; 22 | } 23 | 24 | public get department_employee(): DepartmentEmployee { 25 | return this._department_employee; 26 | } 27 | public set department_employee(value: DepartmentEmployee) { 28 | if (value.id == 0) 29 | this._department_employee = null; 30 | 31 | this._department_employee = Object.assign(new DepartmentEmployee(), value) 32 | } 33 | 34 | public get location(): Location { 35 | return this._location; 36 | } 37 | public set location(value: Location) { 38 | if (value.id == 0) 39 | this._location = null; 40 | 41 | this._location = Object.assign(new Location(), value) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 2 | import { BrowserModule } from '@angular/platform-browser'; 3 | import { FlexLayoutModule } from '@angular/flex-layout'; 4 | import { HttpClientModule } from '@angular/common/http'; 5 | import { MatBottomSheetModule } from '@angular/material/bottom-sheet'; 6 | import { MatListModule } from '@angular/material/list'; 7 | import { NgModule } from '@angular/core'; 8 | import { ServiceWorkerModule } from '@angular/service-worker'; 9 | 10 | import { AppRoutingModule } from './app-routing.module'; 11 | import { QrModule } from './qr/qr.module'; 12 | import { UserModule } from './user/user.module'; 13 | 14 | import { AppComponent } from './app.component'; 15 | 16 | import { environment } from '../environments/environment'; 17 | import { CheckUpdateBottomSheetComponent } from './check-update-bottom-sheet/check-update-bottom-sheet.component'; 18 | 19 | @NgModule({ 20 | declarations: [ 21 | AppComponent, 22 | CheckUpdateBottomSheetComponent, 23 | ], 24 | imports: [ 25 | BrowserAnimationsModule, 26 | BrowserModule, 27 | FlexLayoutModule, 28 | HttpClientModule, 29 | MatBottomSheetModule, 30 | MatListModule, 31 | ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production }), 32 | AppRoutingModule, 33 | QrModule, 34 | UserModule, 35 | ], 36 | providers: [], 37 | bootstrap: [AppComponent], 38 | }) 39 | export class AppModule { } 40 | -------------------------------------------------------------------------------- /src/app/user/model/employee.ts: -------------------------------------------------------------------------------- 1 | import { Department } from './department'; 2 | 3 | export class Employee { 4 | private _user_id: number; 5 | private _name: string; 6 | private _account: string; 7 | private _title: string; 8 | private _departments: Department[]; 9 | 10 | public get user_id(): number { 11 | return this._user_id; 12 | } 13 | public set user_id(value: number) { 14 | this._user_id = value; 15 | } 16 | 17 | public get name(): string { 18 | return this._name; 19 | } 20 | public set name(value: string) { 21 | this._name = value; 22 | } 23 | 24 | public get account(): string { 25 | return this._account; 26 | } 27 | public set account(value: string) { 28 | this._account = value; 29 | } 30 | 31 | public get title(): string { 32 | return this._title; 33 | } 34 | public set title(value: string) { 35 | this._title = value; 36 | } 37 | 38 | public get departments(): Department[] { 39 | return this._departments; 40 | } 41 | public set departments(value: Department[]) { 42 | const departments: Department[] = new Array(); 43 | if (value != null) { 44 | for (const department of value) { 45 | departments.push(Object.assign(new Department(), department)); 46 | } 47 | } 48 | 49 | this._departments = departments; 50 | } 51 | 52 | public currentDepartment(): Department { 53 | return this._departments[this._departments.length-1]; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/app/qr/scan/scan-success-dialog/scan-success-dialog.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Inject, OnInit } from '@angular/core'; 2 | import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; 3 | import { timer } from 'rxjs'; 4 | import { map, takeWhile } from 'rxjs/operators'; 5 | 6 | import { Visit } from '../../models/visit'; 7 | import { TcpassVisit } from '../../models/tcpass-visit'; 8 | 9 | @Component({ 10 | selector: 'app-scan-success-dialog', 11 | templateUrl: './scan-success-dialog.component.html', 12 | styleUrls: ['./scan-success-dialog.component.scss'] 13 | }) 14 | export class ScanSuccessDialogComponent implements OnInit { 15 | closeTime: number = 0; 16 | isTcpass: boolean; 17 | visit: Visit; 18 | tcpass: TcpassVisit; 19 | 20 | constructor( 21 | public dialogRef: MatDialogRef, 22 | @Inject(MAT_DIALOG_DATA) public data: Visit | TcpassVisit, 23 | ) { 24 | if (data instanceof Visit) { 25 | this.isTcpass = false; 26 | this.visit = data; 27 | } else { 28 | this.isTcpass = true; 29 | this.tcpass = data; 30 | } 31 | } 32 | 33 | ngOnInit() { 34 | this.closeTime = 1; 35 | 36 | timer(1000, 1000).pipe( 37 | takeWhile(() => this.closeTime > 0), 38 | map(() => this.closeTime--) 39 | ).subscribe({ 40 | next: (value) => console.log(`closeTime: ${this.closeTime}`), 41 | error: (err) => console.error(err), 42 | complete: () => { 43 | console.log('Close Dialog') 44 | 45 | this.dialogRef.close(); 46 | } 47 | }); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, ApplicationRef } from '@angular/core'; 2 | import { MatBottomSheet } from '@angular/material/bottom-sheet'; 3 | import { SwUpdate } from '@angular/service-worker'; 4 | import { interval, concat } from 'rxjs'; 5 | import { first } from 'rxjs/operators'; 6 | 7 | import { CheckUpdateBottomSheetComponent } from './check-update-bottom-sheet/check-update-bottom-sheet.component'; 8 | 9 | @Component({ 10 | selector: 'app-root', 11 | templateUrl: './app.component.html', 12 | styleUrls: ['./app.component.scss'] 13 | }) 14 | export class AppComponent { 15 | constructor( 16 | private appRef: ApplicationRef, 17 | private bottomSheet: MatBottomSheet, 18 | private updates: SwUpdate) 19 | { 20 | if (updates.isEnabled) { 21 | const appIsStable$ = appRef.isStable.pipe(first(isStable => isStable === true)); 22 | const checkInterval$ = interval(1 * 10 * 60 * 1000); 23 | const checkAppIsStableAtInterval$ = concat(appIsStable$, checkInterval$); 24 | 25 | checkAppIsStableAtInterval$.subscribe(() => { 26 | console.log('Service worker 檢查更新'); 27 | updates.checkForUpdate(); 28 | }); 29 | 30 | updates.available.subscribe((event) => { 31 | console.log('Service worker 有新的版本'); 32 | 33 | const bottomSheetRef = this.bottomSheet.open(CheckUpdateBottomSheetComponent); 34 | 35 | bottomSheetRef.afterDismissed().subscribe( 36 | () => window.location.reload() 37 | ); 38 | }); 39 | } else { 40 | console.log('不支援 Service worker'); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/app/user/user.module.ts: -------------------------------------------------------------------------------- 1 | import { CommonModule } from '@angular/common'; 2 | import { NgModule } from '@angular/core'; 3 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 4 | import { FlexLayoutModule } from '@angular/flex-layout'; 5 | import { MatButtonModule } from '@angular/material/button'; 6 | import { MatCardModule } from '@angular/material/card'; 7 | import { MatDialogModule } from '@angular/material/dialog'; 8 | import { MatExpansionModule } from '@angular/material/expansion'; 9 | import { MatInputModule } from '@angular/material/input'; 10 | import { MatIconModule } from '@angular/material/icon'; 11 | import { MatTabsModule } from '@angular/material/tabs'; 12 | import { MatSnackBarModule } from '@angular/material/snack-bar'; 13 | import { UserRoutingModule } from './user-routing.module'; 14 | import { SvgModule } from '../svg/svg.module'; 15 | 16 | import { LoginComponent } from './login/login.component'; 17 | import { DuplicateVerificationDialogComponent } from './login/duplicate-verification-dialog/duplicate-verification-dialog.component'; 18 | 19 | @NgModule({ 20 | declarations: [ 21 | LoginComponent, 22 | DuplicateVerificationDialogComponent, 23 | ], 24 | imports: [ 25 | CommonModule, 26 | FormsModule, 27 | ReactiveFormsModule, 28 | FlexLayoutModule, 29 | MatButtonModule, 30 | MatCardModule, 31 | MatDialogModule, 32 | MatExpansionModule, 33 | MatInputModule, 34 | MatIconModule, 35 | MatTabsModule, 36 | MatSnackBarModule, 37 | UserRoutingModule, 38 | SvgModule, 39 | ], 40 | }) 41 | export class UserModule { } 42 | -------------------------------------------------------------------------------- /src/app/qr/models/location.ts: -------------------------------------------------------------------------------- 1 | export class Building { 2 | private _id: number; 3 | private _building: string; 4 | private _locations: Location[]; 5 | 6 | public get id(): number { 7 | return this._id; 8 | } 9 | public set id(value: number) { 10 | this._id = value; 11 | } 12 | 13 | public get building(): string { 14 | return this._building; 15 | } 16 | public set building(value: string) { 17 | this._building = value; 18 | } 19 | 20 | public get locations(): Location[] { 21 | return this._locations; 22 | } 23 | public set locations(value: Location[]) { 24 | const locations: Location[] = new Array(); 25 | if (value != null) { 26 | for (const location of value) { 27 | locations.push(Object.assign(new Location(), location)); 28 | } 29 | } 30 | 31 | this._locations = locations; 32 | } 33 | } 34 | 35 | export class Location { 36 | private _id: number; 37 | private _location: string; 38 | private _building: Building; 39 | 40 | public get id(): number { 41 | return this._id; 42 | } 43 | public set id(value: number) { 44 | this._id = value; 45 | } 46 | 47 | public get location(): string { 48 | return this._location; 49 | } 50 | public set location(value: string) { 51 | this._location = value; 52 | } 53 | 54 | public get building(): Building { 55 | return this._building; 56 | } 57 | public set building(value: Building) { 58 | if (value.id == 0) 59 | this._building = null; 60 | 61 | this._building = Object.assign(new Building(), value) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tiwenpass", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "^10.2.5", 15 | "@angular/cdk": "^10.2.7", 16 | "@angular/common": "^10.2.5", 17 | "@angular/compiler": "^10.2.5", 18 | "@angular/core": "^10.2.5", 19 | "@angular/flex-layout": "^10.0.0-beta.32", 20 | "@angular/forms": "^10.2.5", 21 | "@angular/material": "^10.2.7", 22 | "@angular/platform-browser": "^10.2.5", 23 | "@angular/platform-browser-dynamic": "^10.2.5", 24 | "@angular/router": "^10.2.5", 25 | "@angular/service-worker": "^10.2.5", 26 | "@zxing/ngx-scanner": "^3.1.3", 27 | "jsencrypt": "^3.1.0", 28 | "rxjs": "~6.6.7", 29 | "taiwan-id-validator2": "^0.2.0", 30 | "tslib": "^2.1.0", 31 | "zone.js": "~0.10.3" 32 | }, 33 | "devDependencies": { 34 | "@angular-devkit/build-angular": "^0.1002.3", 35 | "@angular/cli": "^10.2.3", 36 | "@angular/compiler-cli": "^10.2.5", 37 | "@angular/language-service": "^10.2.5", 38 | "@types/jasmine": "^3.6.2", 39 | "@types/jasminewd2": "~2.0.3", 40 | "@types/node": "^12.19.12", 41 | "codelyzer": "^5.2.2", 42 | "jasmine-core": "~3.5.0", 43 | "jasmine-spec-reporter": "~5.0.0", 44 | "karma": "~6.3.2", 45 | "karma-chrome-launcher": "~3.1.0", 46 | "karma-coverage-istanbul-reporter": "~3.0.2", 47 | "karma-jasmine": "~3.3.0", 48 | "karma-jasmine-html-reporter": "^1.5.0", 49 | "protractor": "~7.0.0", 50 | "ts-node": "~8.3.0", 51 | "tslint": "^6.1.3", 52 | "typescript": "^3.9.7" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/app/user/model/guest.ts: -------------------------------------------------------------------------------- 1 | export class Guest { 2 | private _user_id: number; 3 | private _name: string; 4 | private _phone: string; 5 | private _phone_verify: boolean; 6 | private _phone_token: string; 7 | private _phone_otp: string; 8 | private _id_card: string; 9 | private _id_card_verify: boolean; 10 | 11 | public get user_id(): number { 12 | return this._user_id; 13 | } 14 | public set user_id(value: number) { 15 | this._user_id = value; 16 | } 17 | 18 | public get name(): string { 19 | return this._name; 20 | } 21 | public set name(value: string) { 22 | this._name = value; 23 | } 24 | 25 | public get phone(): string { 26 | return this._phone; 27 | } 28 | public set phone(value: string) { 29 | this._phone = value; 30 | } 31 | 32 | public get phone_verify(): boolean { 33 | return this._phone_verify; 34 | } 35 | public set phone_verify(value: boolean) { 36 | this._phone_verify = value; 37 | } 38 | 39 | public get phone_token(): string { 40 | return this._phone_token; 41 | } 42 | public set phone_token(value: string) { 43 | this._phone_token = value; 44 | } 45 | 46 | public get phone_otp(): string { 47 | return this._phone_otp; 48 | } 49 | public set phone_otp(value: string) { 50 | this._phone_otp = value; 51 | } 52 | 53 | public get id_card(): string { 54 | return this._id_card; 55 | } 56 | public set id_card(value: string) { 57 | this._id_card = value; 58 | } 59 | 60 | public get id_card_verify(): boolean { 61 | return this._id_card_verify; 62 | } 63 | public set id_card_verify(value: boolean) { 64 | this._id_card_verify = value; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/app/user/model/user.ts: -------------------------------------------------------------------------------- 1 | import { Employee } from './employee'; 2 | import { Guest } from './guest'; 3 | import { Token } from './token'; 4 | 5 | export enum UserType { 6 | Employee = 0, 7 | Guest = 1 8 | } 9 | 10 | export class User { 11 | private _id: number; 12 | private _username: string; 13 | private _name: string; 14 | private _type: UserType; 15 | private _employee: Employee; 16 | private _guest: Guest; 17 | private _token: Token; 18 | 19 | public get id(): number { 20 | return this._id; 21 | } 22 | public set id(value: number) { 23 | this._id = value; 24 | } 25 | 26 | public get username(): string { 27 | return this._username; 28 | } 29 | public set username(value: string) { 30 | this._username = value; 31 | } 32 | 33 | public get name(): string { 34 | return this._name; 35 | } 36 | public set name(value: string) { 37 | this._name = value; 38 | } 39 | 40 | public get type(): UserType { 41 | return this._type; 42 | } 43 | public set type(value: UserType) { 44 | this._type = value; 45 | } 46 | 47 | public get employee(): Employee { 48 | return this._employee; 49 | } 50 | public set employee(value: Employee) { 51 | if (value.user_id == 0) 52 | this._employee = null; 53 | 54 | this._employee = Object.assign(new Employee(), value); 55 | } 56 | 57 | public get guest(): Guest { 58 | return this._guest; 59 | } 60 | public set guest(value: Guest) { 61 | if (value.user_id == 0) 62 | this._guest = null; 63 | 64 | this._guest = Object.assign(new Guest(), value); 65 | } 66 | 67 | public get token(): Token { 68 | return this._token; 69 | } 70 | public set token(value: Token) { 71 | this._token = Object.assign(new Token(), value); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/app/qr/models/visit.ts: -------------------------------------------------------------------------------- 1 | import { Location } from './location'; 2 | import { Follower } from './follower'; 3 | import { User } from '../../user/model/user'; 4 | import { DepartmentEmployee } from '../../user/model/department-employee'; 5 | 6 | export class Visit { 7 | private _id: number; 8 | private _guest: User; 9 | private _department_employee: DepartmentEmployee; 10 | private _location: Location; 11 | private _followers: Follower[]; 12 | 13 | public get id(): number { 14 | return this._id; 15 | } 16 | public set id(value: number) { 17 | this._id = value; 18 | } 19 | 20 | public get guest(): User { 21 | return this._guest; 22 | } 23 | public set guest(value: User) { 24 | if (value.id == 0) 25 | this._guest = null; 26 | 27 | this._guest = Object.assign(new User(), value) 28 | } 29 | 30 | public get department_employee(): DepartmentEmployee { 31 | return this._department_employee; 32 | } 33 | public set department_employee(value: DepartmentEmployee) { 34 | if (value.id == 0) 35 | this._department_employee = null; 36 | 37 | this._department_employee = Object.assign(new DepartmentEmployee(), value) 38 | } 39 | 40 | public get location(): Location { 41 | return this._location; 42 | } 43 | public set location(value: Location) { 44 | if (value.id == 0) 45 | this._location = null; 46 | 47 | this._location = Object.assign(new Location(), value) 48 | } 49 | 50 | public get followers(): Follower[] { 51 | return this._followers; 52 | } 53 | public set followers(value: Follower[]) { 54 | const followers: Follower[] = new Array(); 55 | if (value != null) { 56 | for (const follower of value) { 57 | followers.push(Object.assign(new Follower(), follower)); 58 | } 59 | } 60 | 61 | this._followers = followers; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/app/qr/qr.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 4 | import { FlexLayoutModule } from '@angular/flex-layout'; 5 | import { ZXingScannerModule } from '@zxing/ngx-scanner'; 6 | import { QrRoutingModule } from './qr-routing.module'; 7 | 8 | import { MatAutocompleteModule } from '@angular/material/autocomplete'; 9 | import { MatButtonModule } from '@angular/material/button'; 10 | import { MatCardModule } from '@angular/material/card'; 11 | import { MatChipsModule } from '@angular/material/chips'; 12 | import { MatDialogModule } from '@angular/material/dialog'; 13 | import { MatInputModule } from '@angular/material/input'; 14 | import { MatIconModule } from '@angular/material/icon'; 15 | import { MatMenuModule } from '@angular/material/menu'; 16 | import { MatSelectModule } from '@angular/material/select'; 17 | import { MatSnackBarModule } from '@angular/material/snack-bar'; 18 | import { MatToolbarModule } from '@angular/material/toolbar'; 19 | import { MatTooltipModule } from '@angular/material/tooltip'; 20 | 21 | import { ScanComponent } from './scan/scan.component'; 22 | import { ShowComponent } from './show/show.component'; 23 | import { GuestRegisterDialogComponent } from './scan/guest-register-dialog/guest-register-dialog.component'; 24 | import { ScanSuccessDialogComponent } from './scan/scan-success-dialog/scan-success-dialog.component'; 25 | 26 | @NgModule({ 27 | declarations: [ 28 | ScanComponent, 29 | ShowComponent, 30 | GuestRegisterDialogComponent, 31 | ScanSuccessDialogComponent, 32 | ], 33 | imports: [ 34 | CommonModule, 35 | FormsModule, 36 | ReactiveFormsModule, 37 | FlexLayoutModule, 38 | ZXingScannerModule, 39 | QrRoutingModule, 40 | MatAutocompleteModule, 41 | MatCardModule, 42 | MatChipsModule, 43 | MatButtonModule, 44 | MatDialogModule, 45 | MatIconModule, 46 | MatInputModule, 47 | MatMenuModule, 48 | MatSelectModule, 49 | MatSnackBarModule, 50 | MatToolbarModule, 51 | MatTooltipModule, 52 | ] 53 | }) 54 | export class QrModule { } 55 | -------------------------------------------------------------------------------- /src/app/qr/show/show.component.html: -------------------------------------------------------------------------------- 1 | 2 | QR Code ({{ qrCreatedDate | date: 'yyyy/MM/dd' }}) 3 | 4 | 8 | 9 | 15 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 32 | {{ follower }} 33 | cancel 34 | 35 | 41 | 42 | 43 | 44 | {{ follower }} 45 | 46 | 47 | 48 | 52 | 53 | 54 |
55 | 56 | 60 | 61 | 62 | home 63 | 台中e指通 64 | 65 | 66 | -------------------------------------------------------------------------------- /src/app/qr/scan/scan.component.html: -------------------------------------------------------------------------------- 1 | 2 | Scanner 3 | 4 | 8 | 9 | 13 | 17 | 18 | 19 |
20 | 21 |
22 | 23 | 24 | 26 | 27 | {{ location.location }} 28 | 29 | 30 | 31 | 32 | 33 | 37 | 38 | 42 | 43 |
44 | 45 | 51 | 52 | 條碼輸入 53 | 54 | 註:可直接輸入身分(或居留)證號後按Enter 55 | 56 | 57 | 58 | 61 | 64 | 65 |
66 |
-------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /src/app/qr/scan/guest-register-dialog/guest-register-dialog.component.ts: -------------------------------------------------------------------------------- 1 | import { HttpErrorResponse } from '@angular/common/http'; 2 | import { Component, Inject, OnInit } from '@angular/core'; 3 | import { FormGroup, FormBuilder, Validators } from '@angular/forms'; 4 | import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; 5 | 6 | import { UserService } from '../../../user/user.service'; 7 | import { Result } from '../../../model/result'; 8 | import { User } from '../../../user/model/user'; 9 | import { Guest } from '../../../user/model/guest'; 10 | 11 | @Component({ 12 | selector: 'app-guest-register-dialog', 13 | templateUrl: './guest-register-dialog.component.html', 14 | styleUrls: ['./guest-register-dialog.component.scss'] 15 | }) 16 | export class GuestRegisterDialogComponent implements OnInit { 17 | 18 | registerGuestUserFormGroup: FormGroup; 19 | 20 | constructor( 21 | public dialogRef: MatDialogRef, 22 | @Inject(MAT_DIALOG_DATA) public data: Guest, 23 | 24 | private formBuilder: FormBuilder, 25 | private userService: UserService 26 | ) { } 27 | 28 | ngOnInit() { 29 | this.registerGuestUserFormGroup = this.formBuilder.group({ 30 | id_card: [ 31 | null, 32 | Validators.required 33 | ], 34 | name: [ 35 | null, 36 | [Validators.required, Validators.pattern("[\u4e00-\u9fa5.]{2,}")] 37 | ], 38 | phone: [ 39 | null, 40 | [Validators.required, Validators.pattern("0[0-9]{8,9}")] 41 | ] 42 | }); 43 | 44 | this.registerGuestUserFormGroup.get("id_card").disable(); 45 | this.registerGuestUserFormGroup.get("id_card").setValue(this.data.id_card); 46 | 47 | this.registerGuestUserFormGroup.get("name").setValue(this.data.name); 48 | } 49 | 50 | registerGuestUser(name: string, phone: string, id_card: string) { 51 | this.userService.registerGuestUser(name, phone, id_card) 52 | .subscribe({ 53 | next: (value) => this.registerGuestUserResultHandler(value), 54 | error: (err) => this.faultHandler(err) 55 | }); 56 | } 57 | 58 | verifyGuestUserIDCard(user: User) { 59 | this.userService.verifyGuestUserIDCard(user) 60 | .subscribe({ 61 | next: (value) => this.verifyGuestUserIDCardHandler(value), 62 | error: (err) => this.faultHandler(err) 63 | }); 64 | } 65 | 66 | private registerGuestUserResultHandler(result: Result) { 67 | const user: User = Object.assign(new User(), result.data); 68 | 69 | this.verifyGuestUserIDCard(user); 70 | } 71 | 72 | private verifyGuestUserIDCardHandler(result: Result) { 73 | const user: User = Object.assign(new User(), result.data); 74 | 75 | this.dialogRef.close(user); 76 | } 77 | 78 | private faultHandler(error: HttpErrorResponse) { 79 | let failureResult: Result; 80 | let info = error.statusText; 81 | 82 | if ((error.status === 401) || (error.status === 422)) { 83 | failureResult = Object.assign(new Result(), error.error); 84 | info = failureResult.info[0]; 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "align": { 5 | "options": [ 6 | "parameters", 7 | "statements" 8 | ] 9 | }, 10 | "array-type": false, 11 | "arrow-parens": false, 12 | "arrow-return-shorthand": true, 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warning" 16 | }, 17 | "component-class-suffix": true, 18 | "contextual-lifecycle": true, 19 | "directive-class-suffix": true, 20 | "directive-selector": [ 21 | true, 22 | "attribute", 23 | "app", 24 | "camelCase" 25 | ], 26 | "component-selector": [ 27 | true, 28 | "element", 29 | "app", 30 | "kebab-case" 31 | ], 32 | "eofline": true, 33 | "import-blacklist": [ 34 | true, 35 | "rxjs/Rx" 36 | ], 37 | "import-spacing": true, 38 | "indent": { 39 | "options": [ 40 | "spaces" 41 | ] 42 | }, 43 | "interface-name": false, 44 | "max-classes-per-file": false, 45 | "max-line-length": [ 46 | true, 47 | 140 48 | ], 49 | "member-access": false, 50 | "member-ordering": [ 51 | true, 52 | { 53 | "order": [ 54 | "static-field", 55 | "instance-field", 56 | "static-method", 57 | "instance-method" 58 | ] 59 | } 60 | ], 61 | "no-consecutive-blank-lines": false, 62 | "no-console": [ 63 | true, 64 | "debug", 65 | "info", 66 | "time", 67 | "timeEnd", 68 | "trace" 69 | ], 70 | "no-empty": false, 71 | "no-inferrable-types": [ 72 | true, 73 | "ignore-params" 74 | ], 75 | "no-non-null-assertion": true, 76 | "no-redundant-jsdoc": true, 77 | "no-switch-case-fall-through": true, 78 | "no-var-requires": false, 79 | "object-literal-key-quotes": [ 80 | true, 81 | "as-needed" 82 | ], 83 | "object-literal-sort-keys": false, 84 | "ordered-imports": false, 85 | "quotemark": [ 86 | true, 87 | "single" 88 | ], 89 | "semicolon": { 90 | "options": [ 91 | "always" 92 | ] 93 | }, 94 | "space-before-function-paren": { 95 | "options": { 96 | "anonymous": "never", 97 | "asyncArrow": "always", 98 | "constructor": "never", 99 | "method": "never", 100 | "named": "never" 101 | } 102 | }, 103 | "trailing-comma": false, 104 | "no-conflicting-lifecycle": true, 105 | "no-host-metadata-property": true, 106 | "no-input-rename": true, 107 | "no-inputs-metadata-property": true, 108 | "no-output-native": true, 109 | "no-output-on-prefix": true, 110 | "no-output-rename": true, 111 | "no-outputs-metadata-property": true, 112 | "template-banana-in-box": true, 113 | "template-no-negated-async": true, 114 | "typedef-whitespace": { 115 | "options": [ 116 | { 117 | "call-signature": "nospace", 118 | "index-signature": "nospace", 119 | "parameter": "nospace", 120 | "property-declaration": "nospace", 121 | "variable-declaration": "nospace" 122 | }, 123 | { 124 | "call-signature": "onespace", 125 | "index-signature": "onespace", 126 | "parameter": "onespace", 127 | "property-declaration": "onespace", 128 | "variable-declaration": "onespace" 129 | } 130 | ] 131 | }, 132 | "use-lifecycle-interface": true, 133 | "use-pipe-transform-interface": true 134 | , "variable-name": { 135 | "options": [ 136 | "ban-keywords", 137 | "check-format", 138 | "allow-pascal-case" 139 | ] 140 | }, 141 | "whitespace": { 142 | "options": [ 143 | "check-branch", 144 | "check-decl", 145 | "check-operator", 146 | "check-separator", 147 | "check-type", 148 | "check-typecast" 149 | ] 150 | } 151 | }, 152 | "rulesDirectory": [ 153 | "codelyzer" 154 | ] 155 | } -------------------------------------------------------------------------------- /src/app/user/user.service.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient, HttpHeaders } from '@angular/common/http'; 2 | import { Injectable } from '@angular/core'; 3 | import { Observable } from 'rxjs'; 4 | import { map } from 'rxjs/operators'; 5 | 6 | import { environment } from '../../environments/environment'; 7 | import { Result } from '../model/result'; 8 | import { User, UserType } from './model/user'; 9 | import { Guest } from './model/guest'; 10 | import { Token } from './model/token'; 11 | 12 | @Injectable({ 13 | providedIn: 'root' 14 | }) 15 | export class UserService { 16 | private static _currentUser: User; 17 | private static _redirectUrl: string; 18 | 19 | private baseUrl = environment.baseUrl; 20 | 21 | constructor( 22 | private http: HttpClient 23 | ) { } 24 | 25 | loginTccgUser(account: string, password: string): Observable> { 26 | const params = { 27 | 'username': account, 28 | 'password': password, 29 | 'type': UserType.Employee 30 | }; 31 | 32 | return this.http.patch(this.baseUrl + '/api/v1/users/tccg/login', params).pipe( 33 | map((value: Result) => Object.assign(new Result(), value)) 34 | ); 35 | } 36 | 37 | loginGuestUser(phone_token: string): Observable> { 38 | const params = { 39 | 'username': "0987587487", 40 | 'password': phone_token, 41 | 'type': UserType.Guest 42 | }; 43 | 44 | return this.http.patch(this.baseUrl + '/api/v1/guests/login', params).pipe( 45 | map((value: Result) => Object.assign(new Result(), value)) 46 | ); 47 | } 48 | 49 | refreshToken(): Observable> { 50 | return this.http.patch(this.baseUrl + '/api/v1/auth/refresh_token', null, { 51 | headers: new HttpHeaders().set('Authorization', `Bearer ${this.token.token}`) 52 | }).pipe( 53 | map((value: Result) => Object.assign(new Result(), value)) 54 | ); 55 | } 56 | 57 | registerGuestUser(name: string, phone: string, id_card?: string): Observable> { 58 | const params = { 59 | 'name': name, 60 | 'phone': phone, 61 | 'id_card': id_card 62 | }; 63 | 64 | return this.http.post(this.baseUrl + '/api/v1/guests/register', params).pipe( 65 | map((value: Result) => Object.assign(new Result(), value)) 66 | ); 67 | } 68 | 69 | verifyGuestUserIDCard(user: User): Observable> { 70 | return this.http.patch(this.baseUrl + `/api/v1/guests/verify/${user.id}/idcard`, null, { 71 | headers: new HttpHeaders().set('Authorization', `Bearer ${this.token.token}`) 72 | }).pipe( 73 | map((value: Result) => Object.assign(new Result(), value)) 74 | ); 75 | } 76 | 77 | sendGuestPhoneOTP(user_id: number, phone: string): Observable> { 78 | const params = { 79 | 'user_id': user_id, 80 | 'phone': phone 81 | }; 82 | 83 | return this.http.patch(this.baseUrl + '/api/v1/guests/register/phone/otp', params).pipe( 84 | map((value: Result) => Object.assign(new Result(), value)) 85 | ); 86 | } 87 | 88 | verifyGuestUserPhoneOTP(guest: Guest): Observable> { 89 | // const params = guest; 90 | const params = { 91 | 'user_id': guest.user_id, 92 | 'phone': guest.phone, 93 | 'phone_otp': guest.phone_otp 94 | } 95 | 96 | return this.http.patch(this.baseUrl + '/api/v1/guests/register/phone/otp/verify', params).pipe( 97 | map((value: Result) => Object.assign(new Result(), value)) 98 | ); 99 | } 100 | 101 | public get currentUser(): User { 102 | return UserService._currentUser; 103 | } 104 | public set currentUser(value: User) { 105 | UserService._currentUser = value; 106 | } 107 | 108 | public get token(): Token { 109 | return this.currentUser.token; 110 | } 111 | public set token(value: Token) { 112 | this.currentUser.token = value; 113 | } 114 | 115 | public get redirectUrl(): string { 116 | return UserService._redirectUrl; 117 | } 118 | public set redirectUrl(value: string) { 119 | UserService._redirectUrl = value; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "tiwenpass": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:component": { 10 | "style": "scss" 11 | } 12 | }, 13 | "root": "", 14 | "sourceRoot": "src", 15 | "prefix": "app", 16 | "architect": { 17 | "build": { 18 | "builder": "@angular-devkit/build-angular:browser", 19 | "options": { 20 | "outputPath": "dist/tiwenpass", 21 | "index": "src/index.html", 22 | "main": "src/main.ts", 23 | "polyfills": "src/polyfills.ts", 24 | "tsConfig": "tsconfig.app.json", 25 | "aot": true, 26 | "assets": [ 27 | "src/favicon.ico", 28 | "src/assets", 29 | "src/manifest.webmanifest" 30 | ], 31 | "styles": [ 32 | "src/styles.scss" 33 | ], 34 | "scripts": [] 35 | }, 36 | "configurations": { 37 | "production": { 38 | "fileReplacements": [ 39 | { 40 | "replace": "src/environments/environment.ts", 41 | "with": "src/environments/environment.prod.ts" 42 | } 43 | ], 44 | "optimization": true, 45 | "outputHashing": "all", 46 | "sourceMap": false, 47 | "extractCss": true, 48 | "namedChunks": false, 49 | "extractLicenses": true, 50 | "vendorChunk": false, 51 | "buildOptimizer": true, 52 | "budgets": [ 53 | { 54 | "type": "initial", 55 | "maximumWarning": "2mb", 56 | "maximumError": "5mb" 57 | }, 58 | { 59 | "type": "anyComponentStyle", 60 | "maximumWarning": "6kb", 61 | "maximumError": "10kb" 62 | } 63 | ], 64 | "serviceWorker": true, 65 | "ngswConfigPath": "ngsw-config.json" 66 | } 67 | } 68 | }, 69 | "serve": { 70 | "builder": "@angular-devkit/build-angular:dev-server", 71 | "options": { 72 | "browserTarget": "tiwenpass:build" 73 | }, 74 | "configurations": { 75 | "production": { 76 | "browserTarget": "tiwenpass:build:production" 77 | } 78 | } 79 | }, 80 | "extract-i18n": { 81 | "builder": "@angular-devkit/build-angular:extract-i18n", 82 | "options": { 83 | "browserTarget": "tiwenpass:build" 84 | } 85 | }, 86 | "test": { 87 | "builder": "@angular-devkit/build-angular:karma", 88 | "options": { 89 | "main": "src/test.ts", 90 | "polyfills": "src/polyfills.ts", 91 | "tsConfig": "tsconfig.spec.json", 92 | "karmaConfig": "karma.conf.js", 93 | "assets": [ 94 | "src/favicon.ico", 95 | "src/assets", 96 | "src/manifest.webmanifest" 97 | ], 98 | "styles": [ 99 | "src/styles.scss" 100 | ], 101 | "scripts": [] 102 | } 103 | }, 104 | "lint": { 105 | "builder": "@angular-devkit/build-angular:tslint", 106 | "options": { 107 | "tsConfig": [ 108 | "tsconfig.app.json", 109 | "tsconfig.spec.json", 110 | "e2e/tsconfig.json" 111 | ], 112 | "exclude": [ 113 | "**/node_modules/**" 114 | ] 115 | } 116 | }, 117 | "e2e": { 118 | "builder": "@angular-devkit/build-angular:protractor", 119 | "options": { 120 | "protractorConfig": "e2e/protractor.conf.js", 121 | "devServerTarget": "tiwenpass:serve" 122 | }, 123 | "configurations": { 124 | "production": { 125 | "devServerTarget": "tiwenpass:serve:production" 126 | } 127 | } 128 | } 129 | } 130 | } 131 | }, 132 | "defaultProject": "tiwenpass" 133 | } -------------------------------------------------------------------------------- /src/app/qr/show/show.component.ts: -------------------------------------------------------------------------------- 1 | import { COMMA, ENTER } from '@angular/cdk/keycodes'; 2 | import { Component, ElementRef, ViewChild } from '@angular/core'; 3 | import { FormControl } from '@angular/forms'; 4 | import { MatAutocompleteSelectedEvent, MatAutocomplete } from '@angular/material/autocomplete'; 5 | import { MatSnackBar } from '@angular/material/snack-bar'; 6 | import { SafeUrl } from '@angular/platform-browser'; 7 | import { Router } from '@angular/router'; 8 | import { Observable } from 'rxjs'; 9 | import { map, startWith } from 'rxjs/operators'; 10 | 11 | import { RsaService } from '../rsa.service'; 12 | import { UserService } from '../../user/user.service'; 13 | import { User } from '../../user/model/user'; 14 | 15 | @Component({ 16 | selector: 'app-show', 17 | templateUrl: './show.component.html', 18 | styleUrls: ['./show.component.scss'] 19 | }) 20 | export class ShowComponent { 21 | selectable = true; 22 | removable = true; 23 | separatorKeysCodes: number[] = [ENTER, COMMA]; 24 | followerCtrl = new FormControl(); 25 | filteredFollowers: Observable; 26 | followers: string[] = []; 27 | allFollowers: string[] = []; 28 | 29 | qrCodeImageUrl: Observable; 30 | 31 | @ViewChild('followerInput') followerInput: ElementRef; 32 | @ViewChild('auto') matAutocomplete: MatAutocomplete; 33 | 34 | constructor( 35 | private router: Router, 36 | private snackBar: MatSnackBar, 37 | private rsaService: RsaService, 38 | private userService: UserService 39 | ) { 40 | let allFollowers = JSON.parse(localStorage.getItem("all_followers")); 41 | if ((allFollowers instanceof Array) && (allFollowers.length > 0)) 42 | this.allFollowers = allFollowers; 43 | 44 | let followers = JSON.parse(localStorage.getItem("followers")); 45 | if ((followers instanceof Array) && (followers.length > 0)) 46 | this.followers = followers; 47 | 48 | this.filteredFollowers = this.followerCtrl.valueChanges.pipe( 49 | startWith(null), 50 | map((follower: string | null) => { 51 | let filterFollowers = (follower) ? this._filter(follower) : this.allFollowers.slice(); 52 | return filterFollowers.filter(follower => !this.followers.includes(follower)); 53 | }) 54 | ); 55 | 56 | this.qrCodeImageUrl = this.rsaService.getGuestUserQRCode(this.currentUser.id, this.followers); 57 | } 58 | 59 | addFollower(follower: string) { 60 | if (!this.followers.includes(follower)) { 61 | this.followers.push(follower); 62 | localStorage.setItem("followers", JSON.stringify(this.followers)); 63 | 64 | this.qrCodeImageUrl = this.rsaService.getGuestUserQRCode(this.currentUser.id, this.followers); 65 | } 66 | 67 | if (!this.allFollowers.includes(follower)) { 68 | this.allFollowers.push(follower); 69 | localStorage.setItem("all_followers", JSON.stringify(this.allFollowers)); 70 | } 71 | } 72 | 73 | add(value: string): void { 74 | if ((value || '').trim()) { 75 | let follower = value.trim(); 76 | this.addFollower(follower); 77 | } 78 | 79 | this.followerInput.nativeElement.value = ''; 80 | this.followerCtrl.setValue(null); 81 | } 82 | 83 | remove(follower: string): void { 84 | const index = this.followers.indexOf(follower); 85 | 86 | if (index >= 0) { 87 | this.followers.splice(index, 1); 88 | localStorage.setItem("followers", JSON.stringify(this.followers)); 89 | 90 | this.qrCodeImageUrl = this.rsaService.getGuestUserQRCode(this.currentUser.id, this.followers); 91 | } 92 | 93 | this.followerCtrl.setValue(null); 94 | } 95 | 96 | selected(event: MatAutocompleteSelectedEvent): void { 97 | let follower = event.option.viewValue; 98 | this.addFollower(follower); 99 | 100 | this.followerInput.nativeElement.value = ''; 101 | this.followerCtrl.setValue(null); 102 | } 103 | 104 | private _filter(value: string): string[] { 105 | const filterValue = value.toLowerCase(); 106 | 107 | return this.allFollowers.filter(fruit => fruit.toLowerCase().indexOf(filterValue) === 0); 108 | } 109 | 110 | logout() { 111 | localStorage.removeItem("account"); 112 | localStorage.removeItem("password"); 113 | localStorage.removeItem("phone_token"); 114 | 115 | this.currentUser = null; 116 | this.router.navigate(['/']); 117 | 118 | this.snackBar.open(`帳號已登出`, '確定', { 119 | duration: 2000 120 | }); 121 | } 122 | 123 | switchQRCodeScanner() { 124 | this.router.navigate(['/qr/scan']); 125 | } 126 | 127 | public set currentUser(value: User) { 128 | this.userService.currentUser = value; 129 | } 130 | public get currentUser(): User { 131 | return this.userService.currentUser; 132 | } 133 | 134 | public get qrCreatedDate(): Date { 135 | return this.rsaService.qrCreatedDate; 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/app/qr/rsa.service.ts: -------------------------------------------------------------------------------- 1 | import { DomSanitizer, SafeUrl } from '@angular/platform-browser'; 2 | import { HttpClient, HttpHeaders } from '@angular/common/http'; 3 | import { Injectable } from '@angular/core'; 4 | import { Observable } from 'rxjs'; 5 | import { map } from 'rxjs/operators'; 6 | import * as JsEncryptModule from 'jsencrypt'; 7 | 8 | import { environment } from '../../environments/environment'; 9 | import { UserService } from '../user/user.service'; 10 | import { Result } from '../model/result'; 11 | import { Building, Location } from './models/location'; 12 | import { Department } from '../user/model/department'; 13 | import { Visit } from './models/visit'; 14 | import { TcpassVisit } from './models/tcpass-visit'; 15 | import { Follower } from './models/follower'; 16 | import { NhiUser } from './models/nhi-user'; 17 | 18 | @Injectable({ 19 | providedIn: 'root' 20 | }) 21 | export class RsaService { 22 | private static _redirectUrl: string; 23 | 24 | private baseUrl = environment.baseUrl; 25 | 26 | private jsEncrypt; 27 | private _privkey; 28 | private _qrCraetedDate: Date; 29 | 30 | constructor( 31 | private domSanitizer: DomSanitizer, 32 | private http: HttpClient, 33 | private userService: UserService 34 | ) { 35 | this.jsEncrypt = new JsEncryptModule.JSEncrypt(); 36 | } 37 | 38 | getTodayPrivkey(): Observable> { 39 | return this.http.get(this.baseUrl + '/api/v1/privkeys/today', { 40 | headers: new HttpHeaders().set('Authorization', `Bearer ${this.token}`) 41 | }).pipe( 42 | map((value: Result) => Object.assign(new Result(), value)) 43 | ); 44 | } 45 | 46 | getGuestUserQRCode(user_id: number, followers?: string[]): Observable { 47 | const params = { 48 | 'followers': followers.toString() 49 | }; 50 | 51 | return this.http.get(this.baseUrl + `/api/v1/guests/${user_id}/qr`, { 52 | headers: new HttpHeaders().set('Authorization', `Bearer ${this.token}`), 53 | responseType: 'blob', 54 | params: params 55 | }).pipe( 56 | map((value: Blob) => { 57 | this.qrCreatedDate = new Date(); 58 | 59 | let objUrl = URL.createObjectURL(value); 60 | return this.domSanitizer.bypassSecurityTrustUrl(objUrl); 61 | }) 62 | ); 63 | } 64 | 65 | visit(username: string, location_id: number, followers?: Follower[]): Observable> { 66 | const params = { 67 | 'location_id': location_id, 68 | 'followers': followers 69 | }; 70 | 71 | return this.http.put(this.baseUrl + `/api/v1/visits/users/${username}`, params, { 72 | headers: new HttpHeaders().set('Authorization', `Bearer ${this.token}`) 73 | }).pipe( 74 | map((value: Result) => Object.assign(new Result(), value)) 75 | ); 76 | } 77 | 78 | tcpassVisit(uuid: string, location_id: number): Observable> { 79 | const params = { 80 | 'location_id': location_id 81 | }; 82 | 83 | return this.http.put(this.baseUrl + `/api/v1/visits/tcpass/users/${uuid}`, params, { 84 | headers: new HttpHeaders().set('Authorization', `Bearer ${this.token}`) 85 | }).pipe( 86 | map((value: Result) => Object.assign(new Result(), value)) 87 | ); 88 | } 89 | 90 | getBuildings(): Observable { 91 | return this.http.get(this.baseUrl + '/api/v1/visits/buildings', { 92 | headers: new HttpHeaders().set('Authorization', `Bearer ${this.token}`) 93 | }).pipe( 94 | map((value: Building[]) => { 95 | const buildings: Building[] = new Array(); 96 | const currentDepartment: Department = this.userService.currentUser.employee.currentDepartment(); 97 | const building = new Building(); 98 | building.id = 0; 99 | building.building = "所屬單位"; 100 | building.locations = new Array(); 101 | buildings.push(building) 102 | 103 | const location = new Location(); 104 | location.id = 0; 105 | location.location = currentDepartment.department; 106 | building.locations.push(location); 107 | 108 | for (const building of value) { 109 | buildings.push(Object.assign(new Building(), building)); 110 | } 111 | 112 | return buildings; 113 | }) 114 | ) 115 | } 116 | 117 | decrypt(ciphertext: string): string { 118 | return this.jsEncrypt.decrypt(ciphertext); 119 | } 120 | 121 | checkNhiService(): Observable { 122 | return this.http.get('https://nhi.localhost:5001/nhi/ping'); 123 | } 124 | 125 | getNhiUser(): Observable> { 126 | return this.http.get('https://nhi.localhost:5001/nhi/user').pipe( 127 | map((value: Result) => Object.assign(new Result(), value)) 128 | ); 129 | } 130 | 131 | set privkey(value: string) { 132 | this.jsEncrypt.setPrivateKey(value); 133 | 134 | this._privkey = value; 135 | } 136 | 137 | get privkey(): string { 138 | return this._privkey; 139 | } 140 | 141 | private get token(): string { 142 | return this.userService.currentUser.token.token; 143 | } 144 | 145 | public get qrCreatedDate(): Date { 146 | return this._qrCraetedDate; 147 | } 148 | public set qrCreatedDate(value: Date) { 149 | this._qrCraetedDate = value; 150 | } 151 | 152 | public get redirectUrl(): string { 153 | return RsaService._redirectUrl; 154 | } 155 | public set redirectUrl(value: string) { 156 | RsaService._redirectUrl = value; 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /src/app/user/login/login.component.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/user/login/login.component.ts: -------------------------------------------------------------------------------- 1 | import { HttpErrorResponse } from '@angular/common/http'; 2 | import { Component, OnInit } from '@angular/core'; 3 | import { FormBuilder, FormGroup, Validators } from '@angular/forms'; 4 | import { ActivatedRoute, Router, ParamMap } from '@angular/router'; 5 | import { MatDialog } from '@angular/material/dialog'; 6 | import { MatSnackBar } from '@angular/material/snack-bar'; 7 | import { timer } from 'rxjs'; 8 | import { map, takeWhile, switchMap } from 'rxjs/operators'; 9 | 10 | import { UserService } from '../user.service'; 11 | import { Result } from '../../model/result'; 12 | import { User } from '../model/user'; 13 | import { Guest } from '../model/guest'; 14 | import { DuplicateVerificationDialogComponent } from './duplicate-verification-dialog/duplicate-verification-dialog.component'; 15 | 16 | @Component({ 17 | selector: 'app-login', 18 | templateUrl: './login.component.html', 19 | styleUrls: ['./login.component.scss'] 20 | }) 21 | export class LoginComponent implements OnInit { 22 | hide = true; 23 | verify = false; 24 | agreed = false; 25 | tabGroupIndex = 0; 26 | step = 0; 27 | 28 | otp_code = ""; 29 | otp_ttl = 60; 30 | 31 | loginTccgUserFormGroup: FormGroup; 32 | registerGuestUserFormGroup: FormGroup; 33 | 34 | constructor( 35 | private activatedRoute: ActivatedRoute, 36 | private dialog: MatDialog, 37 | private formBuilder: FormBuilder, 38 | private router: Router, 39 | private snackBar: MatSnackBar, 40 | private userService: UserService, 41 | ) { 42 | let token; 43 | 44 | this.activatedRoute.queryParams.subscribe(params => { 45 | token = params['t']; 46 | }); 47 | 48 | if (!token) 49 | token = this.activatedRoute.snapshot.paramMap.get('token'); 50 | 51 | if (token) { 52 | this.loginGuestUser(token); 53 | } 54 | 55 | let account = localStorage.getItem("account"); 56 | let password = localStorage.getItem("password"); 57 | 58 | if ((account != null) && (password != null)) { 59 | this.loginTccgUser(account, password); 60 | return; 61 | } 62 | 63 | let phone_token = localStorage.getItem("phone_token"); 64 | if (phone_token != null) { 65 | this.loginGuestUser(phone_token); 66 | } 67 | } 68 | 69 | ngOnInit() { 70 | this.loginTccgUserFormGroup = this.formBuilder.group({ 71 | account: [ 72 | null, 73 | Validators.required 74 | ], 75 | password: [ 76 | null, 77 | Validators.required 78 | ] 79 | }); 80 | 81 | this.registerGuestUserFormGroup = this.formBuilder.group({ 82 | name: [ 83 | null, 84 | Validators.required 85 | ], 86 | phone: [ 87 | null, 88 | [Validators.required, Validators.pattern("09[0-9]{8}")] 89 | ], 90 | otp_code: [ 91 | null, 92 | [Validators.pattern("[0-9]{4}")] 93 | ] 94 | }); 95 | } 96 | 97 | agreedNotice() { 98 | this.agreed = true; 99 | this.nextStep(); 100 | } 101 | 102 | loginTccgUser(account: string, password: string) { 103 | this.currentUser = null; 104 | 105 | this.userService.loginTccgUser(account, password) 106 | .subscribe({ 107 | next: (value) => { 108 | localStorage.setItem("account", account) 109 | localStorage.setItem("password", password) 110 | 111 | this.loginTccgUserResultHandler(value) 112 | }, 113 | error: (error) => { 114 | localStorage.removeItem("account"); 115 | localStorage.removeItem("password"); 116 | 117 | this.faultHandler(error); 118 | } 119 | }); 120 | } 121 | 122 | loginGuestUser(phone_token: string) { 123 | this.currentUser = null; 124 | 125 | this.userService.loginGuestUser(phone_token) 126 | .subscribe({ 127 | next: (value) => { 128 | localStorage.setItem("phone_token", phone_token); 129 | this.loginGuestUserResultHandler(value); 130 | }, 131 | error: (error) => { 132 | localStorage.removeItem("phone_token"); 133 | this.faultHandler(error); 134 | } 135 | }); 136 | } 137 | 138 | registerGuestUser(name: string, phone: string) { 139 | this.currentUser = null; 140 | 141 | this.userService.registerGuestUser(name, phone) 142 | .subscribe({ 143 | next: (value) => this.registerGuestUserResultHandler(value), 144 | error: (error) => this.registerGuestUserFaultHandler(error) 145 | }); 146 | } 147 | 148 | sendGuestPhoneOTP(user_id: number, phone: string) { 149 | this.userService.sendGuestPhoneOTP(user_id, phone) 150 | .subscribe({ 151 | next: (value) => this.sendGuestPhoneOTPResultHandler(value), 152 | error: (error) => this.faultHandler(error) 153 | }); 154 | } 155 | 156 | verifyGuestUserPhoneOTP() { 157 | const guest = this.currentUser.guest; 158 | guest.phone_otp = this.registerGuestUserFormGroup.get("otp_code").value; 159 | 160 | this.userService.verifyGuestUserPhoneOTP(guest) 161 | .subscribe({ 162 | next: (value) => this.verifyGuestUserPhoneOTPResultHandler(value), 163 | error: (error) => this.faultHandler(error) 164 | }); 165 | } 166 | 167 | selectedIndexChangeHandler(index: number) { 168 | this.tabGroupIndex = index; 169 | } 170 | 171 | otpInputChangeHandler(value) { 172 | this.otp_code = value; 173 | } 174 | 175 | private loginTccgUserResultHandler(result: Result) { 176 | const user: User = Object.assign(new User(), result.data); 177 | const info = result.info[0]; 178 | this.currentUser = user; 179 | 180 | this.snackBar.open(info, '確定', { 181 | duration: 2000 182 | }); 183 | 184 | if (this.userService.redirectUrl != null) { 185 | this.userService.redirectUrl = null; 186 | this.router.navigate(['/qr/scan']); 187 | } else { 188 | this.router.navigate(['/qr/scan']); 189 | } 190 | } 191 | 192 | private loginGuestUserResultHandler(result: Result) { 193 | const user: User = Object.assign(new User(), result.data); 194 | const info = result.info[0]; 195 | this.currentUser = user; 196 | 197 | this.snackBar.open(info, '確定', { 198 | duration: 2000 199 | }); 200 | 201 | if (this.userService.redirectUrl != null) { 202 | this.userService.redirectUrl = null; 203 | this.router.navigate(['/qr/show']); 204 | } else { 205 | this.router.navigate(['/qr/show']); 206 | } 207 | } 208 | 209 | private registerGuestUserResultHandler(result: Result) { 210 | const user: User = Object.assign(new User(), result.data); 211 | const info = result.info[0]; 212 | this.currentUser = user; 213 | 214 | this.sendGuestPhoneOTP(user.id, user.guest.phone); 215 | 216 | this.snackBar.open(info, '確定', { 217 | duration: 2000 218 | }); 219 | } 220 | 221 | private registerGuestUserFaultHandler(error: HttpErrorResponse) { 222 | const failureResult = Object.assign(new Result(), error.error); 223 | const info = failureResult.info[0]; 224 | const user: User = Object.assign(new User(), failureResult.data) 225 | this.currentUser = user; 226 | 227 | if (error.status === 401) { 228 | this.sendGuestPhoneOTP(user.id, user.guest.phone); 229 | 230 | this.snackBar.open(info, '確定', { 231 | duration: 2000 232 | }); 233 | } 234 | 235 | if (error.status === 409) { 236 | const dialogRef = this.dialog.open(DuplicateVerificationDialogComponent, { 237 | width: '80%', 238 | maxWidth: '600px', 239 | data: user 240 | }); 241 | 242 | dialogRef.afterClosed().subscribe(result => { 243 | if (result) { 244 | this.sendGuestPhoneOTP(user.id, user.guest.phone); 245 | } 246 | }); 247 | } 248 | 249 | if (error.status === 429) { 250 | this.snackBar.open(info, '確定', { 251 | duration: 2000 252 | }); 253 | } 254 | } 255 | 256 | private sendGuestPhoneOTPResultHandler(result: Result) { 257 | const guest: Guest = Object.assign(new Guest(), result.data); 258 | this.currentUser.guest = guest; 259 | 260 | this.verify = true; 261 | this.otp_code = ""; 262 | this.otp_ttl = 60; 263 | 264 | this.registerGuestUserFormGroup.get("name").disable(); 265 | this.registerGuestUserFormGroup.get("phone").disable(); 266 | this.nextStep(); 267 | 268 | timer(1000, 1000).pipe( 269 | takeWhile(() => this.otp_ttl > 0), 270 | map(() => this.otp_ttl--) 271 | ).subscribe({ 272 | next: (value) => console.log(`otp_ttl: ${this.otp_ttl}`), 273 | error: (err) => console.error(err), 274 | complete: () => { 275 | this.registerGuestUserFormGroup.get("name").enable(); 276 | this.registerGuestUserFormGroup.get("phone").enable(); 277 | this.verify = false; 278 | this.setStep(1); 279 | } 280 | }); 281 | } 282 | 283 | private verifyGuestUserPhoneOTPResultHandler(result: Result) { 284 | const guest: Guest = Object.assign(new Guest(), result.data); 285 | const info = result.info[0]; 286 | this.currentUser.guest = guest; 287 | 288 | this.snackBar.open(info, '確定', { 289 | duration: 2000 290 | }); 291 | 292 | this.loginGuestUser(guest.phone_token); 293 | } 294 | 295 | 296 | private faultHandler(error: HttpErrorResponse) { 297 | let failureResult: Result; 298 | let info = error.statusText; 299 | 300 | if ((error.status === 401) || (error.status === 422) || (error.status === 429)) { 301 | failureResult = Object.assign(new Result(), error.error); 302 | info = failureResult.info[0]; 303 | } 304 | 305 | this.snackBar.open(info, '確定', { 306 | duration: 2000 307 | }); 308 | } 309 | 310 | setStep(index: number) { 311 | this.step = index; 312 | } 313 | 314 | nextStep() { 315 | this.step++; 316 | } 317 | 318 | prevStep() { 319 | this.step--; 320 | } 321 | 322 | public get currentUser(): User { 323 | return this.userService.currentUser; 324 | } 325 | public set currentUser(value: User) { 326 | this.userService.currentUser = value; 327 | } 328 | } 329 | -------------------------------------------------------------------------------- /src/app/qr/scan/scan.component.ts: -------------------------------------------------------------------------------- 1 | import { HttpErrorResponse } from '@angular/common/http'; 2 | import { Component, OnInit, ViewChild } from '@angular/core'; 3 | import { Router } from '@angular/router'; 4 | import { MatDialog } from '@angular/material/dialog'; 5 | import { MatInput } from '@angular/material/input'; 6 | import { MatSnackBar } from '@angular/material/snack-bar'; 7 | import { ZXingScannerComponent } from '@zxing/ngx-scanner'; 8 | import { 9 | isNationalIdentificationNumberValid, 10 | isResidentCertificateNumberValid 11 | } from 'taiwan-id-validator2'; 12 | 13 | import { GuestRegisterDialogComponent } from './guest-register-dialog/guest-register-dialog.component'; 14 | import { ScanSuccessDialogComponent } from './scan-success-dialog/scan-success-dialog.component'; 15 | import { RsaService } from '../rsa.service'; 16 | import { UserService } from '../../user/user.service'; 17 | import { Result } from '../../model/result'; 18 | import { User } from '../../user/model/user'; 19 | import { Guest } from '../../user/model/guest'; 20 | import { Token } from '../../user/model/token'; 21 | import { Visit } from '../models/visit'; 22 | import { TcpassVisit } from '../models/tcpass-visit'; 23 | import { Follower} from '../models/follower'; 24 | import { NhiUser } from '../models/nhi-user'; 25 | import { Building, Location } from '../models/location'; 26 | 27 | @Component({ 28 | selector: 'app-scan', 29 | templateUrl: './scan.component.html', 30 | styleUrls: ['./scan.component.scss'] 31 | }) 32 | export class ScanComponent implements OnInit { 33 | private _ciphertext: string; 34 | private _currentLocation: Location; 35 | private _currentDevice: MediaDeviceInfo = null; 36 | 37 | availableDevices: MediaDeviceInfo[]; 38 | buildings: Building[]; 39 | scanEnabled = true; 40 | lastUUID: string; 41 | lastUsername: string; 42 | lastFollowers: Follower[]; 43 | currentGuest: Guest; 44 | nhiEnabled = false; 45 | 46 | tcpassBarCodeCheck = new RegExp('^.[A-Z]{2}[0-9]{11}'); 47 | tcpassQRCodeCheck = new RegExp('^uuid=(?.{0,})&t='); 48 | 49 | @ViewChild(ZXingScannerComponent) qrScanner: ZXingScannerComponent; 50 | @ViewChild(MatInput) scanner: MatInput; 51 | 52 | constructor( 53 | private dialog: MatDialog, 54 | private router: Router, 55 | private rsaService: RsaService, 56 | private userService: UserService, 57 | private snackBar: MatSnackBar, 58 | ) { } 59 | 60 | ngOnInit() { 61 | this.rsaService.checkNhiService().subscribe({ 62 | next: (value) => this.nhiEnabled = true, 63 | error: (err) => console.error(err), 64 | complete: () => console.log("完成健保卡服務連線測試") 65 | }) 66 | 67 | this.rsaService.getTodayPrivkey().subscribe({ 68 | next: (value) => this.rsaService.privkey = value.data, 69 | error: (err) => this.faultHandler(err), 70 | complete: () => console.log('成功取得今天的私鑰') 71 | }); 72 | 73 | this.rsaService.getBuildings().subscribe({ 74 | next: (value) => this.buildings = value, 75 | error: (err) => console.error(err), 76 | complete: () => { 77 | let locationID = +localStorage.getItem("location_id"); 78 | 79 | if (locationID == 0) { 80 | this.currentLocation = this.buildings[0].locations[0]; 81 | } 82 | 83 | for (let building of this.buildings) { 84 | for (let location of building.locations) { 85 | if (location.id == locationID) { 86 | this.currentLocation = location; 87 | return; 88 | } 89 | } 90 | } 91 | } 92 | }); 93 | } 94 | 95 | visit(username: string, followers?: Follower[]) { 96 | let locationID = 0; 97 | if (this.currentLocation) 98 | locationID = this.currentLocation.id 99 | 100 | this.lastUsername = username; 101 | this.lastFollowers = followers; 102 | 103 | this.rsaService.visit(username, locationID, followers).subscribe({ 104 | next: (value) => this.visitResultHandler(value), 105 | error: (err) => this.faultHandler(err), 106 | }); 107 | } 108 | 109 | tcpassVisit(uuid: string) { 110 | let locationID = 0; 111 | if (this.currentLocation) 112 | locationID = this.currentLocation.id 113 | 114 | this.lastUUID = uuid; 115 | 116 | this.rsaService.tcpassVisit(uuid, locationID).subscribe({ 117 | next: (value) => this.tcpassVisitResultHandler(value), 118 | error: (err) => this.faultHandler(err), 119 | }); 120 | } 121 | 122 | logout() { 123 | localStorage.removeItem("account"); 124 | localStorage.removeItem("password"); 125 | localStorage.removeItem("phone_token"); 126 | 127 | this.currentUser = null; 128 | this.router.navigate(['/']); 129 | 130 | this.snackBar.open(`帳號已登出`, '確定', { 131 | duration: 2000 132 | }); 133 | } 134 | 135 | scanSuccessHandler(result: string) { 136 | if (!this.scanEnabled) 137 | return; 138 | 139 | if (this.scanner.value != "") { 140 | this.scanner.value = ""; 141 | } 142 | 143 | let uuid: string; 144 | let username: string; 145 | let followers: Follower[]; 146 | let success = false; 147 | 148 | if (isNationalIdentificationNumberValid(result.toUpperCase()) || 149 | isResidentCertificateNumberValid(result.toUpperCase())) { 150 | let guest = new Guest(); 151 | guest.id_card = result.toUpperCase(); 152 | this.currentGuest = guest; 153 | 154 | username = guest.id_card; 155 | success = true; 156 | } else { 157 | const user = this.rsaService.decrypt(result); 158 | if (user) { 159 | let info = user.split(",") 160 | username = info[1]; 161 | 162 | if (info.length > 2) { 163 | followers = new Array(); 164 | for (let value of info.slice(2)) { 165 | followers.push(new Follower(value)); 166 | } 167 | } 168 | 169 | success = true; 170 | } 171 | 172 | if (!success) { 173 | uuid = result; 174 | if (this.tcpassBarCodeCheck.test(result)) 175 | success = true; 176 | else { 177 | let match = result.match(this.tcpassQRCodeCheck); 178 | if (match) { 179 | uuid = match.groups?.uuid; 180 | success = true; 181 | } 182 | } 183 | 184 | if (success) { 185 | this.scanEnabled = false; 186 | this.tcpassVisit(uuid); 187 | return 188 | } 189 | } 190 | } 191 | 192 | if ((success) && (this.scanEnabled)) { 193 | this.scanEnabled = false; 194 | this.visit(username, followers); 195 | } else { 196 | this.snackBar.open('您使用無效或已經過期的條碼', '確定', { 197 | duration: 2000 198 | }); 199 | } 200 | } 201 | 202 | focusScanner() { 203 | this.scanner.focus(); 204 | } 205 | 206 | switchShowQRCode() { 207 | this.qrScanner.enable = false; 208 | 209 | this.router.navigate(['/qr/show']); 210 | } 211 | 212 | loadNhiUser() { 213 | this.rsaService.getNhiUser().subscribe({ 214 | next: (value) => this.getNhiUserResultHandler(value), 215 | error: (err) => this.faultHandler(err), 216 | }); 217 | 218 | this.focusScanner(); 219 | } 220 | 221 | private visitResultHandler(result: Result) { 222 | const visit: Visit = Object.assign(new Visit(), result.data); 223 | 224 | const dialogRef = this.dialog.open(ScanSuccessDialogComponent, { 225 | width: '80%', 226 | maxWidth: '600px', 227 | data: visit 228 | }); 229 | 230 | dialogRef.afterClosed().subscribe((result: any) => { 231 | this.scanEnabled = true; 232 | this.focusScanner(); 233 | }); 234 | } 235 | 236 | private tcpassVisitResultHandler(result: Result) { 237 | const visit: TcpassVisit = Object.assign(new TcpassVisit(), result.data); 238 | 239 | const dialogRef = this.dialog.open(ScanSuccessDialogComponent, { 240 | width: '80%', 241 | maxWidth: '600px', 242 | data: visit 243 | }); 244 | 245 | dialogRef.afterClosed().subscribe((result: any) => { 246 | this.scanEnabled = true; 247 | this.focusScanner(); 248 | }); 249 | } 250 | 251 | private getNhiUserResultHandler(result: Result) { 252 | const guest = new Guest(); 253 | guest.name = result.data.name; 254 | guest.id_card = result.data.id_card; 255 | 256 | this.currentGuest = guest; 257 | 258 | this.scanEnabled = false; 259 | this.visit(guest.id_card); 260 | } 261 | 262 | private faultHandler(error: HttpErrorResponse) { 263 | const result: Result = Object.assign(new Result(), error.error); 264 | 265 | if (!result.info) { 266 | this.scanEnabled = true; 267 | return; 268 | } 269 | const info = result.info[0] 270 | 271 | if (error.status === 401) { 272 | this.userService.refreshToken().subscribe({ 273 | next: (value) => this.refreshTokenHandler(value), 274 | error: (err) => console.error(err), 275 | complete: () => console.log('complete') 276 | }); 277 | } 278 | 279 | if (error.status === 409) { 280 | const dialogRef = this.dialog.open(GuestRegisterDialogComponent, { 281 | width: '80%', 282 | maxWidth: '600px', 283 | data: this.currentGuest, 284 | disableClose: true 285 | }); 286 | 287 | dialogRef.afterClosed().subscribe((user: User) => { 288 | this.scanEnabled = true; 289 | this.currentGuest = null; 290 | 291 | if ((user) && (user instanceof User)) { 292 | this.scanEnabled = false; 293 | this.visit(user.username); 294 | 295 | this.snackBar.open(`${user.name} 已經完成資料登錄`, '確定', { 296 | duration: 2000 297 | }); 298 | } 299 | 300 | this.focusScanner(); 301 | }); 302 | } 303 | 304 | if (error.status === 422) { 305 | 306 | } 307 | 308 | this.snackBar.open(info, '確定', { 309 | duration: 2000 310 | }); 311 | } 312 | 313 | private refreshTokenHandler(result: Result) { 314 | const token: Token = Object.assign(new Token(), result.data); 315 | this.userService.currentUser.token = token; 316 | 317 | if (this.lastUsername) { 318 | this.visit(this.lastUsername, this.lastFollowers); 319 | 320 | this.lastUsername = null; 321 | this.lastFollowers = null; 322 | } 323 | 324 | if (this.lastUUID) { 325 | this.tcpassVisit(this.lastUUID); 326 | 327 | this.lastUUID = null; 328 | } 329 | } 330 | 331 | onCamerasFound(devices: MediaDeviceInfo[]): void { 332 | this.availableDevices = devices; 333 | } 334 | 335 | set ciphertext(value: string) { 336 | this._ciphertext = value; 337 | } 338 | 339 | get ciphertext(): string { 340 | return this._ciphertext; 341 | } 342 | 343 | public set currentUser(value: User) { 344 | this.userService.currentUser = value; 345 | } 346 | public get currentUser(): User { 347 | return this.userService.currentUser; 348 | } 349 | 350 | public get currentLocation(): Location { 351 | return this._currentLocation; 352 | } 353 | public set currentLocation(value: Location) { 354 | this._currentLocation = value; 355 | 356 | localStorage.setItem("location_id", value.id.toString()); 357 | } 358 | 359 | public get currentDevice(): MediaDeviceInfo { 360 | return this._currentDevice; 361 | } 362 | public set currentDevice(value: MediaDeviceInfo) { 363 | if (value == null) 364 | return; 365 | 366 | this._currentDevice = value; 367 | } 368 | } 369 | -------------------------------------------------------------------------------- /src/app/svg/tccg-logo/tccg-logo.component.svg: -------------------------------------------------------------------------------- 1 | 2 | 6 | 11 | 15 | 24 | 33 | 40 | 44 | 53 | 62 | 66 | 71 | 77 | 87 | 96 | 101 | 111 | 119 | 123 | 128 | 138 | 142 | 146 | 148 | 150 | 152 | 154 | 156 | 166 | 195 | 211 | 229 | 249 | --------------------------------------------------------------------------------