mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Added User Lookup feature
This commit is contained in:
11
sso/forms.py
11
sso/forms.py
@@ -1,4 +1,5 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
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
|
||||||
@@ -52,3 +53,13 @@ class RedditAccountForm(forms.Form):
|
|||||||
return self.cleaned_data
|
return self.cleaned_data
|
||||||
else:
|
else:
|
||||||
raise forms.ValidationError("This User ID is already registered")
|
raise forms.ValidationError("This User ID is already registered")
|
||||||
|
|
||||||
|
class UserLookupForm(forms.Form):
|
||||||
|
username = forms.CharField(label = u'User ID', max_length=64)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
try:
|
||||||
|
acc = User.objects.get(username=self.cleaned_data['username'])
|
||||||
|
except User.DoesNotExist:
|
||||||
|
raise forms.ValidationError("User doesn't exist")
|
||||||
|
return self.cleaned_data
|
||||||
|
|||||||
@@ -15,4 +15,5 @@ urlpatterns = patterns('',
|
|||||||
(r'^profile/del/reddit/$', views.reddit_del),
|
(r'^profile/del/reddit/$', views.reddit_del),
|
||||||
(r'^profile/del/reddit/(?P<redditid>\d+)/$', views.reddit_del),
|
(r'^profile/del/reddit/(?P<redditid>\d+)/$', views.reddit_del),
|
||||||
(r'^users/(?P<user>.*)/$', views.user_view),
|
(r'^users/(?P<user>.*)/$', views.user_view),
|
||||||
|
(r'^users/$', views.user_view),
|
||||||
)
|
)
|
||||||
|
|||||||
55
sso/views.py
55
sso/views.py
@@ -9,7 +9,7 @@ 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, ExistingUser
|
from sso.models import ServiceAccount, SSOUser, ExistingUser
|
||||||
from sso.forms import EveAPIForm, UserServiceAccountForm, RedditAccountForm
|
from sso.forms import EveAPIForm, UserServiceAccountForm, RedditAccountForm, UserLookupForm
|
||||||
|
|
||||||
from reddit.models import RedditAccount
|
from reddit.models import RedditAccount
|
||||||
|
|
||||||
@@ -166,7 +166,23 @@ def reddit_del(request, redditid=0):
|
|||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def user_view(request, user):
|
def user_view(request, user=None):
|
||||||
|
form = UserLookupForm()
|
||||||
|
|
||||||
|
if user:
|
||||||
|
user = user
|
||||||
|
elif request.method == 'POST':
|
||||||
|
form = UserLookupForm(request.POST)
|
||||||
|
if form.is_valid():
|
||||||
|
user = form.cleaned_data['username']
|
||||||
|
else:
|
||||||
|
return render_to_response('sso/userlookup.html', {
|
||||||
|
'form': form,
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
return render_to_response('sso/userlookup.html', {
|
||||||
|
'form': form,
|
||||||
|
})
|
||||||
|
|
||||||
is_admin = request.user.is_staff
|
is_admin = request.user.is_staff
|
||||||
|
|
||||||
@@ -174,28 +190,27 @@ def user_view(request, user):
|
|||||||
profile = user.get_profile()
|
profile = user.get_profile()
|
||||||
|
|
||||||
if is_admin:
|
if is_admin:
|
||||||
try:
|
try:
|
||||||
services = ServiceAccount.objects.filter(user=user).all()
|
services = ServiceAccount.objects.filter(user=user).all()
|
||||||
except ServiceAccount.DoesNotExist:
|
except ServiceAccount.DoesNotExist:
|
||||||
services = None
|
services = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
reddits = RedditAccount.objects.filter(user=user).all()
|
reddits = RedditAccount.objects.filter(user=user).all()
|
||||||
except ServiceAccount.DoesNotExist:
|
except ServiceAccount.DoesNotExist:
|
||||||
reddits = None
|
reddits = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
eveaccounts = EVEAccount.objects.filter(user=user).all()
|
eveaccounts = EVEAccount.objects.filter(user=user).all()
|
||||||
|
|
||||||
characters = []
|
characters = []
|
||||||
|
|
||||||
for acc in eveaccounts:
|
for acc in eveaccounts:
|
||||||
chars = acc.characters.all()
|
chars = acc.characters.all()
|
||||||
for char in chars:
|
for char in chars:
|
||||||
characters.append({'name': char.name, 'corp': char.corporation.name})
|
characters.append({'name': char.name, 'corp': char.corporation.name})
|
||||||
|
|
||||||
except EVEAccount.DoesNotExist:
|
except EVEAccount.DoesNotExist:
|
||||||
eveaccounts = None
|
eveaccounts = None
|
||||||
|
|
||||||
return render_to_response('sso/user.html', locals())
|
return render_to_response('sso/user.html', locals())
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,10 @@
|
|||||||
<li><a href="/">Home</a></li>
|
<li><a href="/">Home</a></li>
|
||||||
{% if request.user %}
|
{% if request.user %}
|
||||||
<li><a href="/profile">Profile</a></li>
|
<li><a href="/profile">Profile</a></li>
|
||||||
|
{% if request.user.is_staff %}
|
||||||
|
<li><a href="/users">Lookup User</a></li>
|
||||||
|
<li><a href="/admin">Admin</a></li>
|
||||||
|
{% endif %}
|
||||||
<li><a href="/logout">Logout</a></li>
|
<li><a href="/logout">Logout</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li><a href="/login">Login</a></li>
|
<li><a href="/login">Login</a></li>
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<h1>{{user.username}}'s Profile</h1>
|
<h1>{{user.username}}'s Profile</h1>
|
||||||
@@ -6,9 +8,10 @@
|
|||||||
<b>Email:</b> {{ user.email }}<br/>
|
<b>Email:</b> {{ user.email }}<br/>
|
||||||
|
|
||||||
{% if is_admin %}
|
{% if is_admin %}
|
||||||
|
<br/>
|
||||||
<h2>Service Accounts</h2>
|
<h2>Service Accounts</h2>
|
||||||
{% if services %}
|
{% if services %}
|
||||||
<table border=1>
|
<table>
|
||||||
<tr><th>Service</th><th>Username</th><th>Password</th><th>Active</th></tr>
|
<tr><th>Service</th><th>Username</th><th>Password</th><th>Active</th></tr>
|
||||||
{% for acc in services %}
|
{% for acc in services %}
|
||||||
<tr><td>{{ acc.service }}</td>
|
<tr><td>{{ acc.service }}</td>
|
||||||
@@ -19,10 +22,10 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<br/>
|
||||||
<h2>Eve API Keys</h2>
|
<h2>Eve API Keys</h2>
|
||||||
{% if eveaccounts %}
|
{% if eveaccounts %}
|
||||||
<table border=1>
|
<table>
|
||||||
<tr><th>User ID</th><th>API Key</th><th>Description</th><th>Active</th></tr>
|
<tr><th>User ID</th><th>API Key</th><th>Description</th><th>Active</th></tr>
|
||||||
{% for acc in eveaccounts %}
|
{% for acc in eveaccounts %}
|
||||||
<tr><td>{{ acc.api_user_id }}</td>
|
<tr><td>{{ acc.api_user_id }}</td>
|
||||||
@@ -35,7 +38,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<br/>
|
<br/>
|
||||||
{% if characters %}
|
{% if characters %}
|
||||||
<table border=1>
|
<table>
|
||||||
<tr><th>Character Name</th><th>Corp</th></tr>
|
<tr><th>Character Name</th><th>Corp</th></tr>
|
||||||
{% for char in characters %}
|
{% for char in characters %}
|
||||||
<tr><td>{{ char.name }}</td>
|
<tr><td>{{ char.name }}</td>
|
||||||
@@ -45,10 +48,10 @@
|
|||||||
</table>
|
</table>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<br/>
|
||||||
<h2>Reddit Accounts</h2>
|
<h2>Reddit Accounts</h2>
|
||||||
{% if reddits %}
|
{% if reddits %}
|
||||||
<table border=1>
|
<table>
|
||||||
<tr><th>Username</th><th>Created Date</th></tr>
|
<tr><th>Username</th><th>Created Date</th></tr>
|
||||||
{% for acc in reddits %}
|
{% for acc in reddits %}
|
||||||
<tr><td>{{ acc.username }}</td>
|
<tr><td>{{ acc.username }}</td>
|
||||||
|
|||||||
12
templates/sso/userlookup.html
Normal file
12
templates/sso/userlookup.html
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}User Lookup{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<form action="/users/" method="post">
|
||||||
|
<table>
|
||||||
|
{{ form.as_table }}
|
||||||
|
</table>
|
||||||
|
<input type="submit" value="Lookup" />
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user