Skip to content

Commit

Permalink
完善登录
Browse files Browse the repository at this point in the history
  • Loading branch information
Joy1024 committed Aug 7, 2024
1 parent 7223333 commit 9537bf6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
5 changes: 0 additions & 5 deletions src/UI/window/login/src/LoginWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,6 @@ void LoginWidget::onError(int statusCode, const QString& msg) {
m_currentOriginalMsg = "Network is not available!";
break;
}
case 4: {
newMsg = tr("Account does not exist!");
m_currentOriginalMsg = "Account does not exist!";
break;
}
case 5: {
newMsg = tr("Server error, please try again later!");
m_currentOriginalMsg = "Server error, please try again later!";
Expand Down
6 changes: 5 additions & 1 deletion src/lib/backend/PassportService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ bool PassportService::signIn(const QString& account, const QString& password,
Res<SysToken> res(Jsons::toJSON(doc));
fn(res);
},
nullptr, nullptr, err);
nullptr, nullptr,
[=](int statusCode, QByteArray body) {
Res<SysToken> res(Jsons::toJSON(body));
err(statusCode, res.msg.toUtf8());
});
}

bool PassportService::refresh(const SysToken& token, Fn<void(Res<SysRefreshToken>&)> fn,
Expand Down
9 changes: 4 additions & 5 deletions src/lib/network/NetworkHttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,17 @@ void NetworkHttp::doRequest(QNetworkRequest& req,
qDebug() << "statusCode:" << statusCode.toInt();
}

auto bytes = reply->readAll();
if (statusCode.toInt() / 100 != 2) {
qWarning() << "Error:" << reply->errorString();
qWarning() << "body:" << bytes;
if (failed) {
failed(statusCode.toInt(), reply->errorString());
failed(statusCode.toInt(), bytes);
}
return;
}

auto bytes = reply->readAll();
auto size = bytes.size();
qDebug() << "Received bytes:" << size;

if (size <= 0) {
qWarning() << "No content!";
return;
Expand All @@ -257,7 +256,7 @@ void NetworkHttp::doRequest(QNetworkRequest& req,
qDebug() << "content-type:" << type;
if (type.startsWith("text/", Qt::CaseInsensitive) ||
type.startsWith(CONTENT_TYPE_JSON, Qt::CaseInsensitive))
qDebug() << "body:" << (QString::fromUtf8(bytes));
qDebug() << "body:" << QString::fromUtf8(bytes);
}

auto cdh = reply->header(QNetworkRequest::KnownHeaders::ContentDispositionHeader);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/network/NetworkHttp.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class QNetworkReply;

namespace network {

using HttpErrorFn = Fn<void(int statusCode, const QString& errStr)>;
using HttpErrorFn = Fn<void(int statusCode, const QByteArray body)>;
using HttpDownloadProgressFn = Fn<void(qint64 bytesReceived, qint64 bytesTotal)>;
using HttpUploadProgressFn = Fn<void(qint64 bytesSent, qint64 bytesTotal)>;
using HttpBodyFn = Fn<void(QByteArray body, QString filename)>;
Expand Down

0 comments on commit 9537bf6

Please sign in to comment.