Commits

Joe Heck  committed 1220975

adding user profile page, updating login/logout

  • Participants
  • Parent commits 787a040

Comments (0)

Files changed (5)

File eyeswebapp/core/views.py

     passive = forms.BooleanField(initial=False)  # identifies a passive monitor
     host = forms.ModelChoiceField(queryset=host_queryset, empty_label="(No Host)")
 
+    # if request.method == 'POST': # If the form has been submitted...
+    #     form = ContactForm(request.POST) # A form bound to the POST data
+    #     if form.is_valid():
+    #         subject = form.cleaned_data['subject']
+    #         message = form.cleaned_data['message']
+    #         sender = form.cleaned_data['sender']
+    #         cc_myself = form.cleaned_data['cc_myself']
+    # 
+    #         return HttpResponseRedirect('/thanks/') # Redirect after POST
+    # else:
+    #     form = ContactForm() # An unbound form
+    # 
+    # return render_to_response('contact.html', {
+    #     'form': form,
+    # })
+
 def render_response(req, *args, **kwargs):
     """ a variation on render_to_response that inserts the RequestContext
     into each template context from these views."""
     return render_to_response(*args, **kwargs)
 
 
+#user profile view - supporting authentication/users
+def userprofile(request):
+    return render_response(request, 'registration/user_profile.html', {})
+
+
 # Create your views here.
 def index(request):
     """ default web view for the 'front page' of the web application. """

File eyeswebapp/settings.py

 
 ROOT_URLCONF = 'eyeswebapp.urls'
 
-LOGIN_REDIRECT_URL = '/'
+#LOGIN_REDIRECT_URL = '/'
 
 TEMPLATE_DIRS = (
     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".

File eyeswebapp/templates/base.html

 					<li><a href="/core/" rel="external">Alerts</a></li>
 					<li><a href="/core/monitor_list/" rel="external">Monitors</a></li>
 					<li><a href="/core/host_list/" rel="external">Hosts</a></li>
-					<li><a href="/core/monitor_list/" rel="external">New</a></li>
 					<li>{% if user.is_authenticated %}
-						<a href="{% url django.contrib.auth.views.logout %}" rel="external">{{ user.username }}</a>
+						<a href="{% url eyeswebapp.core.views.userprofile %}" rel="external">{{ user.username }}</a>
 						{% else %}
-						<a href="{% url django.contrib.auth.views.login %}" rel="external">Anonymous (login)</a>
+						<a href="{% url django.contrib.auth.views.login %}" rel="external">(login)</a>
 					{% endif %}</li>
 				</ul>
 			</div><!-- /navbar -->

File eyeswebapp/templates/registration/user_profile.html

+{% extends "base.html" %}
+
+{% block content %}
+
+
+<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="a">
+	<li data-role="list-divider">User Profile</li>
+	<li>
+		<div class="ui-grid-a">
+			<div class="ui-block-a">username</div>
+			<div class="ui-block-b">
+				{% if request.user.is_anonymous %}Anonymous User{% else %}{{request.user.username}}{% endif %}
+			</div>
+		</div><!-- /grid-a -->
+	</li>
+	<li>
+		<div class="ui-grid-a">
+			<div class="ui-block-a">first name</div>
+			<div class="ui-block-b">{{request.user.first_name}}</div>
+		</div><!-- /grid-a -->
+	</li>
+	<li>
+		<div class="ui-grid-a">
+			<div class="ui-block-a">last name</div>
+			<div class="ui-block-b">{{request.user.last_name}}</div>
+		</div><!-- /grid-a -->
+	</li>
+	<li>
+		<div class="ui-grid-a">
+			<div class="ui-block-a">email</div>
+			<div class="ui-block-b">{{request.user.email}}</div>
+		</div><!-- /grid-a -->
+	</li>
+	<li>
+		{% if request.user.is_staff %}
+			<input type="checkbox" id="staff-checkbox" checked="true"/>
+		{% else %}
+			<input type="checkbox" id="staff-checkbox" />
+		{% endif %}
+		<label for="staff-checkbox">Staff</label>
+	</li>
+	<li>
+		{% if request.user.is_superuser %}
+			<input type="checkbox" id="superuser-checkbox" checked="true"/>
+		{% else %}
+			<input type="checkbox" id="superuser-checkbox" />
+		{% endif %}
+		<label for="superuser-checkbox">Superuser</label>
+	</li>
+</ul>
+
+<div>
+{% if request.user.is_staff %}
+<a href="/admin/" data-role="button" data-icon="gear" rel="external" data-inline="true">Admin Site</a>
+{% endif %}
+<a href="/accounts/logout/" data-role="button" data-icon="delete" rel="external" data-inline="true">Logout</a>
+</div>
+
+<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="a">
+	<li data-role="list-divider">Groups</li>
+	{% for group in request.user.groups.all %}
+	<li>{{group}}</li>
+	{% endfor %}
+</ul>
+
+<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="a">
+	<li data-role="list-divider">Permissions</li>
+	{% for permstring in request.user.get_all_permissions %}
+	<li>{{permstring}}</li>
+	{% endfor %}
+</ul>
+
+
+{% endblock %}

File eyeswebapp/urls.py

     (r'^admin/', include(admin.site.urls)),
     (r'^accounts/login/$', 'django.contrib.auth.views.login'),
     (r'^accounts/logout/$', 'django.contrib.auth.views.logout'),
+    (r'^accounts/profile/$', 'eyeswebapp.core.views.userprofile')
     ## Override the default registration form
     #url(r'^account/register/$', 'registration.views.register',
     #    kwargs={'form_class': UserRegistrationForm},