Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nheko
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
nheko
Commits
78607a7e
Commit
78607a7e
authored
3 years ago
by
Callum Brown
Browse files
Options
Downloads
Patches
Plain Diff
Do a .well-known lookup during registration
parent
b8b0b5c6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#1140
passed
3 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/RegisterPage.cpp
+104
-30
104 additions, 30 deletions
src/RegisterPage.cpp
src/RegisterPage.h
+5
-0
5 additions, 0 deletions
src/RegisterPage.h
with
109 additions
and
30 deletions
src/RegisterPage.cpp
+
104
−
30
View file @
78607a7e
...
...
@@ -11,6 +11,7 @@
#include
<QtMath>
#include
<mtx/responses/register.hpp>
#include
<mtx/responses/well-known.hpp>
#include
"Config.h"
#include
"Logging.h"
...
...
@@ -145,6 +146,17 @@ RegisterPage::RegisterPage(QWidget *parent)
top_layout_
->
addWidget
(
error_label_
,
0
,
Qt
::
AlignHCenter
);
top_layout_
->
addStretch
(
1
);
connect
(
this
,
&
RegisterPage
::
versionErrorCb
,
this
,
[
this
](
const
QString
&
msg
)
{
error_server_label_
->
show
();
server_input_
->
setValid
(
false
);
showError
(
error_server_label_
,
msg
);
},
Qt
::
QueuedConnection
);
connect
(
back_button_
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
onBackButtonClicked
()));
connect
(
register_button_
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
onRegisterButtonClicked
()));
...
...
@@ -414,51 +426,113 @@ RegisterPage::onRegisterButtonClicked()
http
::
client
()
->
set_server
(
server
);
http
::
client
()
->
verify_certificates
(
!
UserSettings
::
instance
()
->
disableCertificateValidation
());
http
::
client
()
->
registration
(
username
,
password
,
[
this
,
username
,
password
](
const
mtx
::
responses
::
Register
&
res
,
http
::
client
()
->
well_known
(
[
this
,
username
,
password
](
const
mtx
::
responses
::
WellKnown
&
res
,
mtx
::
http
::
RequestErr
err
)
{
if
(
!
err
)
{
http
::
client
()
->
set_user
(
res
.
user_id
);
http
::
client
()
->
set_access_token
(
res
.
access_token
);
if
(
err
)
{
using
namespace
boost
::
beast
::
http
;
emit
registerOk
();
return
;
}
if
(
err
->
status_code
==
status
::
not_found
)
{
nhlog
::
net
()
->
info
(
"Autodiscovery: No .well-known."
);
checkVersionAndRegister
(
username
,
password
);
return
;
}
// The server requires registration flows.
if
(
err
->
status_code
==
boost
::
beast
::
http
::
status
::
unauthorized
)
{
if
(
err
->
matrix_error
.
unauthorized
.
flows
.
empty
())
{
nhlog
::
net
()
->
warn
(
"failed to retrieve registration flows1: ({}) "
"{}"
,
static_cast
<
int
>
(
err
->
status_code
),
err
->
matrix_error
.
error
);
emit
errorOccurred
();
emit
registerErrorCb
(
QString
::
fromStdString
(
err
->
matrix_error
.
error
));
if
(
!
err
->
parse_error
.
empty
())
{
emit
versionErrorCb
(
tr
(
"Autodiscovery failed. Received malformed response."
));
nhlog
::
net
()
->
error
(
"Autodiscovery failed. Received malformed response."
);
return
;
}
emit
registrationFlow
(
username
,
password
,
err
->
matrix_error
.
unauthorized
);
emit
versionErrorCb
(
tr
(
"Autodiscovery failed. Unknown error when "
"requesting .well-known."
));
nhlog
::
net
()
->
error
(
"Autodiscovery failed. Unknown error when "
"requesting .well-known. {}"
,
err
->
error_code
.
message
());
return
;
}
nhlog
::
net
()
->
error
(
"failed to register: status_code ({}), matrix_error({})"
,
static_cast
<
int
>
(
err
->
status_code
),
err
->
matrix_error
.
error
);
emit
registerErrorCb
(
QString
::
fromStdString
(
err
->
matrix_error
.
error
));
emit
errorOccurred
();
nhlog
::
net
()
->
info
(
"Autodiscovery: Discovered '"
+
res
.
homeserver
.
base_url
+
"'"
);
http
::
client
()
->
set_server
(
res
.
homeserver
.
base_url
);
checkVersionAndRegister
(
username
,
password
);
});
emit
registering
();
}
}
void
RegisterPage
::
checkVersionAndRegister
(
const
std
::
string
&
username
,
const
std
::
string
&
password
)
{
http
::
client
()
->
versions
(
[
this
,
username
,
password
](
const
mtx
::
responses
::
Versions
&
,
mtx
::
http
::
RequestErr
err
)
{
if
(
err
)
{
using
namespace
boost
::
beast
::
http
;
if
(
err
->
status_code
==
status
::
not_found
)
{
emit
versionErrorCb
(
tr
(
"The required endpoints were not found. "
"Possibly not a Matrix server."
));
return
;
}
if
(
!
err
->
parse_error
.
empty
())
{
emit
versionErrorCb
(
tr
(
"Received malformed response. Make sure "
"the homeserver domain is valid."
));
return
;
}
emit
versionErrorCb
(
tr
(
"An unknown error occured. Make sure the homeserver domain is valid."
));
return
;
}
http
::
client
()
->
registration
(
username
,
password
,
[
this
,
username
,
password
](
const
mtx
::
responses
::
Register
&
res
,
mtx
::
http
::
RequestErr
err
)
{
if
(
!
err
)
{
http
::
client
()
->
set_user
(
res
.
user_id
);
http
::
client
()
->
set_access_token
(
res
.
access_token
);
emit
registerOk
();
return
;
}
// The server requires registration flows.
if
(
err
->
status_code
==
boost
::
beast
::
http
::
status
::
unauthorized
)
{
if
(
err
->
matrix_error
.
unauthorized
.
flows
.
empty
())
{
nhlog
::
net
()
->
warn
(
"failed to retrieve registration flows1: ({}) "
"{}"
,
static_cast
<
int
>
(
err
->
status_code
),
err
->
matrix_error
.
error
);
emit
errorOccurred
();
emit
registerErrorCb
(
QString
::
fromStdString
(
err
->
matrix_error
.
error
));
return
;
}
emit
registrationFlow
(
username
,
password
,
err
->
matrix_error
.
unauthorized
);
return
;
}
nhlog
::
net
()
->
error
(
"failed to register: status_code ({}), matrix_error({})"
,
static_cast
<
int
>
(
err
->
status_code
),
err
->
matrix_error
.
error
);
emit
registerErrorCb
(
QString
::
fromStdString
(
err
->
matrix_error
.
error
));
emit
errorOccurred
();
});
});
}
void
RegisterPage
::
paintEvent
(
QPaintEvent
*
)
{
...
...
This diff is collapsed.
Click to expand it.
src/RegisterPage.h
+
5
−
0
View file @
78607a7e
...
...
@@ -31,6 +31,10 @@ protected:
signals:
void
backButtonClicked
();
void
errorOccurred
();
//! Used to trigger the corresponding slot outside of the main thread.
void
versionErrorCb
(
const
QString
&
err
);
void
registering
();
void
registerOk
();
void
registerErrorCb
(
const
QString
&
msg
);
...
...
@@ -52,6 +56,7 @@ private:
bool
checkOneField
(
QLabel
*
label
,
const
TextField
*
t_field
,
const
QString
&
msg
);
bool
checkFields
();
void
showError
(
QLabel
*
label
,
const
QString
&
msg
);
void
checkVersionAndRegister
(
const
std
::
string
&
username
,
const
std
::
string
&
password
);
QVBoxLayout
*
top_layout_
;
QHBoxLayout
*
back_layout_
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment