Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
lemmy
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
Container Registry
Model registry
Operate
Environments
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
lemmy
Commits
aaaf1748
Unverified
Commit
aaaf1748
authored
1 year ago
by
Nutomic
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Dont create auth cookie in backend (#4136)
parent
7a30a759
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
crates/api/src/local_user/login.rs
+4
-10
4 additions, 10 deletions
crates/api/src/local_user/login.rs
crates/api_common/src/utils.rs
+0
-10
0 additions, 10 deletions
crates/api_common/src/utils.rs
crates/api_crud/src/user/create.rs
+3
-6
3 additions, 6 deletions
crates/api_crud/src/user/create.rs
with
7 additions
and
26 deletions
crates/api/src/local_user/login.rs
+
4
−
10
View file @
aaaf1748
use
crate
::
check_totp_2fa_valid
;
use
actix_web
::{
http
::
StatusCode
,
web
::{
Data
,
Json
},
HttpRequest
,
HttpResponse
,
};
use
bcrypt
::
verify
;
use
lemmy_api_common
::{
claims
::
Claims
,
context
::
LemmyContext
,
person
::{
Login
,
LoginResponse
},
utils
::
{
check_user_valid
,
create_login_cookie
},
utils
::
check_user_valid
,
};
use
lemmy_db_schema
::{
source
::{
local_site
::
LocalSite
,
registration_application
::
RegistrationApplication
},
...
...
@@ -25,7 +23,7 @@ pub async fn login(
data
:
Json
<
Login
>
,
req
:
HttpRequest
,
context
:
Data
<
LemmyContext
>
,
)
->
Result
<
Http
Response
,
LemmyError
>
{
)
->
Result
<
Json
<
Login
Response
>
,
LemmyError
>
{
let
site_view
=
SiteView
::
read_local
(
&
mut
context
.pool
())
.await
?
;
// Fetch that username / email
...
...
@@ -65,15 +63,11 @@ pub async fn login(
let
jwt
=
Claims
::
generate
(
local_user_view
.local_user.id
,
req
,
&
context
)
.await
?
;
let
json
=
LoginResponse
{
Ok
(
Json
(
LoginResponse
{
jwt
:
Some
(
jwt
.clone
()),
verify_email_sent
:
false
,
registration_created
:
false
,
};
let
mut
res
=
HttpResponse
::
build
(
StatusCode
::
OK
)
.json
(
json
);
res
.add_cookie
(
&
create_login_cookie
(
jwt
))
?
;
Ok
(
res
)
}))
}
async
fn
check_registration_application
(
...
...
This diff is collapsed.
Click to expand it.
crates/api_common/src/utils.rs
+
0
−
10
View file @
aaaf1748
use
crate
::{
context
::
LemmyContext
,
request
::
purge_image_from_pictrs
,
sensitive
::
Sensitive
,
site
::{
FederatedInstances
,
InstanceWithFederationState
},
};
use
actix_web
::
cookie
::{
Cookie
,
SameSite
};
use
anyhow
::
Context
;
use
chrono
::{
DateTime
,
Days
,
Local
,
TimeZone
,
Utc
};
use
enum_map
::{
enum_map
,
EnumMap
};
...
...
@@ -776,14 +774,6 @@ pub fn generate_moderators_url(community_id: &DbUrl) -> Result<DbUrl, LemmyError
Ok
(
Url
::
parse
(
&
format!
(
"{community_id}/moderators"
))
?
.into
())
}
pub
fn
create_login_cookie
(
jwt
:
Sensitive
<
String
>
)
->
Cookie
<
'static
>
{
let
mut
cookie
=
Cookie
::
new
(
AUTH_COOKIE_NAME
,
jwt
.into_inner
());
cookie
.set_secure
(
true
);
cookie
.set_same_site
(
SameSite
::
Lax
);
cookie
.set_http_only
(
true
);
cookie
}
/// Ensure that ban/block expiry is in valid range. If its in past, throw error. If its more
/// than 10 years in future, convert to permanent ban. Otherwise return the same value.
pub
fn
check_expire_time
(
expires_unix_opt
:
Option
<
i64
>
)
->
LemmyResult
<
Option
<
DateTime
<
Utc
>>>
{
...
...
This diff is collapsed.
Click to expand it.
crates/api_crud/src/user/create.rs
+
3
−
6
View file @
aaaf1748
use
activitypub_federation
::{
config
::
Data
,
http_signatures
::
generate_actor_keypair
};
use
actix_web
::{
http
::
StatusCode
,
web
::
Json
,
HttpRequest
,
HttpResponse
,
HttpResponseBuilder
};
use
actix_web
::{
web
::
Json
,
HttpRequest
};
use
lemmy_api_common
::{
claims
::
Claims
,
context
::
LemmyContext
,
person
::{
LoginResponse
,
Register
},
utils
::{
create_login_cookie
,
generate_inbox_url
,
generate_local_apub_endpoint
,
generate_shared_inbox_url
,
...
...
@@ -42,7 +41,7 @@ pub async fn register(
data
:
Json
<
Register
>
,
req
:
HttpRequest
,
context
:
Data
<
LemmyContext
>
,
)
->
Result
<
Http
Response
,
LemmyError
>
{
)
->
Result
<
Json
<
Login
Response
>
,
LemmyError
>
{
let
site_view
=
SiteView
::
read_local
(
&
mut
context
.pool
())
.await
?
;
let
local_site
=
site_view
.local_site
;
let
require_registration_application
=
...
...
@@ -158,7 +157,6 @@ pub async fn register(
.await
?
;
}
let
mut
res
=
HttpResponseBuilder
::
new
(
StatusCode
::
OK
);
let
mut
login_response
=
LoginResponse
{
jwt
:
None
,
registration_created
:
false
,
...
...
@@ -170,7 +168,6 @@ pub async fn register(
||
(
!
require_registration_application
&&
!
local_site
.require_email_verification
)
{
let
jwt
=
Claims
::
generate
(
inserted_local_user
.id
,
req
,
&
context
)
.await
?
;
res
.cookie
(
create_login_cookie
(
jwt
.clone
()));
login_response
.jwt
=
Some
(
jwt
);
}
else
{
if
local_site
.require_email_verification
{
...
...
@@ -201,5 +198,5 @@ pub async fn register(
}
}
Ok
(
res
.j
son
(
login_response
))
Ok
(
J
son
(
login_response
))
}
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