normal用户同一时间只能有一个登录session,如何实现多个登录?

声明:本博客只代表作者本人,不代表作者所在公司和组织等。如因此采用本博客内容造成的损失和不便,本博客概不负责。如需相应service请联系对应厂商


1,下载client

      

2,编写脚本

      脚本A(foreverToken.pl)

-----------------

#!/usr/bin/perl -w
use BuildForge::Services;

        $conn = new BuildForge::Services::Connection('localhost');
        $token = $conn->authUser('yq','qq');
        print "token: $token \n";
        #$conn->authToken($token);
 
        # Getting existing projects
        $project = BuildForge::Services::DBO::Project->findByName($conn, 'proj1');

        # Getter / setter functions
        $id = $project->getProjectId();
        $name = $project->getName();
        $class = $project->getBuildClass();
        $env = $project->getEnvironmentId();

        print "Name: $name \n";
        print "ID: $id \n";
        print "Class: $class \n";
        print "Env ID: $env \n";
        
        #wait for a very long, the other script can use the same session.
        my $verbose = 99999999;
        my $idx = 0;
        while ($idx<$verbose) {
         sleep 20;
         $idx =$idx+1;
         warn "index: $idx\n";
       }
                
        $conn->logout;
        $conn->close;

       脚本B(shareToken.pl

-------------------------

#!/usr/bin/perl -w
use BuildForge::Services;

        $conn = new BuildForge::Services::Connection('localhost');
        #$token = $conn->authUser('yq','qq');

        #get the token after the scriptA is executed
        $conn->authToken('77baef380c571000ca2b83f44d314d31');
 
        # Getting existing projects
        $project = BuildForge::Services::DBO::Project->findByName($conn, 'proj2share');

        # Getter / setter functions
        $id = $project->getProjectId();
        $name = $project->getName();
        $class = $project->getBuildClass();
        $env = $project->getEnvironmentId();

        print "Name: $name \n";
        print "ID: $id \n";
        print "Class: $class \n";
        print "Env ID: $env \n";
        
        
        #don't logout or close, for myabe other scripts are using this session at the same time
         print "exit";

3, 执行脚本

    如图1所示的目录结构

     perl -I "c:\\autofvt\rbf-services\lib" foreverToken.pl

     得到输出token,后修改shareToken.pl,然后在新的cmd窗口执行shareToken.pl

     perl -I "c:\\autofvt\rbf-services\lib" shareToken.pl


好的,下面是一个简单的JavaFX登陆界面连接数据库的示例: 首先,我们需要创建一个包含用户名和密码字段的数据库表。假设我们已经创建了一个名为“users”的表,并且包含“username”和“password”两个字段。 接下来,我们需要创建一个JavaFX界面。在这个例子中,我们将创建一个包含两个文本框和两个按钮的界面,用于用户输入用户名和密码,以及进行登录和注册操作。 ```java import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.stage.Stage; public class LoginApp extends Application { @Override public void start(Stage primaryStage) throws Exception { // 创建一个网格布局 GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); // 添加界面元素 Label sceneTitle = new Label("Welcome"); sceneTitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20)); grid.add(sceneTitle, 0, 0, 2, 1); Label userName = new Label("User Name:"); grid.add(userName, 0, 1); TextField userTextField = new TextField(); grid.add(userTextField, 1, 1); Label pw = new Label("Password:"); grid.add(pw, 0, 2); PasswordField pwBox = new PasswordField(); grid.add(pwBox, 1, 2); Button loginBtn = new Button("Login"); Button registerBtn = new Button("Register"); HBox hbBtn = new HBox(10); hbBtn.setAlignment(Pos.BOTTOM_RIGHT); hbBtn.getChildren().addAll(loginBtn, registerBtn); grid.add(hbBtn, 1, 4); // 创建一个场景并设置到主舞台 Scene scene = new Scene(grid, 300, 275); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } ``` 接下来,我们需要添加登录和注册的功能。我们将使用JavaFX的事件处理程序来实现这些功能。对于登录操作,我们将检查用户输入的用户名和密码是否匹配数据库中的记录。对于注册操作,我们将在数据库中创建一个新的用户记录。 ```java import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.stage.Stage; public class LoginApp extends Application { @Override public void start(Stage primaryStage) throws Exception { // 创建一个网格布局 GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); // 添加界面元素 Label sceneTitle = new Label("Welcome"); sceneTitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20)); grid.add(sceneTitle, 0, 0, 2, 1); Label userName = new Label("User Name:"); grid.add(userName, 0, 1); TextField userTextField = new TextField(); grid.add(userTextField, 1, 1); Label pw = new Label("Password:"); grid.add(pw, 0, 2); PasswordField pwBox = new PasswordField(); grid.add(pwBox, 1, 2); Button loginBtn = new Button("Login"); Button registerBtn = new Button("Register"); HBox hbBtn = new HBox(10); hbBtn.setAlignment(Pos.BOTTOM_RIGHT); hbBtn.getChildren().addAll(loginBtn, registerBtn); grid.add(hbBtn, 1, 4); // 添加事件处理程序 loginBtn.setOnAction(event -> { String username = userTextField.getText(); String password = pwBox.getText(); if (verifyLogin(username, password)) { // 登录成功,跳转到主界面 // TODO: 实现跳转逻辑 } else { // 登录失败,显示错误信息 sceneTitle.setText("Login Failed!"); } }); registerBtn.setOnAction(event -> { String username = userTextField.getText(); String password = pwBox.getText(); if (registerUser(username, password)) { // 注册成功,显示成功信息 sceneTitle.setText("Registration Successful!"); } else { // 注册失败,显示错误信息 sceneTitle.setText("Registration Failed!"); } }); // 创建一个场景并设置到主舞台 Scene scene = new Scene(grid, 300, 275); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } // 验证登录 private boolean verifyLogin(String username, String password) { try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useSSL=false", "root", "password"); PreparedStatement stmt = conn.prepareStatement("SELECT * FROM users WHERE username = ? AND password = ?")) { stmt.setString(1, username); stmt.setString(2, password); ResultSet rs = stmt.executeQuery(); return rs.next(); } catch (SQLException e) { e.printStackTrace(); return false; } } // 注册用户 private boolean registerUser(String username, String password) { try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useSSL=false", "root", "password"); PreparedStatement stmt = conn.prepareStatement("INSERT INTO users (username, password) VALUES (?, ?)")) { stmt.setString(1, username); stmt.setString(2, password); stmt.executeUpdate(); return true; } catch (SQLException e) { e.printStackTrace(); return false; } } } ``` 注意,在这个例子中,我们使用了Java的JDBC API来连接数据库。你需要根据你的数据库类型和配置来修改这个代码中的连接字符串、用户名和密码。同时,你也需要将MySQL驱动程序添加到你的项目中,以便在运行时加载它。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值