import win.ui;
import console;
import libpq;
import crypt;
import crypt.bin;
//import crypt.hmac;
/*DSG{{*/
mainForm = win.form(text="新用户注册USII";right=204;bottom=136)
mainForm.add(
button={cls="button";text="注册账号";left=48;top=95;right=117;bottom=128;z=5};
button2={cls="button";text="删除账号";left=123;top=95;right=192;bottom=128;z=6};
checkbox={cls="checkbox";text="Checkbox";left=17;top=114;right=34;bottom=128;z=8};
edit={cls="edit";left=51;top=8;right=195;bottom=37;edge=1;multiline=1;tabstop=1;z=1};
edit2={cls="edit";left=51;top=50;right=195;bottom=79;edge=1;multiline=1;tabstop=1;z=2};
static={cls="static";text="账号";left=15;top=14;right=49;bottom=45;transparent=1;z=3};
static2={cls="static";text="密码";left=17;top=57;right=50;bottom=78;transparent=1;z=4};
static3={cls="static";text="GM";left=15;top=96;right=47;bottom=116;transparent=1;z=7}
)
/*}}*/
mainForm.button.oncommand = function(id,event){
/*
PostgreSQL 服务端:
https://get.enterprisedb.com/pos ... indows-binaries.zip
*/
var db = libpq(
dbname = "zhuxian";
port = 9999 ;
user = "postgres";
password = "8888";
)
var regcom=`insert into hops.account (user_name,"password",user_type) values ('`++mainForm.edit.text+`','`+crypt.sha256(mainForm.edit2.text)+`',1);`
var quecom=`select user_name from hops.account where user_name ='`++mainForm.edit.text+`';`
if(mainForm.checkbox.checked){
regcom=`insert into hops.account (user_name,"password",user_type) values ('`++mainForm.edit.text+`','`+crypt.sha256(mainForm.edit2.text)+`',5);`
}
if(mainForm.edit.text==''){
mainForm.msgbox("请输入用户名")
}elseif(mainForm.edit2.text==''){
mainForm.msgbox("请输入用密码")
}else {
rs= db.exec(regcom);
if(rs==1){
mainForm.msgbox("注册成功,账号: "+mainForm.edit.text)
}else {
mainForm.msgbox("添加失败")
}
}
}
mainForm.button2.oncommand = function(id,event){
var db = libpq(
dbname = "hero";
port = 5432 ;
user = "postgres";
password = "1234";
)
if(mainForm.edit.text==''){
mainForm.msgbox("请输入用户名")
}else {
var delcom=`delete from hops.account where user_name='`++mainForm.edit.text+`';`
rs= db.exec(delcom);
if(rs==1){
mainForm.msgbox("已经删除,账号: "+mainForm.edit.text)
}else {
mainForm.msgbox("删除失败")
}
}
}
mainForm.show();
return win.loopMessage();