Skip to content

Commit

Permalink
fix: login failed
Browse files Browse the repository at this point in the history
  • Loading branch information
Serein207 authored Aug 1, 2024
1 parent ef04ce0 commit 67dcd22
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions src/ViewModel/UserProfileViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ using namespace NeteaseCloudMusic;
UserProfileViewModel::UserProfileViewModel(QObject* parent) : QObject(parent) {
isLogin = !(SettingsUtils::getInstance()->value("Cookies").isNull() &&
SettingsUtils::getInstance()->value("Cookies").toByteArray().isEmpty());
connect(this, &UserProfileViewModel::isLoginChanged, this, [this]() {
if (!isLogin) {
setUserProfileModel(UserProfile());
emit loadUserProfileSuccess();
}
});
}

UserProfileViewModel* UserProfileViewModel::create(QQmlEngine*, QJSEngine*) {
return new UserProfileViewModel();
}

void UserProfileViewModel::loadUserProfile() {
if (!getIsLogin()) { // when logout
setUserProfileModel(UserProfile());
emit loadUserProfileSuccess();
return;
}
CloudMusicClient::getInstance()->getLoginStatus([=](Result<LoginStatusEntity> result) {
if (result.isErr()) {
emit loadUserProfileFailed(result.unwrapErr().message);
Expand All @@ -29,6 +30,7 @@ void UserProfileViewModel::loadUserProfile() {
auto entity = result.unwrap();
if (!entity.account.has_value() || entity.account.value().anonimousUser) {
setIsLogin(false);
return;
} else {
setIsLogin(true);
}
Expand Down Expand Up @@ -57,7 +59,43 @@ QString UserProfileViewModel::getNickname() const {
}

QString UserProfileViewModel::getAvatarUrl() const {
return userProfileModel.avatarUrl;
return userProfileModel.avatarUrl;#include "UserProfileViewModel.h"
#include "Model/UserProfile.h"
#include "Service/NeteaseCloudMusic/Response/LoginStatusEntity.h"
#include <Service/NeteaseCloudMusic/CloudMusicClient.h>
#include <Utility/SettingsUtils.h>

using namespace NeteaseCloudMusic;

UserProfileViewModel::UserProfileViewModel(QObject* parent) : QObject(parent) {
isLogin = !(SettingsUtils::getInstance()->value("Cookies").isNull() &&
SettingsUtils::getInstance()->value("Cookies").toByteArray().isEmpty());
}

UserProfileViewModel* UserProfileViewModel::create(QQmlEngine*, QJSEngine*) {
return new UserProfileViewModel();
}

void UserProfileViewModel::loadUserProfile() {
if (!getIsLogin()) { // when logout
setUserProfileModel(UserProfile());
emit loadUserProfileSuccess();
return;
}
CloudMusicClient::getInstance()->getLoginStatus([=](Result<LoginStatusEntity> result) {
if (result.isErr()) {
emit loadUserProfileFailed(result.unwrapErr().message);
return;
}
auto entity = result.unwrap();
if (!entity.account.has_value() || entity.account.value().anonimousUser) {
setIsLogin(false);
} else {
setIsLogin(true);
}
setUserProfileModel(UserProfile(entity));
emit loadUserProfileSuccess();

}

bool UserProfileViewModel::getDefaultAvatar() const {
Expand Down

0 comments on commit 67dcd22

Please sign in to comment.