auwinodws.java
4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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();
}
}