Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
conduwuit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
🥺
conduwuit
Commits
890187e0
Unverified
Commit
890187e0
authored
4 years ago
by
Devon Hudson
Browse files
Options
Downloads
Patches
Plain Diff
improvement: Handle optional device_id field during login
remove debug logging
parent
9424ba05
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/client_server/session.rs
+26
-9
26 additions, 9 deletions
src/client_server/session.rs
src/database/users.rs
+1
-1
1 addition, 1 deletion
src/database/users.rs
with
27 additions
and
10 deletions
src/client_server/session.rs
+
26
−
9
View file @
890187e0
...
...
@@ -77,7 +77,6 @@ pub async fn login_route(
// Generate new device id if the user didn't specify one
let
device_id
=
body
.body
.device_id
.clone
()
.unwrap_or_else
(||
utils
::
random_string
(
DEVICE_ID_LENGTH
)
.into
());
...
...
@@ -85,14 +84,32 @@ pub async fn login_route(
// Generate a new token for the device
let
token
=
utils
::
random_string
(
TOKEN_LENGTH
);
// TODO: Don't always create a new device
// Add device
db
.users
.create_device
(
&
user_id
,
&
device_id
,
&
token
,
body
.initial_device_display_name
.clone
(),
)
?
;
let
mut
create_new_device
=
true
;
// Only search db for existing device if one was provided in the request
match
&
body
.device_id
{
Some
(
_
)
=>
{
// Look to see if provided device_id already exists
if
let
Some
(
_
)
=
db
.users
.all_device_ids
(
&
user_id
)
.find
(|
x
|
match
x
{
Ok
(
x
)
if
**
x
==
*
device_id
=>
true
,
_
=>
false
,
})
{
// Replace token for existing device
db
.users
.set_token
(
&
user_id
,
&
device_id
,
&
token
)
?
;
create_new_device
=
false
;
}
}
_
=>
(),
};
if
create_new_device
{
db
.users
.create_device
(
&
user_id
,
&
device_id
,
&
token
,
body
.initial_device_display_name
.clone
(),
)
?
;
}
info!
(
"{} logged in"
,
user_id
);
...
...
This diff is collapsed.
Click to expand it.
src/database/users.rs
+
1
−
1
View file @
890187e0
...
...
@@ -251,7 +251,7 @@ pub fn all_device_ids(&self, user_id: &UserId) -> impl Iterator<Item = Result<Bo
}
/// Replaces the access token of one device.
fn
set_token
(
&
self
,
user_id
:
&
UserId
,
device_id
:
&
DeviceId
,
token
:
&
str
)
->
Result
<
()
>
{
pub
fn
set_token
(
&
self
,
user_id
:
&
UserId
,
device_id
:
&
DeviceId
,
token
:
&
str
)
->
Result
<
()
>
{
let
mut
userdeviceid
=
user_id
.to_string
()
.as_bytes
()
.to_vec
();
userdeviceid
.push
(
0xff
);
userdeviceid
.extend_from_slice
(
device_id
.as_bytes
());
...
...
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