mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 14:52:15 +00:00
Added RedditAccount as a editable section to users, also added Admin side
This commit is contained in:
8
reddit/admin.py
Normal file
8
reddit/admin.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from reddit.models import RedditAccount
|
||||||
|
|
||||||
|
class RedditAccountAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ('username', 'user', 'date_created', 'link_karma', 'comment_karma')
|
||||||
|
search_fields = ['username', 'user']
|
||||||
|
|
||||||
|
admin.site.register(RedditAccount, RedditAccountAdmin)
|
||||||
12
sso/forms.py
12
sso/forms.py
@@ -2,6 +2,7 @@ from django import forms
|
|||||||
|
|
||||||
from eve_api.models.api_player import EVEAccount
|
from eve_api.models.api_player import EVEAccount
|
||||||
from sso.models import ServiceAccount, Service
|
from sso.models import ServiceAccount, Service
|
||||||
|
from reddit.models import RedditAccount
|
||||||
|
|
||||||
class EveAPIForm(forms.Form):
|
class EveAPIForm(forms.Form):
|
||||||
user_id = forms.CharField(label = u'User ID', max_length=10)
|
user_id = forms.CharField(label = u'User ID', max_length=10)
|
||||||
@@ -37,3 +38,14 @@ def UserServiceAccountForm(user):
|
|||||||
password = forms.CharField(label = u'Password',widget = forms.PasswordInput(render_value=False))
|
password = forms.CharField(label = u'Password',widget = forms.PasswordInput(render_value=False))
|
||||||
|
|
||||||
return ServiceAccountForm
|
return ServiceAccountForm
|
||||||
|
|
||||||
|
class RedditAccountForm(forms.Form):
|
||||||
|
username = forms.CharField(label = u'User ID', max_length=64)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
try:
|
||||||
|
eaccount = RedditAccount.objects.get(username=self.cleaned_data['username'])
|
||||||
|
except RedditAccount.DoesNotExist:
|
||||||
|
return self.cleaned_data
|
||||||
|
else:
|
||||||
|
raise forms.ValidationError("This User ID is already registered")
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ urlpatterns = patterns('',
|
|||||||
(r'^profile/del/eveapi/$', views.eveapi_del),
|
(r'^profile/del/eveapi/$', views.eveapi_del),
|
||||||
(r'^profile/del/eveapi/(?P<userid>\d+)/$', views.eveapi_del),
|
(r'^profile/del/eveapi/(?P<userid>\d+)/$', views.eveapi_del),
|
||||||
(r'^profile/add/service', views.service_add),
|
(r'^profile/add/service', views.service_add),
|
||||||
(r'^profile/del/service/$', views.eveapi_del),
|
(r'^profile/del/service/$', views.service_del),
|
||||||
(r'^profile/del/service/(?P<serviceid>\d+)/$', views.service_del),
|
(r'^profile/del/service/(?P<serviceid>\d+)/$', views.service_del),
|
||||||
|
(r'^profile/add/reddit', views.reddit_add),
|
||||||
|
(r'^profile/del/reddit/$', views.reddit_del),
|
||||||
|
(r'^profile/del/reddit/(?P<redditid>\d+)/$', views.reddit_del),
|
||||||
)
|
)
|
||||||
|
|||||||
45
sso/views.py
45
sso/views.py
@@ -9,7 +9,9 @@ from eve_api.api_puller.accounts import import_eve_account
|
|||||||
from eve_api.models.api_player import EVEAccount
|
from eve_api.models.api_player import EVEAccount
|
||||||
|
|
||||||
from sso.models import ServiceAccount, SSOUser
|
from sso.models import ServiceAccount, SSOUser
|
||||||
from sso.forms import EveAPIForm, UserServiceAccountForm
|
from sso.forms import EveAPIForm, UserServiceAccountForm, RedditAccountForm
|
||||||
|
|
||||||
|
from reddit.models import RedditAccount
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
@@ -30,6 +32,11 @@ def profile(request):
|
|||||||
srvaccounts = ServiceAccount.objects.filter(user=request.user).all()
|
srvaccounts = ServiceAccount.objects.filter(user=request.user).all()
|
||||||
except ServiceAccount.DoesNotExist:
|
except ServiceAccount.DoesNotExist:
|
||||||
srvaccounts = None
|
srvaccounts = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
redditaccounts = RedditAccount.objects.filter(user=request.user).all()
|
||||||
|
except ServiceAccount.DoesNotExist:
|
||||||
|
redditaccounts = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
eveaccounts = EVEAccount.objects.filter(user=request.user).all()
|
eveaccounts = EVEAccount.objects.filter(user=request.user).all()
|
||||||
@@ -118,4 +125,40 @@ def service_del(request, serviceid=0):
|
|||||||
return HttpResponseRedirect(reverse('sso.views.profile'))
|
return HttpResponseRedirect(reverse('sso.views.profile'))
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def reddit_add(request):
|
||||||
|
if request.method == 'POST':
|
||||||
|
form = RedditAccountForm(request.POST)
|
||||||
|
if form.is_valid():
|
||||||
|
|
||||||
|
acc = RedditAccount()
|
||||||
|
|
||||||
|
acc.user = request.user
|
||||||
|
acc.username = form.cleaned_data['username']
|
||||||
|
|
||||||
|
acc.save()
|
||||||
|
return HttpResponseRedirect(reverse('sso.views.profile')) # Redirect after POST
|
||||||
|
else:
|
||||||
|
defaults = { 'username': request.user.username, }
|
||||||
|
form = RedditAccountForm(defaults) # An unbound form
|
||||||
|
|
||||||
|
return render_to_response('sso/redditaccount.html', {
|
||||||
|
'form': form,
|
||||||
|
})
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def reddit_del(request, redditid=0):
|
||||||
|
if redditid > 0 :
|
||||||
|
try:
|
||||||
|
acc = RedditAccount.objects.get(id=redditid)
|
||||||
|
except RedditAccount.DoesNotExist:
|
||||||
|
return HttpResponseRedirect(reverse('sso.views.profile'))
|
||||||
|
|
||||||
|
if acc.user == request.user:
|
||||||
|
acc.delete()
|
||||||
|
|
||||||
|
return HttpResponseRedirect(reverse('sso.views.profile'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,29 @@ setup.</p>
|
|||||||
<p>
|
<p>
|
||||||
<a href="/profile/add/eveapi">Add a Eve API key</a>
|
<a href="/profile/add/eveapi">Add a Eve API key</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
<h2>Reddit Accounts</h2>
|
||||||
|
<p>This is a list of all your current linked Reddit accounts</p>
|
||||||
|
{% if redditaccounts %}
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr><th>Username</th><th>Created Date</th></tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for acc in redditaccounts %}
|
||||||
|
<tr><td>{{ acc.username }}</td>
|
||||||
|
<td>{{ acc.date_created }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
<tfoot><tr><td colspan="5"> </td></tr></tfoot>
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
|
<p>
|
||||||
|
<a href="/profile/add/reddit">Add a Reddit account</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>If you encounter any errors during using this service, copy the massive
|
<p>If you encounter any errors during using this service, copy the massive
|
||||||
error message into <a href="http://pastebin.com/">Pastebin</a> and give
|
error message into <a href="http://pastebin.com/">Pastebin</a> and give
|
||||||
Matalok a good kicking on IRC/Jabber/Email or on the Forums.</p>
|
Matalok a good kicking on IRC/Jabber/Email or on the Forums.</p>
|
||||||
|
|||||||
14
templates/sso/redditaccount.html
Normal file
14
templates/sso/redditaccount.html
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Add Reddit Account{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<p>This will bind a Reddit account to your Auth Gateway login, this is usually required for application to the
|
||||||
|
corporation</p>
|
||||||
|
<p>Please note, you will be forever tied to this account and posts and comments made on this account will be checked
|
||||||
|
on from time to time</p>
|
||||||
|
<form action="/profile/add/reddit" method="post">
|
||||||
|
{{ form.as_p }}
|
||||||
|
<input type="submit" value="Submit" />
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user