1. Udi Bauman
  2. ultrasound

Commits

Udi Bauman  committed 484f5c1

temporarily changed to django authentication

  • Participants
  • Parent commits 4d746f3
  • Branches default

Comments (0)

Files changed (5)

File django_ultrasound/app.yaml

View file
  • Ignore whitespace
 application: ultrasound-2010
-version: 2
+version: 1
 runtime: python
 api_version: 1
 

File django_ultrasound/customers/templates/home.html

View file
  • Ignore whitespace
 
 {{ content }}
 
+
+<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
+
+<hr>
+<font size="-3"><a href="/accounts/login/">Employees login</a></font>
 </body>
 </html>

File django_ultrasound/customers/views.py

View file
  • Ignore whitespace
+from django.contrib.auth.models import User
 from django.http import HttpResponseRedirect
 from django.contrib.auth.decorators import login_required
 from django.shortcuts import render_to_response
 from customers.forms import CustomerMoreDetailsForm
-from customers.models import CANDIDATE
+from customers.models import CANDIDATE, CustomerStatus
 from common.utils import evaluate_template
 from employees.models import Employee
+from customers.models import Customer, CustomerStatus, REQUESTING_TO_BE_CANDIDATE
+from django.contrib import auth
 
-@login_required
 def customer_home(request):
     user = request.user
 
-    if is_employee(user):
+    if user.is_authenticated() and is_employee(user):
         return HttpResponseRedirect("/employee_home/")
 
-    customer = user.customer.get()
+    try:
+        customer = user.customer.get()
+    except:
+        contrib_user = User()
+        contrib_user.save()
+        contrib_user.username = u"user_%s" % contrib_user.id
+        contrib_user.is_staff = True
+        contrib_user.is_superuser = True
+        password = "tukyrtxtubs"
+        contrib_user.set_password(password)
+        contrib_user.save()
+
+        # create Customer
+        customer = Customer()
+        customer.user = contrib_user
+        customer.fb_key = contrib_user.id # fb.facebook_id
+        #customer.link_to_page = "http://www.facebook.com/?uid=%s" % customer.fb_key
+        customer.customer_status = CustomerStatus.objects.get(code=REQUESTING_TO_BE_CANDIDATE)
+        customer.save()
+
+        status = "created new user"
+
+        authenticated_user = auth.authenticate(
+                                     username=contrib_user.username,
+                                     password=password)
+        auth.login(request, authenticated_user)
+
+
+
     customer_status = customer.customer_status
     data = {
-        "user_first_name": user.first_name,
+        "user_first_name": user.username,
         # add any fields that will be inserted into the HTML page
     }
     data["title"] = evaluate_template(customer_status.html_page.title, data)

File django_ultrasound/templates/registration/login.html

View file
  • Ignore whitespace
+{% extends "admin/base_site.html" %}
+{% load i18n %}
+
+{% block extrastyle %}{% load adminmedia %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/login.css" />{% endblock %}
+
+{% block bodyclass %}login{% endblock %}
+
+{% block content_title %}{% endblock %}
+
+{% block breadcrumbs %}{% endblock %}
+
+{% block content %}
+{% if error_message %}
+<p class="errornote">{{ error_message }}</p>
+{% endif %}
+<div id="content-main">
+<form action="{{ app_path }}" method="post" id="login-form">{% csrf_token %}
+  <div class="form-row">
+    <label for="id_username">{% trans 'Username:' %}</label> <input type="text" name="username" id="id_username" />
+  </div>
+  <div class="form-row">
+    <label for="id_password">{% trans 'Password:' %}</label> <input type="password" name="password" id="id_password" />
+    <input type="hidden" name="this_is_the_login_form" value="1" />
+  </div>
+  <div class="submit-row">
+    <label>&nbsp;</label><input type="submit" value="{% trans 'Log in' %}" />
+  </div>
+</form>
+
+<script type="text/javascript">
+document.getElementById('id_username').focus()
+</script>
+</div>
+{% endblock %}

File django_ultrasound/urls.py

View file
  • Ignore whitespace
 
     (r'^setup/create_first_user/', 'employees.views.setup_first_user'),
 
+    (r'^accounts/login/$', 'django.contrib.auth.views.login'),    
+
     (r'^home/', 'customers.views.customer_home'),
     (r'^employee_home/', 'employees.views.employee_home'),
 
+    (r'^$', 'customers.views.customer_home'),
 
-    url(r'^$', direct_to_template, {'template': 'login.html'}, name='login'),
+#    url(r'^$', direct_to_template, {'template': 'login.html'}, name='login'),
 )