зеркало из https://github.com/mozilla/FlightDeck.git
amo and person added, amo with fake auth
This commit is contained in:
Родитель
3ef7d0629c
Коммит
55d0e0dcb8
|
@ -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
|
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
|
@ -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.
|
|
@ -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.
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
source scripts/environment.sh
|
||||
|
||||
# run server
|
||||
cd $PROJECT_DIR/$PROJECT_NAME/
|
||||
django-admin.py $@
|
Загрузка…
Ссылка в новой задаче