From ab13957cb042bc9edc41417b7dd4882d8f9b8f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B0=D0=B2=D0=B5=D0=BB=D0=B8=D0=B9=20=D0=A1=D0=B0?= =?UTF-8?q?=D0=B2=D0=B5=D0=BD=D0=BE=D0=BA?= <56991906+Lisoveliy@users.noreply.github.com> Date: Sat, 9 Nov 2024 18:22:00 +0300 Subject: [PATCH] feat: created logic for render totps --- lib/totp.js/lib/hotp.js | 4 +- page/index.js | 88 ++++++++++++++++++++++++++++++----------- page/tip.js | 1 - page/totplogic/totps.js | 20 ++++++++++ 4 files changed, 87 insertions(+), 26 deletions(-) create mode 100644 page/totplogic/totps.js diff --git a/lib/totp.js/lib/hotp.js b/lib/totp.js/lib/hotp.js index 3614db9..129ec74 100644 --- a/lib/totp.js/lib/hotp.js +++ b/lib/totp.js/lib/hotp.js @@ -12,7 +12,9 @@ export class HOTP { this.key = key; this.digit = digit; } - + static encode(data){ + return encode(data) + } /** * generate secret key * @param {int} len diff --git a/page/index.js b/page/index.js index d1a6b86..c68f940 100644 --- a/page/index.js +++ b/page/index.js @@ -1,35 +1,75 @@ import { getDeviceInfo } from '@zos/device' import { push } from '@zos/router' -import { createWidget, widget } from '@zos/ui' +import { setStatusBarVisible, createWidget, widget, align, prop, text_style, event } from '@zos/ui' -import {TOTP} from '../lib/totp.js/lib/totp.js' +import { TOTPBuffer } from './totplogic/totps.js' Page({ build() { - - const totp = new TOTP('asdasd') + setStatusBarVisible(false); + buf = new TOTPBuffer(); - const {width, height} = getDeviceInfo() - createWidget(widget.TEXT, { - x: width / 2 - 30, - y: height / 2 - 60, - text: totp.genOTP() - }) - createWidget(widget.BUTTON,{ - x: width / 2 - 40, - y: height / 2 - 20, - w: 80, - h: 80, - text: '+', - radius: 50, - text_size: 40, - normal_color: 0x303030, - press_color: 0x181c18, - click_func: () => { - push({ - url: 'page/tip' + const { width, height } = getDeviceInfo() + buffer = buf.getTOTPs(); + if(buffer.length < 1){ + createWidget(widget.BUTTON, { + x: width / 2 - 40, + y: height / 2 - 20, + w: 80, + h: 80, + text: '+', + radius: 50, + text_size: 40, + normal_color: 0x303030, + press_color: 0x181c18, + click_func: () => { + push({ + url: 'page/tip' + }) + } + }) + }else{ + const buttonWidth = width - width / 20; + const buttonHeight = height / 4; + const margin = 10; + let totpHeight = margin; + + for(let i = 0; i < buffer.length; i++){ + createWidget(widget.FILL_RECT, { + x: width / 2 - buttonWidth / 2, + y: totpHeight, + w: buttonWidth, + h: buttonHeight, + color: 0x303030, + radius: 20 }) + createWidget(widget.TEXT, { + x: 0, + y: totpHeight + 10, + w: width, + h: 26, + color: 0xa0a0a0, + text_size: 24, + align_h: align.CENTER_H, + align_v: align.CENTER_V, + text_style: text_style.NONE, + text: buffer[i].name + }) + createWidget(widget.TEXT, { + x: 0, + y: totpHeight + 60, + w: width, + h: 36, + color: 0xffffff, + text_size: 36, + align_h: align.CENTER_H, + align_v: align.CENTER_V, + text_style: text_style.NONE, + text: buffer[i].data + }) + + totpHeight += margin + buttonHeight; } - }) + } } }) diff --git a/page/tip.js b/page/tip.js index 29ab95a..7452d2a 100644 --- a/page/tip.js +++ b/page/tip.js @@ -13,7 +13,6 @@ Page({ }) }, build() { - console.log("Page tip opened") const {width, height} = getDeviceInfo() createWidget(widget.TEXT, { x: 0, diff --git a/page/totplogic/totps.js b/page/totplogic/totps.js new file mode 100644 index 0000000..2fd3aaf --- /dev/null +++ b/page/totplogic/totps.js @@ -0,0 +1,20 @@ +import { TOTP } from "../../lib/totp.js/lib/totp"; + +export class TOTPBuffer{ + constructor(){ + + } + + getTOTPs(){ + return [new TOTPData("Contabo-Customer-Control-Panel-11755808: my.contabo.com", new TOTP(TOTP.encode('UU5WIIWKDNAHUNNL')).genOTP()), + new TOTPData("OTPData", new TOTP(TOTP.encode('LCHJZO23LT3Z2QYNYAYAJXH5HFDZ5YI2')).genOTP()), + new TOTPData("test", new TOTP(TOTP.encode('GAXHMZDEGJVG64LP')).genOTP())] + } +} + +export class TOTPData{ + constructor(name, data){ + this.name = name; + this.data = data; + } +} \ No newline at end of file