auwinodws.java 4.24 KB
package cn.csbr.app.gui.handler;


import cn.csbr.app.gui.GUIContext;
import cn.csbr.app.gui.util.DialogUtils;

import cn.csbr.configenc.AESUtil;
import cn.csbr.springboot.dao.mapper.SysRoleMapper;
import cn.csbr.springboot.dao.model.SysRole;
import com.csbr.util.IdUtils;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.ToggleButton;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import org.controlsfx.control.textfield.TextFields;
import tk.mybatis.mapper.entity.Example;

//@Component
public class auwinodws {
    Button btn;
   // @Autowired
    private SysRoleMapper sysRoleMapper;
    //@Autowired
    private GUIContext guiContext;
    //public auwinodws(){}
    public auwinodws(final Stage stg, ToggleButton t, GUIContext guiContext, SysRoleMapper sysRoleMapper) {
        this.guiContext=guiContext;
        this.sysRoleMapper=sysRoleMapper;
        btn = new Button();

        final Stage stage = new Stage();
        stage.setOnCloseRequest((e)->{
            t.setSelected(true);
            t.setFocusTraversable(true);
        });
//Initialize the Stage with type of modal
        stage.initModality(Modality.APPLICATION_MODAL);
//Set the owner of the Stage
        stage.initOwner(stg);
        stage.setTitle("请输入授权码");
        Group root = new Group();
        Scene scene = new Scene(root, 340, 100);


       // TextField textField = new TextField();
       // textField.setLayoutX(100);
      //  textField.setScaleY(50);
        VBox vBox= new VBox();
        PasswordField text = TextFields.createClearablePasswordField();
        text.setTranslateY(20);
        text.setTranslateX(60);
        //text.setStyle("-fx-font-family: 宋体; -fx-font-size: 28;-fx-max-width: 20;-fx-max-height: 20");
      //  text.setMinWidth(150);
       // text.setMaxHeight(40);
        //btn;
        btn.setTranslateY(40);
        btn.setTranslateX(120);
       // btn.setMinWidth(80);
        btn.setText("授权");
        btn.setOnAction(new EventHandler<ActionEvent>() {

            public void handle(ActionEvent event) {
                Example example = new Example(SysRole.class);
                String ss="";
                try {
                    ss= AESUtil.Encrypt(text.getText());
                } catch (Exception e) {
                    DialogUtils.showHeaderTextInformationAlert("授权失败",stg);
                    t.setSelected(true);
                    t.setFocusTraversable(true);
                    stage.hide();
                    return;
                }
                example.createCriteria().andEqualTo("rolename",ss).andEqualTo("guid","ae990cd2d33a4aa2bc9a52963925bf22");
                if(sysRoleMapper.selectByExample(example).size()>0) {
                    guiContext.stoporstartcheck(0);
                       String newsq = IdUtils.getUUID();//一旦授权成功 上一次授权码作废 随机生成最新的授权码
                    example.createCriteria().andEqualTo("guid","ae990cd2d33a4aa2bc9a52963925bf22");
                    SysRole sysRole =new SysRole();
                    try {
                        sysRole.setRolename(AESUtil.Encrypt(newsq));
                    } catch (Exception e) {
                        DialogUtils.showHeaderTextInformationAlert("警告随机授权码生成失败指纹验证关闭失败",stg);
                        guiContext.stoporstartcheck(1);
                        e.printStackTrace();
                    }
                    sysRoleMapper.updateByExampleSelective(sysRole,example);
                    System.out.println("指纹卡片验证已关闭");
                }else{
                    DialogUtils.showHeaderTextInformationAlert("授权码错误",stg);
                    t.setSelected(true);
                    t.setFocusTraversable(true);
                    stage.close();
                    return;
                }
                stage.close();
            }
        });
        vBox.getChildren().addAll(text,btn);
        root.getChildren().add(vBox);
     //hsz   root.getChildren().add(textField);
        stage.setScene(scene);
        stage.show();

    }

}