Skip to content

Commit 8b59147

Browse files
authored
Merge pull request #114 from dtinit/user_oauth
User oauth
2 parents f08a631 + d023b09 commit 8b59147

File tree

11 files changed

+183
-11
lines changed

11 files changed

+183
-11
lines changed

.env-example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ PROJECT_NAME=ActivityPubTestbed
22
DJANGO_SECRET_KEY=SECRETKEY
33
DJANGO_DEBUG=True
44
DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1
5-
DJ_DATABASE_CONN_STRING=postgres://username:password@localhost:5432/database
5+
DJ_DATABASE_CONN_STRING=postgres://username:password@localhost:5432/database

static/scss/_base.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,3 @@ html {
3737
background: #fff;
3838
border-top: 1px solid #ccc;
3939
}
40-

static/scss/index.scss

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,54 @@
99
padding: 10px;
1010
background: #f5f5f5;
1111
}
12+
13+
.messages {
14+
list-style: none;
15+
padding: 0;
16+
}
17+
.messages p {
18+
margin-bottom: 1em;
19+
padding: 0.7em;
20+
border-radius: 4px;
21+
}
22+
.messages p.success {
23+
background: #e3fdd7;
24+
color: #102010;
25+
}
26+
.messages p.error {
27+
background: #f2dede;
28+
color: #a94442;
29+
}
30+
31+
.oauth-form {
32+
margin-top: 1em;
33+
}
34+
.oauth-form .form-group {
35+
margin-bottom: 1em;
36+
}
37+
.oauth-form label {
38+
font-weight: bold;
39+
margin-bottom: 0.2em;
40+
display: block;
41+
}
42+
.oauth-form .form-control {
43+
width: 100%;
44+
padding: 0.4em;
45+
border: 1px solid #bbb;
46+
border-radius: 4px;
47+
box-sizing: border-box;
48+
font-size: 1em;
49+
}
50+
.oauth-form .btn {
51+
background: #1976d2;
52+
color: #fff;
53+
border: none;
54+
padding: 0.5em 1.5em;
55+
border-radius: 3px;
56+
cursor: pointer;
57+
font-size: 1em;
58+
}
59+
.oauth-form .btn:hover {
60+
background: #1565c0;
61+
}
1262
}

static/scss/reset.scss

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
Modified to remove invalid property name
66
*/
77

8-
*, *::before, *::after {
8+
*,
9+
*::before,
10+
*::after {
911
box-sizing: border-box;
1012
}
1113

@@ -17,27 +19,45 @@ body {
1719
line-height: 1.5;
1820
}
1921

20-
img, picture, video, canvas, svg {
22+
img,
23+
picture,
24+
video,
25+
canvas,
26+
svg {
2127
display: block;
2228
max-width: 100%;
2329
}
2430

25-
input, button, textarea, select {
31+
input,
32+
button,
33+
textarea,
34+
select {
2635
font: inherit;
2736
}
2837

29-
p, h1, h2, h3, h4, h5, h6 {
38+
p,
39+
h1,
40+
h2,
41+
h3,
42+
h4,
43+
h5,
44+
h6 {
3045
overflow-wrap: break-word;
3146
}
3247

3348
p {
3449
text-wrap: pretty;
3550
}
36-
h1, h2, h3, h4, h5, h6 {
51+
h1,
52+
h2,
53+
h3,
54+
h4,
55+
h5,
56+
h6 {
3757
text-wrap: balance;
3858
}
3959

40-
#root, #__next {
60+
#root,
61+
#__next {
4162
isolation: isolate;
4263
}
43-

static/scss/site.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
@import "reset";
22
@import "_base";
33
@import "index";
4-
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django import forms
2+
from testbed.core.models import OauthConnection
3+
4+
class OauthConnectionForm(forms.ModelForm):
5+
class Meta:
6+
model = OauthConnection
7+
fields = ['client_id', 'client_secret', 'redirect_url']
8+
widgets = {
9+
'client_id': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Client ID'}),
10+
'client_secret': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Client Secret'}),
11+
'redirect_url': forms.URLInput(attrs={'class': 'form-control', 'placeholder': 'Redirect URL'}),
12+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Generated by Django 5.1.3 on 2025-06-13 03:00
2+
3+
import django.db.models.deletion
4+
from django.conf import settings
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('core', '0001_initial'),
12+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name='OauthConnection',
18+
fields=[
19+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20+
('client_id', models.CharField(max_length=100)),
21+
('client_secret', models.CharField(max_length=255)),
22+
('redirect_url', models.URLField()),
23+
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
24+
],
25+
),
26+
]

testbed/core/models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,13 @@ def add_activity(self, activity):
239239
self.activities_like.add(activity)
240240
elif isinstance(activity, FollowActivity):
241241
self.activities_follow.add(activity)
242+
243+
class OauthConnection(models.Model):
244+
user = models.OneToOneField(User, on_delete=models.CASCADE)
245+
client_id = models.CharField(max_length=100)
246+
client_secret = models.CharField(max_length=255)
247+
redirect_url = models.URLField()
248+
249+
def __str__(self):
250+
return f"OAuth for {self.user.username}"
251+

testbed/core/templates/index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
{% block content %}
44
<main class="index">
5+
{% if messages %}
6+
<ul class="messages">
7+
{% for message in messages %}
8+
<p class="{{ message.tags }}">{{ message }}</p>
9+
{% endfor %}
10+
</ul>
11+
{% endif %}
512
<h1>ActivityPub Account Portability Testbed</h1>
613
<br />
714
{% if user.is_authenticated %}
@@ -45,5 +52,19 @@ <h3>Destination</h3>
4552
Accounts on this site are not full ActivityPub accounts in that they are not shared to the Fediverse or truly federated with other ActivityPubservers.
4653
</p>
4754
{% endif %}
55+
</div>
56+
57+
<h3>Update Your OAuth Connection</h3>
58+
59+
{% if oauth_form %}
60+
<div class="actor">
61+
<form method="post" class="oauth-form">
62+
{% csrf_token %}
63+
{{ oauth_form.as_p }}
64+
<br/>
65+
<button type="submit">Update</button>
66+
</form>
67+
</div>
68+
{% endif %}
4869
</main>
4970
{% endblock %}

testbed/core/utils/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import string
2+
import secrets
3+
4+
def random_client_id(length=10):
5+
return ''.join(secrets.choice(string.ascii_letters + string.digits) for _ in range(length))
6+
7+
def random_client_secret(length=40):
8+
return ''.join(secrets.choice(string.ascii_letters + string.digits) for _ in range(length))

0 commit comments

Comments
 (0)