mirror of
https://gitlab.com/comunic/comunicwatcher
synced 2024-11-24 14:29:27 +00:00
Get user ID
This commit is contained in:
parent
cbbf4b43c8
commit
ea961a6d41
@ -55,3 +55,16 @@ void AccountHelper::RemoveLoginToken()
|
||||
{
|
||||
QSettings().remove(LOGIN_TOKEN_VALUE);
|
||||
}
|
||||
|
||||
void AccountHelper::GetUserID(const vGetUserIDCallback cb)
|
||||
{
|
||||
auto req = new APIRequest("account/id");
|
||||
req->exec();
|
||||
QObject::connect(req, &APIRequest::done, [=] (APIResponse res) {
|
||||
if(res.isError())
|
||||
cb(-1);
|
||||
else
|
||||
cb(res.getObject().value("userID").toInt(-1));
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ enum LoginResult {
|
||||
|
||||
typedef std::function<void (LoginResult)> vLoginCallback;
|
||||
|
||||
typedef std::function<void (int)> vGetUserIDCallback;
|
||||
|
||||
class AccountHelper
|
||||
{
|
||||
public:
|
||||
@ -44,5 +46,10 @@ public:
|
||||
* Destroy the login token of a user
|
||||
*/
|
||||
static void RemoveLoginToken();
|
||||
|
||||
/**
|
||||
* Get current user ID
|
||||
*/
|
||||
static void GetUserID(const vGetUserIDCallback cb);
|
||||
};
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "accounthelper.h"
|
||||
#include "whoamidialog.h"
|
||||
#include "ui_whoamidialog.h"
|
||||
|
||||
@ -6,9 +9,23 @@ WhoAmIDialog::WhoAmIDialog(QWidget *parent) :
|
||||
ui(new Ui::WhoAmIDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
AccountHelper::GetUserID([this](int id) {
|
||||
this->onGotUserId(id);
|
||||
});
|
||||
}
|
||||
|
||||
WhoAmIDialog::~WhoAmIDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void WhoAmIDialog::onGotUserId(int userID)
|
||||
{
|
||||
if(userID < 1) {
|
||||
QMessageBox::warning(this, tr("Error"), tr("Could not get your id!"));
|
||||
return;
|
||||
}
|
||||
|
||||
this->ui->user_id->setText(QString::number(userID));
|
||||
}
|
||||
|
@ -15,6 +15,9 @@ public:
|
||||
~WhoAmIDialog();
|
||||
|
||||
private:
|
||||
void onGotUserId(int userID);
|
||||
|
||||
// Class members
|
||||
Ui::WhoAmIDialog *ui;
|
||||
};
|
||||
|
||||
|
@ -17,6 +17,46 @@
|
||||
<iconset resource="ressources.qrc">
|
||||
<normaloff>:/logo_large.png</normaloff>:/logo_large.png</iconset>
|
||||
</property>
|
||||
<widget class="QWidget" name="gridLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>180</x>
|
||||
<y>80</y>
|
||||
<width>160</width>
|
||||
<height>80</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>User ID</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="user_id">
|
||||
<property name="text">
|
||||
<string>Loading</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>User name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="user_name">
|
||||
<property name="text">
|
||||
<string>Loading</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="ressources.qrc"/>
|
||||
|
Loading…
Reference in New Issue
Block a user