-
Notifications
You must be signed in to change notification settings - Fork 13
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
automatically create hedgedoc user accounts so that edits are no longer anonymous #2
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,16 @@ | |
|
||
{% include 'snippets/messages.html' %} | ||
|
||
<script> | ||
fetch("{{CODIMD_URL}}/login", { | ||
method: 'POST', | ||
mode: 'no-cors', | ||
cache: 'no-cache', | ||
credentials: 'include', | ||
headers: { 'Content-Type': 'application/x-www-form-urlencoded'}, | ||
body: "email={{request.user}}%40localhost.localdomain&password=hedgedoc"}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also not a fan of static password: we have access to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah i just wanted to have a quick PoC working, feel free to use |
||
</script> | ||
|
||
<div aria-live="polite" aria-atomic="true" style="position: relative; min-height: 200px;"> | ||
<div style="position: absolute; top: 0; right: 0;"> | ||
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import datetime | ||
import requests | ||
|
||
from django.contrib import auth, messages | ||
from django.contrib.auth.mixins import LoginRequiredMixin | ||
|
@@ -21,7 +22,7 @@ | |
from ctfpad.models import Challenge, ChallengeFile, Member, Team | ||
from ctfpad.forms import CreateUserForm, UpdateMemberForm | ||
from ctfpad.decorators import only_if_unauthenticated_user, only_if_authenticated_user | ||
|
||
from ctftools.settings import CODIMD_URL | ||
|
||
class CtfpadLogin(LoginView): | ||
template_name = "users/login.html" | ||
|
@@ -70,6 +71,17 @@ def form_valid(self, form): | |
messages.error(self.request, "Username already exists, try logging in instead") | ||
return redirect("ctfpad:home") | ||
|
||
# create the hedgedoc user | ||
email = form.cleaned_data["username"] + '@localhost.localdomain' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same remarks as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same reply as above ;) |
||
res = requests.post(f'{CODIMD_URL}/register', | ||
data={'email': email, 'password': 'hedgedoc'}, | ||
allow_redirects = False) | ||
|
||
if res.status_code != requests.codes.found: | ||
form.errors["name"] = "FailedToCreateHedgedocUser" | ||
messages.error(self.request, "Failed to create Hedgedoc user") | ||
return redirect("ctfpad:home") | ||
|
||
# create the django user | ||
user = User.objects.create_user( | ||
username=form.cleaned_data["username"], | ||
|
@@ -137,4 +149,4 @@ def get_context_data(self, **kwargs): | |
context.update( | ||
{"solved_challenges": Challenge.objects.filter(solver = self.object.id).order_by("-solved_time")} | ||
) | ||
return context | ||
return context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use
request.user.email
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because if I register
lanjelot
on ctfpad usinghahanfiwhothisis@gmail.com
and we userequest.user.email
instead ofrequest.user
then hedgedoc will usehahanfiwhothisis
as the username and we'll have no idea that it is actually me (hedgedoc uses everything before @ as the username)