amo and person added, amo with fake auth

This commit is contained in:
Piotr Zalewa 2010-02-04 18:18:57 +00:00
Родитель 3ef7d0629c
Коммит 55d0e0dcb8
10 изменённых файлов: 113 добавлений и 0 удалений

Просмотреть файл

Просмотреть файл

@ -0,0 +1,50 @@
from django.contrib.auth.models import User
from person.models import Profile
class AMOAuthentication:
def authenticate(self, username, password):
"""
Authenticate user by contacting with AMO
"""
# Try to retrieve AMO session info from db
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
user = None
amo_session = None
if user:
amo_session = user.get_profile().amo_session
# TODO: here contact AMO and receive authentication status
authenticated = False
if username != 'fake':
authenticated = True
# TODO: "steal" session cookie from AMO and save in profile
amo_session = "fake"
if not authenticated:
return False
# save user into the database
if not user:
user = User(
username=username,
password='saved in AMO',
# TODO: retrieve from AMO
first_name="John",
last_name="Doe",
email='fake@email.com'
)
user.save()
try:
profile = user.get_profile()
except Profile.DoesNotExist:
profile = Profile()
profile.amo_session = amo_session
profile.save()
return user

3
flightdeck/amo/models.py Normal file
Просмотреть файл

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

23
flightdeck/amo/tests.py Normal file
Просмотреть файл

@ -0,0 +1,23 @@
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.failUnlessEqual(1 + 1, 2)
__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}

1
flightdeck/amo/views.py Normal file
Просмотреть файл

@ -0,0 +1 @@
# Create your views here.

Просмотреть файл

Просмотреть файл

@ -0,0 +1,5 @@
from django.db import models
from django.contrib.auth.models import User
class Profile(models.Model):
amo_session = models.CharField(max_length=255, blank=True, null=True)

Просмотреть файл

@ -0,0 +1,23 @@
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.failUnlessEqual(1 + 1, 2)
__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}

Просмотреть файл

@ -0,0 +1 @@
# Create your views here.

7
scripts/django-admin.sh Executable file
Просмотреть файл

@ -0,0 +1,7 @@
#!/bin/bash
source scripts/environment.sh
# run server
cd $PROJECT_DIR/$PROJECT_NAME/
django-admin.py $@