def test_authenticating_users(self): """Tests the authentication of users""" # Creates the users user1 = FomoUser() user1.first_name = 'Stephane' user1.last_name = 'Akoki' user1.set_password('baseball') user1.date_joined = datetime.now() user1.last_login = datetime.now() user1.username = '******' user1.email = '*****@*****.**' user1.phone = '336-486-4595' user1.address = '1960 N Canyon Rd' user1.city = 'Provo' user1.state = 'Utah' user1.zip_code = '84604' user1.is_superuser = True user1.is_staff = True user1.is_active = True user1.save() #pull back off of the database user1auth = authenticate(username=user1.username, password='******') u2 = FomoUser.objects.get(username='******') self.assertEqual(u2, user1auth)
def authenticate(self, username=None, password=None): active_directory = LDAP() ad_user = active_directory.authenticate(username, password) if ad_user != None: try: user = FomoUser.objects.get(username=ad_user.sAMAccountName) user.username = ad_user.sAMAccountName user.first_name = ad_user.givenName user.last_name = ad_user.sn user.email = str(ad_user.userPrincipalName).replace( '.local', '.us') user.save() except FomoUser.DoesNotExist: user = FomoUser() user.username = ad_user.sAMAccountName user.first_name = ad_user.givenName user.last_name = ad_user.sn user.email = str(ad_user.userPrincipalName).replace( '.local', '.us') user.is_staff = True user.save() group = Group.objects.get(name__exact='Managers') user.groups.add(group) cart = ShoppingCart(user=user) cart.save() return user return None
u1 = FomoUser() u1.first_name = "Stephane" u1.last_name = "Akoki" u1.username = "******" u1.set_password("jeuvideo") u1.address = "Provo" u1.zip = '84604' u1.date_joined = datetime.now() u1.last_login = datetime.now() u1.email = "*****@*****.**" u1.phone_number = "8013863392" u1.city = "Provo" u1.state = "UT" u1.is_staff = True u1.is_active = True u1.save() u2 = FomoUser() u2.first_name = "Xavier" u2.last_name = "Akoki" u2.username = "******" u2.set_password("jeuvideo") u2.address = "Draper" u2.zip = '84604' u2.date_joined = datetime.now() u2.last_login = datetime.now() u2.email = "*****@*****.**" u2.phone_number = "8013863392" u2.city = "Provo" u2.state = "UT" u2.is_staff = True
## USERS ## u1 = FomoUser() u1.username = '******' u1.first_name = 'Colby' u1.last_name = 'Thomas' u1.gender = 'Male' u1.birthdate = date(1994, 6, 16) u1.email = '*****@*****.**' u1.password = '******' u1.is_staff = True u1.is_active = True u1.date_joined = datetime.now() u1.last_login = datetime.now() u1.save() u2 = FomoUser() u2.username = '******' u2.first_name = 'Marc' u2.last_name = 'Oelkers' u2.gender = 'Male' u2.birthdate = date(1994, 2, 13) u2.email = '*****@*****.**' u2.password = '******' u2.is_staff = True u2.is_active = True u2.date_joined = datetime.now() u2.last_login = datetime.now() u2.save()
import django django.setup() from account.models import FomoUser #user 1 user1 = FomoUser() user1.address = "Provo, UT 84602" user1.city = "Provo" user1.gender = "Female" user1.phone = "801-422-4636" user1.state = "UTAH" user1.stateinitial = "UT" user1.zipcode = "84602" user1.save() #user 2 user2 = FomoUser() user2.address = "Provo, UT 84602" user2.city = "Provo" user2.gender = "Female" user2.phone = "801-422-4636" user2.state = "UTAH" user2.stateinitial = "UT" user2.zipcode = "84602" user2.save() #user 3 user3 = FomoUser() user3.address = "Provo, UT 84602"