"Fossies" - the Fresh Open Source Software Archive 
Member "seafile-client-7.0.4/src/auto-login-service.cpp" (19 Nov 2019, 2318 Bytes) of package /linux/www/seafile-client-7.0.4.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "auto-login-service.cpp" see the
Fossies "Dox" file reference documentation.
1 #include <QDesktopServices>
2 #include <QHash>
3
4 #include "seafile-applet.h"
5 #include "account-mgr.h"
6 #include "api/api-error.h"
7 #include "api/requests.h"
8 #include "utils/utils.h"
9
10 #include "auto-login-service.h"
11
12 namespace {
13
14 } // namespace
15
16 SINGLETON_IMPL(AutoLoginService)
17
18 AutoLoginService::AutoLoginService(QObject *parent)
19 : QObject(parent)
20 {
21 }
22
23 void AutoLoginService::startAutoLogin(const QString& next_url)
24 {
25 const Account account = seafApplet->accountManager()->currentAccount();
26 QUrl absolute_url = QUrl(next_url).isRelative()
27 ? account.getAbsoluteUrl(next_url)
28 : next_url;
29 if (!account.isValid() || !account.isAtLeastVersion(4, 2, 0)) {
30 QDesktopServices::openUrl(absolute_url);
31 return;
32 }
33
34 QString next = absolute_url.path();
35 if (absolute_url.hasQuery()) {
36 next += "?" + absolute_url.query();
37 }
38 if (!absolute_url.fragment().isEmpty()) {
39 next += "#" + absolute_url.fragment();
40 }
41 GetLoginTokenRequest *req = new GetLoginTokenRequest(account, next);
42
43 connect(req, SIGNAL(success(const QString&)),
44 this, SLOT(onGetLoginTokenSuccess(const QString&)));
45
46 connect(req, SIGNAL(failed(const ApiError&)),
47 this, SLOT(onGetLoginTokenFailed(const ApiError&)));
48
49 req->send();
50 }
51
52 void AutoLoginService::onGetLoginTokenSuccess(const QString& token)
53 {
54 GetLoginTokenRequest *req = (GetLoginTokenRequest *)(sender());
55 // printf("login token is %s\n", token.toUtf8().data());
56
57 QUrl url = req->account().getAbsoluteUrl("/client-login/");
58 QString next_url = req->nextUrl();
59
60 QHash<QString, QString> params;
61 params.insert("token", token);
62 params.insert("next", req->nextUrl());
63 url = includeQueryParams(url, params);
64
65 QDesktopServices::openUrl(url);
66 req->deleteLater();
67 }
68
69 void AutoLoginService::onGetLoginTokenFailed(const ApiError& error)
70 {
71 GetLoginTokenRequest *req = (GetLoginTokenRequest *)(sender());
72 qWarning("get login token failed: %s\n", error.toString().toUtf8().data());
73 // server doesn't support client directly login, or other errors happened.
74 // We open the server url directly in this case;
75 QDesktopServices::openUrl(req->account().getAbsoluteUrl(req->nextUrl()));
76 req->deleteLater();
77 }