Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix register fails on channles requests. #137 #519

Merged
merged 12 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,4 @@ Contributed by [ניר](https://github.com/nrbnlulu) via [PR #355](https://githu

This release just updates dependencies.

Contributed by [ניר](https://github.com/nrbnlulu) via [PR #354](https://github.com/nrbnlulu/strawberry-django-auth/pull/354/)
Contributed by [ניר](https://github.com/nrbnlulu) via [PR #354](https://github.com/nrbnlulu/strawberry-django-auth/pull/354/)
5 changes: 5 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Release type: patch

Fix register fails on channles requests. #137
Do noyt call get_current_site() from get_email_context()
Extract values from channels context.
43 changes: 29 additions & 14 deletions gqlauth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,35 @@

def get_email_context(self, info: Info, path, action, **kwargs):
token = get_token(self.user, action, **kwargs)
request = info.context.request
site = get_current_site(request)
return {
"user": self.user,
"request": request,
"token": token,
"port": request.get_port(),
"site_name": site.name,
"domain": site.domain,
"protocol": "https" if request.is_secure() else "http",
"path": path,
"timestamp": time.time(),
**app_settings.EMAIL_TEMPLATE_VARIABLES,
}
if isinstance(info.context, dict):
request = info.context["request"]
return {

Check warning on line 63 in gqlauth/models.py

View check run for this annotation

Codecov / codecov/patch

gqlauth/models.py#L62-L63

Added lines #L62 - L63 were not covered by tests
"user": self.user,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to do something like

is_channels = isinstance(info.context, dict)

if is_channels:
	domain, port =  request.headers["host"].split(":")
else:
	domain = site.domain
	# yada yada
return {
	"domain" domain,
	# yada yada

"request": request,
"token": token,
"port": request.headers["host"].split(":")[1],
"site_name": request.headers["host"].split(":")[0],
"domain": request.headers["host"].split(":")[0],
"protocol": request.consumer.scope["type"],
"path": path,
"timestamp": time.time(),
**app_settings.EMAIL_TEMPLATE_VARIABLES,
}
else:
request = info.context.request
site = get_current_site(request)
return {
"user": self.user,
"request": request,
"token": token,
"port": request.get_port(),
"site_name": site.name,
"domain": site.domain,
"protocol": "https" if request.is_secure() else "http",
"path": path,
"timestamp": time.time(),
**app_settings.EMAIL_TEMPLATE_VARIABLES,
}

def send_activation_email(self, info, *args, **kwargs):
email_context = self.get_email_context(
Expand Down
Loading