Commit 247a7347 by Carwyn

Merge branch 'master' of git.oschina.net:kong__mo/fmp_home

1.合并登录保存密码; 2. 登录消息提示样式优化
parents 7c265f04 8c80c808
#ifndef ALGORITHM_H
#define ALGORITHM_H
#include <QCryptographicHash>
#include <QByteArray>
#include <QDateTime>
// md5字符串分段点
const qint8 pwd[] = {0, 5, 7, 13, 21, 32};
QByteArray encrypt(const QByteArray &plaintext)
{
QByteArray md5 = QCryptographicHash::hash(QByteArray::number(QDateTime::currentMSecsSinceEpoch()), QCryptographicHash::Md5).toHex();
QByteArray base64 = plaintext.toBase64();
int group = base64.length() / 4;
QByteArray cipertext = "";
for(int i=0; i<5; i++)
{
cipertext += md5.mid(pwd[i], pwd[i+1]-pwd[i]);
cipertext += base64.mid(i*group, group);
}
return cipertext;
}
QByteArray decrypt(const QByteArray &ciphertext)
{
int group = (ciphertext.length()-(pwd[5]-pwd[0])) / 4;
QByteArray base64 = "";
for(int i=0; i<5; i++)
{
base64 += ciphertext.mid(pwd[i+1]-pwd[0]+i*group, group);
}
QByteArray plaintext = QByteArray::fromBase64(base64);
return plaintext;
}
#endif // ALGORITHM_H
...@@ -23,7 +23,8 @@ SOURCES +=\ ...@@ -23,7 +23,8 @@ SOURCES +=\
fmp_he_handlers.cpp \ fmp_he_handlers.cpp \
fmnumpad.cpp \ fmnumpad.cpp \
fmp_home_settings.cpp \ fmp_home_settings.cpp \
fmp_flicker.cpp fmp_flicker.cpp \
fmp_message.cpp
HEADERS += fmp_home.h \ HEADERS += fmp_home.h \
fmp_home_plugin_p.h \ fmp_home_plugin_p.h \
...@@ -37,12 +38,15 @@ HEADERS += fmp_home.h \ ...@@ -37,12 +38,15 @@ HEADERS += fmp_home.h \
fmp_he_handlers.h \ fmp_he_handlers.h \
fmnumpad.h \ fmnumpad.h \
fmp_home_settings.h \ fmp_home_settings.h \
fmp_flicker.h fmp_flicker.h \
algorithm.h \
fmp_message.h
FORMS += \ FORMS += \
fmp_home_navwindow.ui \ fmp_home_navwindow.ui \
fmp_login.ui \ fmp_login.ui \
fmnumpad.ui fmnumpad.ui \
fmp_message.ui
unix { unix {
target.path = /usr/lib target.path = /usr/lib
......
...@@ -74,17 +74,15 @@ int FMPHomePrivate::login() ...@@ -74,17 +74,15 @@ int FMPHomePrivate::login()
if(loginWnd.isLogined()) { if(loginWnd.isLogined()) {
_isLogined = true; _isLogined = true;
_userName = loginWnd.userName(); _userName = loginWnd.userName();
return FMP_SUCCESS;
} else { } else {
_isLogined = false; _isLogined = false;
return FMP_FAILURE;
} }
#else #else
_isLogining = false; _isLogining = false;
_isLogined = true; _isLogined = true;
_userName = ""; _userName = "";
return FMP_SUCCESS;
#endif #endif
return (_isLogined ? FMP_SUCCESS : FMP_FAILURE);
} }
int FMPHomePrivate::blink(FMPluginInterface *plugin, const QString &image) int FMPHomePrivate::blink(FMPluginInterface *plugin, const QString &image)
...@@ -130,6 +128,12 @@ void FMPHomePrivate::onMenuBtnClicked(QString btnName) ...@@ -130,6 +128,12 @@ void FMPHomePrivate::onMenuBtnClicked(QString btnName)
if(!_isLogined && btnName!="tool") { if(!_isLogined && btnName!="tool") {
if(login() != FMP_SUCCESS) { if(login() != FMP_SUCCESS) {
return; return;
} else if(btnName != "takeout") {
// 启动外卖
FMPBaseInterface *svc = q->GetService<FMPTakeoutInterface>(q->_ctx);
if(svc) {
svc->StartService();
}
} }
} }
......
...@@ -60,6 +60,16 @@ QString FMPHomeSettings::getStroeId() ...@@ -60,6 +60,16 @@ QString FMPHomeSettings::getStroeId()
return _GetValue(FMP_INIKEY_LOGINSTOREID).toString(); return _GetValue(FMP_INIKEY_LOGINSTOREID).toString();
} }
bool FMPHomeSettings::getIsRememberPwd()
{
return _GetValue(FMP_INIKEY_REMEMBERPWD, false).toBool();
}
bool FMPHomeSettings::setIsRememberPwd(bool isRemember)
{
return _SetValue(FMP_INIKEY_REMEMBERPWD, isRemember);
}
QVariant FMPHomeSettings::_GetValue(const QString &key, QVariant defaultValue) QVariant FMPHomeSettings::_GetValue(const QString &key, QVariant defaultValue)
{ {
if (_settings) { if (_settings) {
......
...@@ -51,6 +51,14 @@ public: ...@@ -51,6 +51,14 @@ public:
*/ */
QString getStroeId(); QString getStroeId();
/**
* @brief getIsRememberPwd setIsRememberPwd
* 获取/设置是否记住登录密码
* @return
*/
bool getIsRememberPwd();
bool setIsRememberPwd(bool isRemember);
private: private:
explicit FMPHomeSettings(QObject *parent = 0); explicit FMPHomeSettings(QObject *parent = 0);
......
#include "fmp_login.h" #include "fmp_login.h"
#include "ui_fmp_login.h" #include "ui_fmp_login.h"
#include "algorithm.h"
#include "fmp_home_settings.h" #include "fmp_home_settings.h"
#include <QMessageBox> #include "fmp_message.h"
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonParseError> #include <QJsonParseError>
#include <QProcess>
#include <QFile>
#include "fmnetwork.h" #include "fmnetwork.h"
#include <QDebug> #include <QDebug>
...@@ -28,6 +31,14 @@ FMPLogin::FMPLogin(QDialog *parent) : ...@@ -28,6 +31,14 @@ FMPLogin::FMPLogin(QDialog *parent) :
_url = FMPHomeSettings::instance()->getServer(); _url = FMPHomeSettings::instance()->getServer();
_storeId = FMPHomeSettings::instance()->getStroeId(); _storeId = FMPHomeSettings::instance()->getStroeId();
_partnerId = FMPHomeSettings::instance()->getPartnerId(); _partnerId = FMPHomeSettings::instance()->getPartnerId();
if(FMPHomeSettings::instance()->getIsRememberPwd()) {
QString userName, password;
readPassword(userName, password);
ui->user_edit->setText(userName);
ui->pwd_edit->setText(password);
ui->remember_check->setChecked(true);
}
} }
FMPLogin::~FMPLogin() FMPLogin::~FMPLogin()
...@@ -37,12 +48,22 @@ FMPLogin::~FMPLogin() ...@@ -37,12 +48,22 @@ FMPLogin::~FMPLogin()
void FMPLogin::on_login_btn_clicked() void FMPLogin::on_login_btn_clicked()
{ {
if(ui->user_edit->text().isEmpty()) {
FMPMessage::critical(this, QString::fromLocal8Bit("账号不能为空"));
ui->user_edit->setFocus();
return;
} else if(ui->pwd_edit->text().isEmpty()) {
FMPMessage::critical(this, QString::fromLocal8Bit("密码不能为空"));
ui->pwd_edit->setFocus();
return;
}
this->setEnabled(false); this->setEnabled(false);
if(login(ui->user_edit->text(), ui->pwd_edit->text())) { if(login(ui->user_edit->text(), ui->pwd_edit->text())) {
this->close(); this->close();
} else { } else {
QMessageBox::critical(this, "Login Failed", _errorMsg); FMPMessage::critical(this, _errorMsg);
this->setEnabled(true); this->setEnabled(true);
ui->pwd_edit->clear(); ui->pwd_edit->clear();
ui->pwd_edit->setFocus(); ui->pwd_edit->setFocus();
...@@ -75,7 +96,17 @@ bool FMPLogin::login(QString userName, QString password) ...@@ -75,7 +96,17 @@ bool FMPLogin::login(QString userName, QString password)
_errorMsg = error.errorString(); _errorMsg = error.errorString();
} }
} }
return isLogined();
if(isLogined()) {
if(ui->remember_check->isChecked()) {
FMPHomeSettings::instance()->setIsRememberPwd(true);
savePassword(userName, password);
} else {
FMPHomeSettings::instance()->setIsRememberPwd(false);
}
return true;
}
return false;
} }
void FMPLogin::onFocusChanged(QWidget *, QWidget *now) void FMPLogin::onFocusChanged(QWidget *, QWidget *now)
...@@ -84,3 +115,46 @@ void FMPLogin::onFocusChanged(QWidget *, QWidget *now) ...@@ -84,3 +115,46 @@ void FMPLogin::onFocusChanged(QWidget *, QWidget *now)
// ui->numpad->setLineEdit(qobject_cast<QLineEdit*>(now)); // ui->numpad->setLineEdit(qobject_cast<QLineEdit*>(now));
} }
} }
void FMPLogin::savePassword(const QString &userName, const QString &pwd)
{
bool isCreate = false;
QString fileName = qApp->applicationDirPath() + "/.fmp";
QFile file(fileName);
isCreate = !file.exists();
if(!file.open(QIODevice::WriteOnly)) {
return;
}
QDataStream out(&file);
out << encrypt(userName.toUtf8());
out << encrypt(pwd.toUtf8());
file.close();
if(isCreate) {
QString program = "attrib";
QStringList arguments;
arguments << "+h" << fileName;
QProcess *process = new QProcess(this);
process->start(program, arguments);
process->waitForFinished(3000);
}
}
void FMPLogin::readPassword(QString &userName, QString &pwd)
{
QFile file(qApp->applicationDirPath() + "/.fmp");
if(!file.open(QIODevice::ReadOnly)) {
return;
}
QDataStream out(&file);
QByteArray n, p;
out >> n >> p;
userName = decrypt(n);
pwd = decrypt(p);
file.close();
}
...@@ -26,6 +26,7 @@ public: ...@@ -26,6 +26,7 @@ public:
QString userName() {return _userName;} QString userName() {return _userName;}
QString errorMsg() {return _errorMsg;} QString errorMsg() {return _errorMsg;}
private slots: private slots:
void on_login_btn_clicked(); void on_login_btn_clicked();
...@@ -40,6 +41,9 @@ private: ...@@ -40,6 +41,9 @@ private:
QString _url; QString _url;
QString _storeId; QString _storeId;
QString _partnerId; QString _partnerId;
void savePassword(const QString &userName, const QString &pwd);
void readPassword(QString &userName, QString &pwd);
}; };
#endif // FMP_LOGIN_H #endif // FMP_LOGIN_H
...@@ -83,6 +83,12 @@ ...@@ -83,6 +83,12 @@
border-left: 0; border-left: 0;
} }
#remember_check {
font: 300 15px &quot;Microsoft YaHei&quot;;
max-height: 20px;
margin-bottom: 10px;
}
#login_btn { #login_btn {
min-height: 56px; min-height: 56px;
background: rgb(99, 148, 235); background: rgb(99, 148, 235);
...@@ -200,7 +206,7 @@ ...@@ -200,7 +206,7 @@
<widget class="QWidget" name="user" native="true"> <widget class="QWidget" name="user" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing"> <property name="spacing">
<number>25</number> <number>0</number>
</property> </property>
<property name="leftMargin"> <property name="leftMargin">
<number>124</number> <number>124</number>
...@@ -219,6 +225,9 @@ ...@@ -219,6 +225,9 @@
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </property>
<property name="bottomMargin">
<number>20</number>
</property>
<item> <item>
<widget class="QLabel" name="user_label"> <widget class="QLabel" name="user_label">
<property name="margin"> <property name="margin">
...@@ -284,6 +293,16 @@ ...@@ -284,6 +293,16 @@
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="remember_check">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>记住密码</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="login_btn"> <widget class="QPushButton" name="login_btn">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
......
#include "fmp_message.h"
#include "ui_fmp_message.h"
FMPMessage::FMPMessage(QWidget *parent) : QDialog(parent), ui(new Ui::FMPMessage)
{
ui->setupUi(this);
setAttribute(Qt::WA_TranslucentBackground);
ui->widget->setWindowOpacity(1);
setGeometry(parent->geometry());
this->move(parent->pos());
setWindowFlags(Qt::FramelessWindowHint| Qt::Tool );
connect(ui->btn_confirm, &QPushButton::clicked, this, &FMPMessage::accept);
qRegisterMetaType<FMPMessage::Type>("FMPMessage::Type");
//setStyleSheet("QWidget#mainWdg{background:rgba(110,110,110,0.5)}");
}
FMPMessage::~FMPMessage()
{
delete ui;
}
void FMPMessage::SetContent(FMPMessage::Type type, const QString &msg)
{
switch (type) {
case FMPMessage::SUCCESS:
ui->btn_confirm->setVisible(true);
ui->label_logo->setStyleSheet("#label_logo {background: url(:/img/loading.png) center no-repeat;}");
break;
case FMPMessage::ERROR:
ui->btn_confirm->setVisible(true);
ui->label_logo->setStyleSheet("#label_logo {background: url(:/img/fmclient-icon_payment_fail.png) center no-repeat;}");
break;
case FMPMessage::LOADING:
ui->label_logo->setStyleSheet("#label_logo {background: url(:/img/loading.png) center no-repeat;}");
ui->btn_confirm->setVisible(false);
break;
default:
ui->btn_confirm->setVisible(true);
ui->label_logo->setStyleSheet("#label_logo {background: url(:/img/loading.png) center no-repeat;}");
break;
}
ui->label_msg->setText(msg);
}
int FMPMessage::critical(QWidget *parent, const QString &msg)
{
FMPMessage window(parent);
window.SetContent(FMPMessage::ERROR, msg);
return window.exec();
}
#ifndef WAITDIALOG_H
#define WAITDIALOG_H
#include <QDialog>
namespace Ui {
class FMPMessage;
}
class FMPMessage : public QDialog
{
Q_OBJECT
public:
explicit FMPMessage(QWidget *parent = 0);
~FMPMessage();
typedef enum
{
SUCCESS=0,
ERROR,
LOADING
}Type;
void SetContent(FMPMessage::Type type, const QString& msg);
static int critical(QWidget *parent, const QString &msg);
private:
Ui::FMPMessage *ui;
};
#endif // WAITDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FMPMessage</class>
<widget class="QDialog" name="FMPMessage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>553</width>
<height>414</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="styleSheet">
<string notr="true">#FMPPayWait
{
opacity: 223;
background-color: rgb(148, 148, 148, 0);
}
#label_logo {
background: url(:/img/loading.png) no-repeat center;
}</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QWidget" name="mainWdg" native="true">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>182</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>13</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<property name="minimumSize">
<size>
<width>344</width>
<height>222</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>344</width>
<height>222</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">#widget
{
background-color: rgb(255, 255, 255);
border: 1 solid silver;
border-radius:8px;
opacity:0;
}</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_logo">
<property name="minimumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_msg">
<property name="minimumSize">
<size>
<width>161</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<family>微软雅黑</family>
<pointsize>-1</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">#label_msg
{
color: rgb(100, 100, 100);
font: 22px &quot;微软雅黑&quot;;
}</string>
</property>
<property name="text">
<string>支付中...</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>13</width>
<height>57</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btn_confirm">
<property name="minimumSize">
<size>
<width>121</width>
<height>62</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>62</height>
</size>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="styleSheet">
<string notr="true">#btn_confirm
{
font: normal 26px &quot;微软雅黑&quot;;
border: 1 solid silver;
border-top: 0;
border-bottom-right-radius: 8px;
border-bottom-left-radius: 8px;
background-color: rgb(93, 144, 236);
color: rgb(255, 255, 255);
}</string>
</property>
<property name="text">
<string>确认</string>
</property>
</widget>
</item>
</layout>
<zorder>verticalSpacer</zorder>
<zorder>verticalSpacer_2</zorder>
<zorder>btn_confirm</zorder>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>13</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>181</height>
</size>
</property>
</spacer>
</item>
</layout>
<zorder>verticalSpacer_4</zorder>
<zorder>verticalSpacer_3</zorder>
<zorder></zorder>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment