You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

96 lines
3.1 KiB

import { Component, OnInit, Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
import {MTokenK1Service} from './m-token-k1.service' //引入服务
declare var mToken : any;
@Injectable({
providedIn: 'root'
})
@Component({
selector: 'app-m-token-k1',
templateUrl: './m-token-k1.component.html',
styleUrls: ['./m-token-k1.component.scss']
})
export class MTokenK1Component implements OnInit {
constructor(private router: Router,public snackBar: MatSnackBar,public mTokenK1: MTokenK1Service) { }
ngOnInit(): void {
}
// 路由守卫
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
return this.checkKey();
}
K1mToken = new mToken("mTokenPlugin")
keyBase64 = '5YyX5Lqs5a6J5L+h4oCU5LqM57u06aKE5qGI57yW5Yi25bel5YW3d2Vi'; //秘钥验证base64字符
password='12345678'; //秘钥验证用户密码
checkKey(): boolean {
this.K1mToken.LoadLibrary()
try { //try 捕获错误
let keyIndex = this.K1mToken.K1_mTokenFindDevice() //查找秘钥是否插入
if (keyIndex > 0) { //秘钥已插入
let keyUID = this.K1mToken.K1_mTokenGetUID(keyIndex) //读取秘钥UID
let isLogin = this.K1mToken.K1_mTokenOpen(keyUID,this.password)
if (isLogin == 0 ) { //密码验证成功
let keyMSG = window.atob( this.K1mToken.K1_mTokenReadUserStorage(keyUID,0,56) )
if (keyMSG==this.keyBase64) { //base64转码 验证
const config = new MatSnackBarConfig();
config.verticalPosition = 'top';
config.duration = 3000
this.snackBar.open('密钥验证成功','确定',config);
this.mTokenK1.startUp() //开始定时验证秘钥是否拔出
return true
} else { //base64验证失败
const config = new MatSnackBarConfig();
config.verticalPosition = 'top';
config.duration = 5000
this.snackBar.open('密钥错误,不为本公司发放密钥','确定',config);
return false
}
} else { //密码验证失败
const config = new MatSnackBarConfig();
config.verticalPosition = 'top';
config.duration = 5000
this.snackBar.open('密钥密码错误,请使用初始密码','确定',config);
return false
}
} else { //秘钥未插入
const config = new MatSnackBarConfig();
config.verticalPosition = 'top';
config.duration = 5000
this.snackBar.open('密钥未插入','确定',config);
return false
}
} catch (error) {
const config = new MatSnackBarConfig();
config.verticalPosition = 'top';
config.duration = 5000
this.snackBar.open('请检查您密钥是否插入或者驱动是否已启动','确定',config);
return false
}
} //路由守卫
//倒计时插件关闭页面
handleEvent (e) {
if (e.left===0) {window.close()}
}
}