Added User Lookup feature

This commit is contained in:
2010-03-10 00:55:39 +00:00
parent a6cbb2744b
commit 4ccdaf5187
6 changed files with 72 additions and 26 deletions

View File

@@ -1,4 +1,5 @@
from django import forms
from django.contrib.auth.models import User
from eve_api.models.api_player import EVEAccount
from sso.models import ServiceAccount, Service
@@ -52,3 +53,13 @@ class RedditAccountForm(forms.Form):
return self.cleaned_data
else:
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

View File

@@ -15,4 +15,5 @@ urlpatterns = patterns('',
(r'^profile/del/reddit/$', views.reddit_del),
(r'^profile/del/reddit/(?P<redditid>\d+)/$', views.reddit_del),
(r'^users/(?P<user>.*)/$', views.user_view),
(r'^users/$', views.user_view),
)

View File

@@ -9,7 +9,7 @@ from eve_api.api_puller.accounts import import_eve_account
from eve_api.models.api_player import EVEAccount
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
@@ -166,7 +166,23 @@ def reddit_del(request, redditid=0):
@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
@@ -198,4 +214,3 @@ def user_view(request, user):
eveaccounts = None
return render_to_response('sso/user.html', locals())

View File

@@ -17,6 +17,10 @@
<li><a href="/">Home</a></li>
{% if request.user %}
<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>
{% else %}
<li><a href="/login">Login</a></li>

View File

@@ -1,3 +1,5 @@
{% extends "base.html" %}
{% block content %}
<h1>{{user.username}}'s Profile</h1>
@@ -6,9 +8,10 @@
<b>Email:</b> {{ user.email }}<br/>
{% if is_admin %}
<br/>
<h2>Service Accounts</h2>
{% if services %}
<table border=1>
<table>
<tr><th>Service</th><th>Username</th><th>Password</th><th>Active</th></tr>
{% for acc in services %}
<tr><td>{{ acc.service }}</td>
@@ -19,10 +22,10 @@
{% endfor %}
</table>
{% endif %}
<br/>
<h2>Eve API Keys</h2>
{% if eveaccounts %}
<table border=1>
<table>
<tr><th>User ID</th><th>API Key</th><th>Description</th><th>Active</th></tr>
{% for acc in eveaccounts %}
<tr><td>{{ acc.api_user_id }}</td>
@@ -35,7 +38,7 @@
{% endif %}
<br/>
{% if characters %}
<table border=1>
<table>
<tr><th>Character Name</th><th>Corp</th></tr>
{% for char in characters %}
<tr><td>{{ char.name }}</td>
@@ -45,10 +48,10 @@
</table>
{% endif %}
<br/>
<h2>Reddit Accounts</h2>
{% if reddits %}
<table border=1>
<table>
<tr><th>Username</th><th>Created Date</th></tr>
{% for acc in reddits %}
<tr><td>{{ acc.username }}</td>

View 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 %}