Skip to content

Commit

Permalink
fix: server login box
Browse files Browse the repository at this point in the history
Signed-off-by: dragonflylee <[email protected]>
  • Loading branch information
dragonflylee committed Sep 7, 2023
1 parent c136c62 commit 411e9ad
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 47 deletions.
2 changes: 1 addition & 1 deletion app/include/utils/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ class AppConfig : public brls::Singleton<AppConfig> {

bool addServer(const AppServer& s);
bool addUser(const AppUser& u);
std::string getDevice(const std::string& token = "");
const AppUser& getUser() const { return this->user; }
const std::string& getUrl() const { return this->server_url; }
const std::string& getDevice() const { return this->device; }
const std::vector<AppServer> getServers() const;

NLOHMANN_DEFINE_TYPE_INTRUSIVE(AppConfig, user_id, server_url, device, users, servers, setting);
Expand Down
18 changes: 9 additions & 9 deletions app/src/tab/server_login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ ServerLogin::ServerLogin(const AppServer& s, const std::string& user) : url(s.ur
ServerLogin::~ServerLogin() { brls::Logger::debug("ServerLogin Activity: delete"); }

bool ServerLogin::onSignin() {
std::string username = inputUser->getValue();
std::string password = inputPass->getValue();
if (username.empty()) {
Dialog::show("Username is empty");
return false;
}

brls::Application::blockInputs();
btnSignin->setTextColor(brls::Application::getTheme().getColor("font/grey"));
nlohmann::json data = {{"Username", inputUser->getValue()}, {"Pw", inputPass->getValue()}};
nlohmann::json data = {{"Username", username}, {"Pw", password}};

ASYNC_RETAIN
brls::async([ASYNC_TOKEN, data]() {
HTTP::Header header = {
"Content-Type: application/json",
fmt::format(
"X-Emby-Authorization: MediaBrowser Client=\"{}\", Device=\"{}\", DeviceId=\"{}\", Version=\"{}\"",
AppVersion::pkg_name, AppVersion::getDeviceName(), AppConfig::instance().getDevice(),
AppVersion::getVersion()),
};

HTTP::Header header = {"Content-Type: application/json", AppConfig::instance().getDevice()};
brls::Logger::info("login header {}", header[1]);

try {
Expand Down
18 changes: 13 additions & 5 deletions app/src/utils/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,7 @@ void AppConfig::save() {
bool AppConfig::checkLogin() {
for (auto& u : this->users) {
if (u.id == this->user_id) {
HTTP::Header header = {
fmt::format("X-Emby-Authorization: MediaBrowser Client=\"{}\", Device=\"{}\", DeviceId=\"{}\", "
"Version=\"{}\", Token=\"{}\"",
AppVersion::pkg_name, AppVersion::getDeviceName(), this->getDevice(), AppVersion::getVersion(),
u.access_token)};
HTTP::Header header = {this->getDevice(u.access_token)};
const long timeout = this->getItem(AppConfig::REQUEST_TIMEOUT, default_timeout);
try {
HTTP::get(this->server_url + jellyfin::apiInfo, header, HTTP::Timeout{timeout});
Expand Down Expand Up @@ -271,6 +267,18 @@ bool AppConfig::addUser(const AppUser& u) {
return found;
}

std::string AppConfig::getDevice(const std::string& token) {
if (token.empty())
return fmt::format(
"X-Emby-Authorization: MediaBrowser Client=\"{}\", Device=\"{}\", DeviceId=\"{}\", Version=\"{}\"",
AppVersion::pkg_name, AppVersion::getDeviceName(), this->device, AppVersion::getVersion());
else
return fmt::format(
"X-Emby-Authorization: MediaBrowser Client=\"{}\", Device=\"{}\", DeviceId=\"{}\", Version=\"{}\", "
"Token=\"{}\"",
AppVersion::pkg_name, AppVersion::getDeviceName(), this->device, AppVersion::getVersion(), token);
}

const std::vector<AppServer> AppConfig::getServers() const {
std::vector<AppServer> list(this->servers);
for (auto& u : this->users) {
Expand Down
30 changes: 11 additions & 19 deletions resources/xml/tabs/server_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,26 @@

<brls:Box
width="50%"
height="auto"
axis="column"
alignItems="stretch">

<brls:Header
width="auto"
height="auto"
id="server/sigin_to" />
<brls:Box
width="100%"
height="auto"
axis="column">

<brls:InputCell
id="server/user" />

<brls:InputCell
id="server/pass" />
<brls:InputCell
id="server/user" />

<brls:Button
marginTop="15"
text="@i18n/main/setting/server/signin"
style="primary"
fontSize="@style/brls/sidebar/item_font_size"
padding="12.5"
id="server/signin" />
<brls:InputCell
id="server/pass" />

</brls:Box>
<brls:Button
text="@i18n/main/setting/server/signin"
marginTop="15"
style="primary"
fontSize="@style/brls/sidebar/item_font_size"
padding="12.5"
id="server/signin" />

</brls:Box>
</brls:Box>
4 changes: 0 additions & 4 deletions resources/xml/view/setting_about.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<brls:Box
grow="1.0"
width="auto"
height="auto"
axis="column"
wireframe="false"
paddingLeft="60"
paddingRight="60"
paddingTop="@style/brls/tab_frame/content_padding_top_bottom"
Expand Down
16 changes: 7 additions & 9 deletions resources/xml/view/tutorial_font.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<brls:Box
margin="40"
margin="20"
axis="column">
<brls:Header
title="@i18n/main/setting/tutorial/font_q1"
marginBottom="20" />
margin="10"
title="@i18n/main/setting/tutorial/font_q1" />
<brls:Label
marginLeft="20"
marginBottom="20"
margin="10"
text="@i18n/main/setting/tutorial/font_a1" />
<brls:Header
title="@i18n/main/setting/tutorial/font_q2"
marginBottom="20" />
margin="10"
title="@i18n/main/setting/tutorial/font_q2" />
<brls:Label
marginLeft="20"
marginBottom="20"
margin="10"
text="@i18n/main/setting/tutorial/font_a2" />
</brls:Box>

0 comments on commit 411e9ad

Please sign in to comment.