增加登录功能
|
@ -17,6 +17,7 @@ FILE(GLOB SDK_SRC
|
|||
find_package(catkin REQUIRED COMPONENTS
|
||||
rviz roscpp std_msgs
|
||||
rosconsole sensor_msgs # node.cpp
|
||||
rosbag
|
||||
)
|
||||
|
||||
|
||||
|
@ -57,6 +58,7 @@ set(SRC_FILES
|
|||
src/myviz.cpp
|
||||
src/main.cpp
|
||||
tools/color.cpp
|
||||
src/loginDialog.cpp
|
||||
)
|
||||
|
||||
## Add the "myviz" executable and specify the list of source files we
|
||||
|
@ -68,7 +70,7 @@ add_executable(myviz ${SRC_FILES} )
|
|||
|
||||
add_executable(rplidarNode src/node.cpp ${SDK_SRC}) # 创建启动laser
|
||||
target_link_libraries(rplidarNode ${catkin_LIBRARIES})
|
||||
|
||||
target_link_libraries(myviz -lcrypto)
|
||||
|
||||
|
||||
## Link the myviz executable with whatever Qt libraries have been defined by
|
||||
|
|
After Width: | Height: | Size: 191 B |
After Width: | Height: | Size: 188 B |
After Width: | Height: | Size: 188 B |
After Width: | Height: | Size: 157 B |
After Width: | Height: | Size: 155 B |
After Width: | Height: | Size: 157 B |
After Width: | Height: | Size: 154 B |
After Width: | Height: | Size: 154 B |
After Width: | Height: | Size: 157 B |
After Width: | Height: | Size: 152 B |
After Width: | Height: | Size: 155 B |
|
@ -0,0 +1,5 @@
|
|||
root 123!@
|
||||
wbw 1234
|
||||
|
||||
## 待删除,保存原始用户密码
|
||||
##
|
|
@ -0,0 +1,2 @@
|
|||
root p<><70><EFBFBD><08><><EFBFBD><EFBFBD>w<>:<3A><>R<EFBFBD>wH<77>pD<02><>#<23><><EFBFBD>6
|
||||
wbw <03>gB<16><>\v<1E><><EFBFBD>U<EFBFBD>g<EFBFBD>6#ȳ<><C8B3>E<EFBFBD><13>x<EFBFBD><78>F<EFBFBD>
|
|
@ -0,0 +1,206 @@
|
|||
#include "loginDialog.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include<QDebug>
|
||||
|
||||
LoginDialog::LoginDialog(QWidget *parent):QDialog(parent)
|
||||
{
|
||||
userLabel = new QLabel(this);
|
||||
userLabel->move(80, 80);
|
||||
userLabel->setText(tr("用户名"));
|
||||
|
||||
userEditLine = new QLineEdit(this);
|
||||
userEditLine->move(150, 80);
|
||||
userEditLine->setPlaceholderText(tr("请输入用户名"));
|
||||
|
||||
pwdLabel = new QLabel(this);
|
||||
pwdLabel->move(80, 130);
|
||||
pwdLabel->setText(tr("密码"));
|
||||
|
||||
pwdEditLine = new QLineEdit(this);
|
||||
pwdEditLine->move(150, 130);
|
||||
pwdEditLine->setPlaceholderText(tr("请输入密码"));
|
||||
pwdEditLine->setEchoMode(QLineEdit::Password);
|
||||
|
||||
loginBtn = new QPushButton(this);
|
||||
loginBtn->move(60, 200);
|
||||
loginBtn->setText(tr("登录"));
|
||||
|
||||
exitBtn = new QPushButton(this);
|
||||
exitBtn->move(220, 200);
|
||||
exitBtn->setText(tr("退出"));
|
||||
|
||||
connect(loginBtn, &QPushButton::clicked, this, &LoginDialog::login);
|
||||
connect(exitBtn, &QPushButton::clicked, this, &LoginDialog::close);
|
||||
|
||||
// 待解锁的组件名称
|
||||
setting_name = {"laser_topic", "open_file", "bag_progress"};
|
||||
|
||||
// to do read from file
|
||||
createUser();
|
||||
// userPasswords["root"] = hashPassword("root123");
|
||||
// userPasswords["wbw"] = hashPassword("123");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LoginDialog::createUser(){
|
||||
std::ifstream inputFile("../Rviz/librviz_ws/src/librviz_tutorial/sources/user/user.txt");
|
||||
// 第一次读写user.txt将user加密后,建立userPasswords
|
||||
if(inputFile.is_open()){
|
||||
std::string line;
|
||||
while(std::getline(inputFile, line)){
|
||||
std::istringstream iss(line);
|
||||
std::string username, pwd;
|
||||
if(iss>> username && iss>> pwd){
|
||||
if(pwd.size() < 8){
|
||||
// 根据长度判断是否已经被加密
|
||||
pwd = hashPassword(pwd);
|
||||
}
|
||||
// 创建map/用户表
|
||||
userPasswords[QString::fromStdString(username)] = QString::fromStdString(pwd);
|
||||
}
|
||||
}
|
||||
inputFile.close();
|
||||
}else{
|
||||
qDebug() << "Unable to open the user.txt.";
|
||||
}
|
||||
writeHash(userPasswords);
|
||||
}
|
||||
|
||||
// 加密后的账户密码写入user.txt
|
||||
void LoginDialog::writeHash(const std::map<QString, QString> user){
|
||||
std::ofstream file("../Rviz/librviz_ws/src/librviz_tutorial/sources/user/user.txt");
|
||||
|
||||
if(file.is_open()){
|
||||
for(auto iter = user.begin(); iter != user.end() ; iter++){
|
||||
file << (iter->first).toStdString() << " ";
|
||||
file << (iter->second).toStdString() << std::endl;
|
||||
}
|
||||
file.close();
|
||||
}else{
|
||||
qDebug()<<"Unable to write hashcode!!!";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// hash加密函数
|
||||
QString LoginDialog::hashPassword(const QString& pwd) {
|
||||
std::string password = pwd.toStdString();
|
||||
unsigned char hash[SHA256_DIGEST_LENGTH];
|
||||
SHA256_CTX sha256;
|
||||
SHA256_Init(&sha256);
|
||||
SHA256_Update(&sha256, password.c_str(), password.size());
|
||||
SHA256_Final(hash, &sha256);
|
||||
|
||||
std::string hashedPassword;
|
||||
for (int i = 0; i < SHA256_DIGEST_LENGTH; ++i) {
|
||||
hashedPassword += hash[i];
|
||||
}
|
||||
return QString(hashedPassword.c_str());
|
||||
}
|
||||
|
||||
// 重载加密函数
|
||||
std::string LoginDialog::hashPassword(const std::string& password) {
|
||||
// std::string password = pwd.toStdString();
|
||||
unsigned char hash[SHA256_DIGEST_LENGTH];
|
||||
SHA256_CTX sha256;
|
||||
SHA256_Init(&sha256);
|
||||
SHA256_Update(&sha256, password.c_str(), password.size());
|
||||
SHA256_Final(hash, &sha256);
|
||||
|
||||
std::string hashedPassword;
|
||||
for (int i = 0; i < SHA256_DIGEST_LENGTH; ++i) {
|
||||
hashedPassword += hash[i];
|
||||
}
|
||||
return hashedPassword;
|
||||
}
|
||||
|
||||
|
||||
// 判断用户账号返回不同code
|
||||
int LoginDialog::checkUser(const QString username, const QString pwd){
|
||||
auto iter = userPasswords.find(username);
|
||||
if (iter != userPasswords.end()) {
|
||||
if(iter->second == hashPassword(pwd)){
|
||||
// 用户密码都对
|
||||
return 2;
|
||||
}else{
|
||||
// 用户对,密码不对
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
// 用户不对
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 槽函数
|
||||
void LoginDialog::login()
|
||||
{
|
||||
int flag = checkUser(userEditLine->text().trimmed(), pwdEditLine->text());
|
||||
switch(flag){
|
||||
case 0: {
|
||||
QMessageBox::warning(this, tr("登录失败"), tr("用户名错误"), QMessageBox::Ok);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
QMessageBox::warning(this, tr("登录失败"), tr("密码错误"), QMessageBox::Ok);
|
||||
break;
|
||||
}
|
||||
case 2:{
|
||||
for(int i=0 ; i<setting_name.size(); i++){
|
||||
QWidget *foundChild = parent()->findChild<QWidget*>(setting_name[i]);
|
||||
if (foundChild) {
|
||||
// 找到了指定的子组件 在这里可以对子组件进行操作
|
||||
foundChild->setEnabled(true);
|
||||
}else{
|
||||
qDebug()<<"第" << i+1 <<"组件未找到" ;
|
||||
}
|
||||
}
|
||||
QMessageBox::information(this, tr("登录成功"), tr("已解锁"), QMessageBox::Ok);
|
||||
accept();
|
||||
}
|
||||
}
|
||||
userEditLine->clear();
|
||||
pwdEditLine->clear();
|
||||
userEditLine->setFocus();
|
||||
// //判断用户名和密码是否正确 todo 函数判断
|
||||
// if (userEditLine->text().trimmed() == tr("tom") &&
|
||||
// pwdEditLine->text() == tr("123456"))
|
||||
// {
|
||||
// for(int i=0 ; i<setting_name.size(); i++){
|
||||
// QWidget *foundChild = parent()->findChild<QWidget*>(setting_name[i]);
|
||||
// if (foundChild) {
|
||||
// qDebug()<<"111" ;
|
||||
// // 找到了指定的子组件 在这里可以对子组件进行操作
|
||||
// foundChild->setEnabled(true);
|
||||
// }else{
|
||||
// qDebug()<<"第" << i+1 <<"组件未找到" ;
|
||||
// }
|
||||
// }
|
||||
// QMessageBox::information(this, tr("登录成功"), tr("已解锁"), QMessageBox::Yes);
|
||||
// // landed = 1;
|
||||
// accept();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// QMessageBox::warning(this, tr("登录失败"), tr("用户名或者密码错误"), QMessageBox::Yes);
|
||||
// }
|
||||
// userEditLine->clear();
|
||||
// pwdEditLine->clear();
|
||||
// userEditLine->setFocus();
|
||||
|
||||
|
||||
// QMessageBox::information(this, tr("提示"), tr("已经登陆,请勿重新登录"), QMessageBox::Yes);
|
||||
|
||||
}
|
||||
|
||||
|
||||
LoginDialog::~LoginDialog()
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
#ifndef LOGINDIALOG_H
|
||||
#define LOGINDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include<iostream>
|
||||
#include<vector>
|
||||
#include <map>
|
||||
#include <openssl/sha.h>
|
||||
#include <fstream>
|
||||
#include<sstream>
|
||||
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
class QPushButton;
|
||||
|
||||
|
||||
class LoginDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LoginDialog(QWidget *parent = 0);
|
||||
~LoginDialog();
|
||||
int checkUser(const QString username, const QString pwd);
|
||||
QString hashPassword(const QString& pwd);
|
||||
std::string hashPassword(const std::string& password); // 重载
|
||||
void createUser();
|
||||
void writeHash(const std::vector<std::string> usernames, const std::vector<std::string> pwds);
|
||||
void writeHash(const std::map<QString, QString>);
|
||||
// 待解锁组件名
|
||||
std::vector<QString> setting_name;
|
||||
|
||||
//槽函数
|
||||
private Q_SLOTS:
|
||||
void login();
|
||||
|
||||
private:
|
||||
QLabel *userLabel;
|
||||
QLabel *pwdLabel;
|
||||
|
||||
QLineEdit *userEditLine;
|
||||
QLineEdit *pwdEditLine;
|
||||
|
||||
QPushButton *loginBtn;
|
||||
QPushButton *exitBtn;
|
||||
// 待解锁组件名
|
||||
// std::vector<QString> setting_name;
|
||||
// 用户表
|
||||
std::map<QString, QString> userPasswords;
|
||||
|
||||
};
|
||||
|
||||
#endif // LOGINDIALOG_H
|
||||
|
|
@ -37,6 +37,7 @@
|
|||
#include <ros/ros.h>
|
||||
#include "myviz.h"
|
||||
#include<iostream>
|
||||
#include<QDebug>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
|
|
@ -29,17 +29,32 @@
|
|||
#ifndef MYVIZ_H
|
||||
#define MYVIZ_H
|
||||
|
||||
|
||||
#include <QWidget>
|
||||
#include<QString>
|
||||
#include <QGridLayout>
|
||||
#include<ros/ros.h>
|
||||
#include"std_msgs/String.h"
|
||||
#include<thread>
|
||||
#include <visualization_msgs/Marker.h>
|
||||
|
||||
#include<QTimer>
|
||||
#include <QMutex>
|
||||
#include <QProcess>
|
||||
#include <QThread>
|
||||
#include<QSlider>
|
||||
#include <rosbag/bag.h>
|
||||
#include <sensor_msgs/LaserScan.h>
|
||||
#include <rosbag/view.h>
|
||||
#include"loginDialog.h"
|
||||
|
||||
namespace rviz
|
||||
{
|
||||
class Display;
|
||||
class RenderPanel;
|
||||
class VisualizationManager;
|
||||
class ToolManager;
|
||||
class PropertyTreeWidget;
|
||||
}
|
||||
|
||||
// BEGIN_TUTORIAL
|
||||
|
@ -52,6 +67,8 @@ public:
|
|||
virtual ~MyViz();
|
||||
void subCallback(const std_msgs::String& msg);
|
||||
void pubThread();
|
||||
void PlayCircle(int index); // 圆圈线程执行函数
|
||||
rosbag::View *view;
|
||||
private Q_SLOTS: // QT信号和槽
|
||||
void setThickness( int thickness_percent );
|
||||
void setCellSize( int cell_size_percent );
|
||||
|
@ -64,18 +81,78 @@ private Q_SLOTS: // QT信号和槽
|
|||
void GridColorChanged(int index); // 格栅颜色
|
||||
void setFixedFrame(const QString &FixedFrame);
|
||||
void setBackgroundColor(const QString& bg_color); // 背景颜色
|
||||
void AxesDisplayChanged(int index); // axe
|
||||
void CircleDisplayChanged(int index); // circle
|
||||
void Tree_Display(QGridLayout* layout, int index);
|
||||
|
||||
void login_button_clicked();
|
||||
void quit_login_button_clicked();
|
||||
void slot_select(); // 切换至select模式
|
||||
void slot_move_camera();
|
||||
|
||||
// off
|
||||
double extractDuration(const QByteArray& output);
|
||||
void selectFile();
|
||||
void SpeedChanged(int index);
|
||||
void openFile();
|
||||
private:
|
||||
rviz::VisualizationManager* manager_; //
|
||||
rviz::RenderPanel* render_panel_;
|
||||
rviz::ToolManager* tool_manager_;
|
||||
rviz::Display* grid_;
|
||||
rviz::Display* cloud;
|
||||
rviz::Display* laser;
|
||||
rviz::Display* laser_;
|
||||
rviz::Display* axes_display;
|
||||
rviz::Display* marker_;
|
||||
rviz::PropertyTreeWidget* tree_widget_ ;
|
||||
ros::NodeHandle nh;
|
||||
ros::Subscriber sub;
|
||||
ros::Publisher pub;
|
||||
std::thread pub_thread;
|
||||
|
||||
std::vector<QString> color_name; // 颜色的名称集合
|
||||
QString color_icon_filename;
|
||||
|
||||
LoginDialog* dlg;
|
||||
bool landed;
|
||||
QString cur_fixed_frame;
|
||||
// off
|
||||
bool isclicked;// 用于判断play第几次按下play键
|
||||
bool ispauseclick;// 用于判断暂停键第几次按下
|
||||
int count;// 用于记录timeout的次数
|
||||
bool sliderreleased;// 用于判断是否拖动了进度条
|
||||
bool playagain;// 用于检测是否多次按下play按钮
|
||||
bool isthreadplaying;// 用于标识线程是否在运行
|
||||
bool abs;// 用于单独开线程?
|
||||
bool stored;// 用于存储一次容器,只在第一次play的时候存储容器
|
||||
bool is_pause = false;
|
||||
bool is_reset = false;
|
||||
bool is_end = false;
|
||||
bool is_save = false;
|
||||
bool is_saveMul = false;
|
||||
bool is_bagClosed = true;
|
||||
bool is_rateChanged = false;
|
||||
bool is_openFile = false;
|
||||
bool is_setFrameIndex = false;
|
||||
bool is_saveMulFinish = false;
|
||||
bool end = false;
|
||||
bool threadout = false;
|
||||
bool ischanged = false;
|
||||
bool ismoved = false;
|
||||
double speed_rate;
|
||||
QSlider* progress;
|
||||
QString filePath;
|
||||
double duration;
|
||||
int remain;
|
||||
int prog_num = 0;
|
||||
std::vector<QString> speed_name;
|
||||
ros::Publisher scan_pub;
|
||||
std::vector<sensor_msgs::LaserScan::ConstPtr> indx;// 存储节点信息
|
||||
int countbag;// 存储播放的具体位置
|
||||
double indxsize;
|
||||
int test = 0;
|
||||
|
||||
|
||||
};
|
||||
// END_TUTORIAL
|
||||
#endif // MYVIZ_H
|
||||
|
|