Enforce unique AuthServicesInfo (#618)

Alter user field to OneToOneField
Migration to enforce uniqueness pre-change
Migration to ensure all users have an AuthServicesInfo
Receiver to automatically create one upon user creation
Replace AuthServicesInfo.get_or_create with get
Prevent deletion of AuthServicesInfo from admin site
Remove add and delete permissions from model.

Get character names in chunks on corpstats update to prevent HTTP400 when requesting >350(ish) names

Include corpstats docs.
Update settings docs.
This commit is contained in:
Adarnof 2017-01-11 21:48:20 -05:00 committed by GitHub
parent 33c2ba9bca
commit 8360371ab7
26 changed files with 406 additions and 129 deletions

View File

@ -26,6 +26,14 @@ class AuthServicesInfoManager(admin.ModelAdmin):
pass pass
return None return None
@staticmethod
def has_delete_permission(request, obj=None):
return False
@staticmethod
def has_add_permission(request, obj=None):
return False
def sync_jabber(self, request, queryset): def sync_jabber(self, request, queryset):
count = 0 count = 0
for a in queryset: # queryset filtering doesn't work here? for a in queryset: # queryset filtering doesn't work here?

View File

@ -17,7 +17,7 @@ class AuthServicesInfoManager:
def update_main_char_id(char_id, user): def update_main_char_id(char_id, user):
if User.objects.filter(username=user.username).exists(): if User.objects.filter(username=user.username).exists():
logger.debug("Updating user %s main character to id %s" % (user, char_id)) logger.debug("Updating user %s main character to id %s" % (user, char_id))
authserviceinfo = AuthServicesInfo.objects.get_or_create(user=user)[0] authserviceinfo = AuthServicesInfo.objects.get(user=user)
authserviceinfo.main_char_id = char_id authserviceinfo.main_char_id = char_id
authserviceinfo.save(update_fields=['main_char_id']) authserviceinfo.save(update_fields=['main_char_id'])
logger.info("Updated user %s main character to id %s" % (user, char_id)) logger.info("Updated user %s main character to id %s" % (user, char_id))
@ -28,7 +28,7 @@ class AuthServicesInfoManager:
def update_user_forum_info(username, user): def update_user_forum_info(username, user):
if User.objects.filter(username=user.username).exists(): if User.objects.filter(username=user.username).exists():
logger.debug("Updating user %s forum info: username %s" % (user, username)) logger.debug("Updating user %s forum info: username %s" % (user, username))
authserviceinfo = AuthServicesInfo.objects.get_or_create(user=user)[0] authserviceinfo = AuthServicesInfo.objects.get(user=user)
authserviceinfo.forum_username = username authserviceinfo.forum_username = username
authserviceinfo.save(update_fields=['forum_username']) authserviceinfo.save(update_fields=['forum_username'])
logger.info("Updated user %s forum info in authservicesinfo model." % user) logger.info("Updated user %s forum info in authservicesinfo model." % user)
@ -39,7 +39,7 @@ class AuthServicesInfoManager:
def update_user_jabber_info(username, user): def update_user_jabber_info(username, user):
if User.objects.filter(username=user.username).exists(): if User.objects.filter(username=user.username).exists():
logger.debug("Updating user %s jabber info: username %s" % (user, username)) logger.debug("Updating user %s jabber info: username %s" % (user, username))
authserviceinfo = AuthServicesInfo.objects.get_or_create(user=user)[0] authserviceinfo = AuthServicesInfo.objects.get(user=user)
authserviceinfo.jabber_username = username authserviceinfo.jabber_username = username
authserviceinfo.save(update_fields=['jabber_username']) authserviceinfo.save(update_fields=['jabber_username'])
logger.info("Updated user %s jabber info in authservicesinfo model." % user) logger.info("Updated user %s jabber info in authservicesinfo model." % user)
@ -50,7 +50,7 @@ class AuthServicesInfoManager:
def update_user_mumble_info(username, user): def update_user_mumble_info(username, user):
if User.objects.filter(username=user.username).exists(): if User.objects.filter(username=user.username).exists():
logger.debug("Updating user %s mumble info: username %s" % (user, username)) logger.debug("Updating user %s mumble info: username %s" % (user, username))
authserviceinfo = AuthServicesInfo.objects.get_or_create(user=user)[0] authserviceinfo = AuthServicesInfo.objects.get(user=user)
authserviceinfo.mumble_username = username authserviceinfo.mumble_username = username
authserviceinfo.save(update_fields=['mumble_username']) authserviceinfo.save(update_fields=['mumble_username'])
logger.info("Updated user %s mumble info in authservicesinfo model." % user) logger.info("Updated user %s mumble info in authservicesinfo model." % user)
@ -61,7 +61,7 @@ class AuthServicesInfoManager:
def update_user_ipboard_info(username, user): def update_user_ipboard_info(username, user):
if User.objects.filter(username=user.username).exists(): if User.objects.filter(username=user.username).exists():
logger.debug("Updating user %s ipboard info: uername %s" % (user, username)) logger.debug("Updating user %s ipboard info: uername %s" % (user, username))
authserviceinfo = AuthServicesInfo.objects.get_or_create(user=user)[0] authserviceinfo = AuthServicesInfo.objects.get(user=user)
authserviceinfo.ipboard_username = username authserviceinfo.ipboard_username = username
authserviceinfo.save(update_fields=['ipboard_username']) authserviceinfo.save(update_fields=['ipboard_username'])
logger.info("Updated user %s ipboard info in authservicesinfo model." % user) logger.info("Updated user %s ipboard info in authservicesinfo model." % user)
@ -72,7 +72,7 @@ class AuthServicesInfoManager:
def update_user_xenforo_info(username, user): def update_user_xenforo_info(username, user):
if User.objects.filter(username=user.username).exists(): if User.objects.filter(username=user.username).exists():
logger.debug("Updating user %s xenforo info: uername %s" % (user, username)) logger.debug("Updating user %s xenforo info: uername %s" % (user, username))
authserviceinfo = AuthServicesInfo.objects.get_or_create(user=user)[0] authserviceinfo = AuthServicesInfo.objects.get(user=user)
authserviceinfo.xenforo_username = username authserviceinfo.xenforo_username = username
authserviceinfo.save(update_fields=['xenforo_username']) authserviceinfo.save(update_fields=['xenforo_username'])
logger.info("Updated user %s xenforo info in authservicesinfo model." % user) logger.info("Updated user %s xenforo info in authservicesinfo model." % user)
@ -83,7 +83,7 @@ class AuthServicesInfoManager:
def update_user_teamspeak3_info(uid, perm_key, user): def update_user_teamspeak3_info(uid, perm_key, user):
if User.objects.filter(username=user.username).exists(): if User.objects.filter(username=user.username).exists():
logger.debug("Updating user %s teamspeak3 info: uid %s" % (user, uid)) logger.debug("Updating user %s teamspeak3 info: uid %s" % (user, uid))
authserviceinfo = AuthServicesInfo.objects.get_or_create(user=user)[0] authserviceinfo = AuthServicesInfo.objects.get(user=user)
authserviceinfo.teamspeak3_uid = uid authserviceinfo.teamspeak3_uid = uid
authserviceinfo.teamspeak3_perm_key = perm_key authserviceinfo.teamspeak3_perm_key = perm_key
authserviceinfo.save(update_fields=['teamspeak3_uid', 'teamspeak3_perm_key']) authserviceinfo.save(update_fields=['teamspeak3_uid', 'teamspeak3_perm_key'])
@ -95,7 +95,7 @@ class AuthServicesInfoManager:
def update_is_blue(is_blue, user): def update_is_blue(is_blue, user):
if User.objects.filter(username=user.username).exists(): if User.objects.filter(username=user.username).exists():
logger.debug("Updating user %s blue status: %s" % (user, is_blue)) logger.debug("Updating user %s blue status: %s" % (user, is_blue))
authserviceinfo = AuthServicesInfo.objects.get_or_create(user=user)[0] authserviceinfo = AuthServicesInfo.objects.get(user=user)
authserviceinfo.is_blue = is_blue authserviceinfo.is_blue = is_blue
authserviceinfo.save(update_fields=['is_blue']) authserviceinfo.save(update_fields=['is_blue'])
logger.info("Updated user %s blue status to %s in authservicesinfo model." % (user, is_blue)) logger.info("Updated user %s blue status to %s in authservicesinfo model." % (user, is_blue))
@ -104,7 +104,7 @@ class AuthServicesInfoManager:
def update_user_discord_info(user_id, user): def update_user_discord_info(user_id, user):
if User.objects.filter(username=user.username).exists(): if User.objects.filter(username=user.username).exists():
logger.debug("Updating user %s discord info: user_id %s" % (user, user_id)) logger.debug("Updating user %s discord info: user_id %s" % (user, user_id))
authserviceinfo = AuthServicesInfo.objects.get_or_create(user=user)[0] authserviceinfo = AuthServicesInfo.objects.get(user=user)
authserviceinfo.discord_uid = user_id authserviceinfo.discord_uid = user_id
authserviceinfo.save(update_fields=['discord_uid']) authserviceinfo.save(update_fields=['discord_uid'])
logger.info("Updated user %s discord info in authservicesinfo model." % user) logger.info("Updated user %s discord info in authservicesinfo model." % user)
@ -115,7 +115,7 @@ class AuthServicesInfoManager:
def update_user_ips4_info(username, id, user): def update_user_ips4_info(username, id, user):
if User.objects.filter(username=user.username).exists(): if User.objects.filter(username=user.username).exists():
logger.debug("Updating user %s IPS4 info: username %s" % (user, username)) logger.debug("Updating user %s IPS4 info: username %s" % (user, username))
authserviceinfo = AuthServicesInfo.objects.get_or_create(user=user)[0] authserviceinfo = AuthServicesInfo.objects.get(user=user)
authserviceinfo.ips4_username = username authserviceinfo.ips4_username = username
authserviceinfo.ips4_id = id authserviceinfo.ips4_id = id
authserviceinfo.save(update_fields=['ips4_username', 'ips4_id']) authserviceinfo.save(update_fields=['ips4_username', 'ips4_id'])
@ -127,7 +127,7 @@ class AuthServicesInfoManager:
def update_user_smf_info(username, user): def update_user_smf_info(username, user):
if User.objects.filter(username=user.username).exists(): if User.objects.filter(username=user.username).exists():
logger.debug("Updating user %s forum info: username %s" % (user, username)) logger.debug("Updating user %s forum info: username %s" % (user, username))
authserviceinfo = AuthServicesInfo.objects.get_or_create(user=user)[0] authserviceinfo = AuthServicesInfo.objects.get(user=user)
authserviceinfo.smf_username = username authserviceinfo.smf_username = username
authserviceinfo.save(update_fields=['smf_username']) authserviceinfo.save(update_fields=['smf_username'])
logger.info("Updated user %s smf info in authservicesinfo model." % user) logger.info("Updated user %s smf info in authservicesinfo model." % user)
@ -138,7 +138,7 @@ class AuthServicesInfoManager:
def update_user_market_info(username, user): def update_user_market_info(username, user):
if User.objects.filter(username=user.username).exists(): if User.objects.filter(username=user.username).exists():
logger.debug("Updating user %s market info: username %s" % (user, username)) logger.debug("Updating user %s market info: username %s" % (user, username))
authserviceinfo = AuthServicesInfo.objects.get_or_create(user=user)[0] authserviceinfo = AuthServicesInfo.objects.get(user=user)
authserviceinfo.market_username = username authserviceinfo.market_username = username
authserviceinfo.save(update_fields=['market_username']) authserviceinfo.save(update_fields=['market_username'])
logger.info("Updated user %s market info in authservicesinfo model." % user) logger.info("Updated user %s market info in authservicesinfo model." % user)
@ -173,7 +173,7 @@ class UserState:
@classmethod @classmethod
def get_membership_state(cls, request): def get_membership_state(cls, request):
if request.user.is_authenticated: if request.user.is_authenticated:
auth = AuthServicesInfo.objects.get_or_create(user=request.user)[0] auth = AuthServicesInfo.objects.get(user=request.user)
return {'STATE': auth.state} return {'STATE': auth.state}
return {'STATE': cls.NONE_STATE} return {'STATE': cls.NONE_STATE}
@ -182,6 +182,6 @@ class UserState:
if user.is_superuser and settings.SUPERUSER_STATE_BYPASS: if user.is_superuser and settings.SUPERUSER_STATE_BYPASS:
return True return True
if user.is_authenticated: if user.is_authenticated:
auth = AuthServicesInfo.objects.get_or_create(user=user)[0] auth = AuthServicesInfo.objects.get(user=user)
return auth.state in states return auth.state in states
return False return False

View File

@ -24,7 +24,7 @@ def determine_membership_by_character(char, apps):
def determine_membership_by_user(user, apps): def determine_membership_by_user(user, apps):
AuthServicesInfo = apps.get_model('authentication', 'AuthServicesInfo') AuthServicesInfo = apps.get_model('authentication', 'AuthServicesInfo')
auth, c = AuthServicesInfo.objects.get_or_create(user=user) auth = AuthServicesInfo.objects.get(user=user)
if auth.main_char_id: if auth.main_char_id:
EveCharacter = apps.get_model('eveonline', 'EveCharacter') EveCharacter = apps.get_model('eveonline', 'EveCharacter')
if EveCharacter.objects.filter(character_id=auth.main_char_id).exists(): if EveCharacter.objects.filter(character_id=auth.main_char_id).exists():
@ -41,7 +41,7 @@ def set_state(user, apps):
else: else:
state = NONE_STATE state = NONE_STATE
AuthServicesInfo = apps.get_model('authentication', 'AuthServicesInfo') AuthServicesInfo = apps.get_model('authentication', 'AuthServicesInfo')
auth = AuthServicesInfo.objects.get_or_create(user=user)[0] auth = AuthServicesInfo.objects.get(user=user)
if auth.state != state: if auth.state != state:
auth.state = state auth.state = state
auth.save() auth.save()

View File

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.1 on 2017-01-07 06:47
from __future__ import unicode_literals
from django.db import migrations
def count_completed_fields(model):
return len([True for key, value in model.__dict__.items() if bool(value)])
def forward(apps, schema_editor):
# this ensures only one model exists per user
AuthServicesInfo = apps.get_model('authentication', 'AuthServicesInfo')
users = set([a.user for a in AuthServicesInfo.objects.all()])
for u in users:
auths = AuthServicesInfo.objects.filter(user=u)
if auths.count() > 1:
pk = auths[0].pk
largest = 0
for auth in auths:
completed = count_completed_fields(auth)
if completed > largest:
largest = completed
pk = auth.pk
auths.exclude(pk=pk).delete()
# ensure all users have a model
User = apps.get_model('auth', 'User')
for u in User.objects.exclude(pk__in=[user.pk for user in users]):
AuthServicesInfo.objects.create(user=u)
class Migration(migrations.Migration):
dependencies = [
('authentication', '0009_auto_20161021_0228'),
]
operations = [
migrations.RunPython(forward, migrations.RunPython.noop)
]

View File

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.1 on 2017-01-07 07:11
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('authentication', '0010_only_one_authservicesinfo'),
]
operations = [
migrations.AlterField(
model_name='authservicesinfo',
name='user',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]

View File

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-01-12 00:59
from __future__ import unicode_literals
from django.db import migrations, models
def remove_permissions(apps, schema_editor):
ContentType = apps.get_model('contenttypes', 'ContentType')
Permission = apps.get_model('auth', 'Permission')
AuthServicesInfo = apps.get_model('authentication', 'AuthServicesInfo')
# delete the add and remove permissions for AuthServicesInfo
ct = ContentType.objects.get_for_model(AuthServicesInfo)
Permission.objects.filter(content_type=ct).filter(codename__in=['add_authservicesinfo', 'delete_authservicesinfo']).delete()
def add_permissions(apps, schema_editor):
ContentType = apps.get_model('contenttypes', 'ContentType')
Permission = apps.get_model('auth', 'Permission')
AuthServicesInfo = apps.get_model('authentication', 'AuthServicesInfo')
# recreate the add and remove permissions for AuthServicesInfo
ct = ContentType.objects.get_for_model(AuthServicesInfo)
Permission.objects.create(content_type=ct, codename='add_authservicesinfo', name='Can add auth services info')
Permission.objects.create(content_type=ct, codename='delete_authservicesinfo', name='Can delete auth services info')
class Migration(migrations.Migration):
dependencies = [
('authentication', '0011_authservicesinfo_user_onetoonefield'),
]
operations = [
migrations.AlterModelOptions(
name='authservicesinfo',
options={'default_permissions': ('change',)},
),
migrations.RunPython(remove_permissions, add_permissions),
]

View File

@ -7,6 +7,9 @@ from authentication.states import MEMBER_STATE, BLUE_STATE, NONE_STATE
@python_2_unicode_compatible @python_2_unicode_compatible
class AuthServicesInfo(models.Model): class AuthServicesInfo(models.Model):
class Meta:
default_permissions = ('change',)
STATE_CHOICES = ( STATE_CHOICES = (
(NONE_STATE, 'None'), (NONE_STATE, 'None'),
(BLUE_STATE, 'Blue'), (BLUE_STATE, 'Blue'),
@ -27,7 +30,7 @@ class AuthServicesInfo(models.Model):
smf_username = models.CharField(max_length=254, blank=True, default="") smf_username = models.CharField(max_length=254, blank=True, default="")
market_username = models.CharField(max_length=254, blank=True, default="") market_username = models.CharField(max_length=254, blank=True, default="")
main_char_id = models.CharField(max_length=64, blank=True, default="") main_char_id = models.CharField(max_length=64, blank=True, default="")
user = models.ForeignKey(User) user = models.OneToOneField(User)
state = models.CharField(blank=True, null=True, choices=STATE_CHOICES, default=NONE_STATE, max_length=10) state = models.CharField(blank=True, null=True, choices=STATE_CHOICES, default=NONE_STATE, max_length=10)
def __str__(self): def __str__(self):

View File

@ -1,6 +1,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db.models.signals import pre_save from django.db.models.signals import pre_save, post_save
from django.dispatch import receiver from django.dispatch import receiver
from django.contrib.auth.models import User
from authentication.models import AuthServicesInfo from authentication.models import AuthServicesInfo
from authentication.states import MEMBER_STATE, BLUE_STATE from authentication.states import MEMBER_STATE, BLUE_STATE
from authentication.tasks import make_member, make_blue, disable_member from authentication.tasks import make_member, make_blue, disable_member
@ -23,3 +24,11 @@ def pre_save_auth_state(sender, instance, *args, **kwargs):
else: else:
disable_member(instance.user) disable_member(instance.user)
validate_services(instance.user, instance.state) validate_services(instance.user, instance.state)
@receiver(post_save, sender=User)
def post_save_user(sender, instance, created, *args, **kwargs):
# ensure all users have a model
if created:
AuthServicesInfo.objects.get_or_create(user=instance)

View File

@ -85,7 +85,7 @@ def determine_membership_by_character(char):
def determine_membership_by_user(user): def determine_membership_by_user(user):
logger.debug("Determining membership of user %s" % user) logger.debug("Determining membership of user %s" % user)
auth, c = AuthServicesInfo.objects.get_or_create(user=user) auth = AuthServicesInfo.objects.get(user=user)
if auth.main_char_id: if auth.main_char_id:
if EveCharacter.objects.filter(character_id=auth.main_char_id).exists(): if EveCharacter.objects.filter(character_id=auth.main_char_id).exists():
char = EveCharacter.objects.get(character_id=auth.main_char_id) char = EveCharacter.objects.get(character_id=auth.main_char_id)
@ -105,7 +105,7 @@ def set_state(user):
else: else:
state = NONE_STATE state = NONE_STATE
logger.debug("Assigning user %s to state %s" % (user, state)) logger.debug("Assigning user %s to state %s" % (user, state))
auth = AuthServicesInfo.objects.get_or_create(user=user)[0] auth = AuthServicesInfo.objects.get(user=user)
if auth.state != state: if auth.state != state:
auth.state = state auth.state = state
auth.save() auth.save()

View File

@ -9,7 +9,7 @@ class CorpStatsQuerySet(models.QuerySet):
if user.is_superuser: if user.is_superuser:
return self return self
auth = AuthServicesInfo.objects.get_or_create(user=user)[0] auth = AuthServicesInfo.objects.get(user=user)
try: try:
char = EveCharacter.objects.get(character_id=auth.main_char_id) char = EveCharacter.objects.get(character_id=auth.main_char_id)
# build all accepted queries # build all accepted queries

View File

@ -89,7 +89,7 @@ class CorpStats(models.Model):
return [name for id, name in self.members.items()] return [name for id, name in self.members.items()]
def show_apis(self, user): def show_apis(self, user):
auth = AuthServicesInfo.objects.get_or_create(user=user)[0] auth = AuthServicesInfo.objects.get(user=user)
if auth.main_char_id: if auth.main_char_id:
try: try:
char = EveCharacter.objects.get(character_id=auth.main_char_id) char = EveCharacter.objects.get(character_id=auth.main_char_id)

133
docs/features/corpstats.md Normal file
View File

@ -0,0 +1,133 @@
# Corp Stats
This module is used to check the registration status of corp members and to determine character relationships, being mains or alts.
## Creating a Corp Stats
Upon initial install, nothing will be visible. For every corp, a model will have to be created before data can be viewed.
![nothing is visible](http://i.imgur.com/va3DyT6.png)
If you are a superuser, the add button will be immediate visible to you. If not, your user account requires the `add_corpstats` permission.
Corp Stats requires an EVE SSO token to access data from the EVE Swagger Interface. Upon pressing the Add button, you will be prompted to authenticated. Please select the character who is in the corp you want data for.
![authorize from the EVE site](http://i.imgur.com/OnyoOAZ.png)
You will return to auth where you are asked to select a token with the green arrow button. If you want to use a different character, press the `LOG IN with EVE Online` button.
![select an SSO token to create with](http://i.imgur.com/KdA0XH0.png)
If this works (and you have permission to view the Corp Stats you just created) you'll be returned to a view of the Corp Stats.
If it fails an error message will be displayed.
## Corp Stats View
### Navigation Bar
![navigation bar](http://i.imgur.com/2l9gbml.png)
This bar contains a dropdown menu of all available corps. If the user has the `add_corpstats` permission, a button to add a Corp Stats will be shown.
On the right of this bar is a search field. Press enter to search. It checks all characters in all Corp Stats you have view permission to and returns search results. Generic searches (such as 'a') will be slow.
### API Index
![API Index](http://i.imgur.com/P1U2WJ2.png)
This is a visual indication of the number of registered characters.
### Last Update
![last update and update button](http://i.imgur.com/yHbueGK.png)
Corp Stats do not automatically update. They update once upon creation for initial data, and whenever someone presses the update button.
Only superusers and the creator of the Corp Stat can update it.
### Member List
![member list](http://i.imgur.com/udEVoSh.png)
The list contains all characters in the corp. Red backgrounds means they are not registered in auth. If registered, and the user has the required permission to view APIs, a link to JackKnife will be present.
A link to zKillboard is present for all characters.
If registered, the character will also have a main character, main corporation, and main alliance field.
This view is paginated: use the navigation arrows to view more pages (sorted alphabetically by character name), or search for a specific character.
![pagination buttons](http://i.imgur.com/otcPGsU.png)
## Search View
![search results](http://i.imgur.com/7wf0Q2C.png)
This view is essentially the same as the Corp Stats page, but not specific to a single corp.
The search query is visible in the search box.
Characters from all Corp Stats to which the user has view access will be displayed. APIs respect permissions.
This view is paginated: use the navigation arrows to view more pages (sorted alphabetically by character name).
## Permissions
To use this feature, users will require some of the following:
```eval_rst
+---------------------------------------+------------------+----------------------------------------------------+
| Permission | Admin Site | Auth Site |
+=======================================+==================+====================================================+
| corpstats.corp_apis | None | Can view API keys of members of their corporation. |
+---------------------------------------+------------------+----------------------------------------------------+
| corpstats.alliance_apis | None | Can view API keys of members of their alliance. |
+---------------------------------------+------------------+----------------------------------------------------+
| corpstats.blue_apis | None | Can view API keys of members of blue corporations. |
----------------------------------------+------------------+----------------------------------------------------+
| corpstats.view_corp_corpstats | None | Can view corp stats of their corporation. |
+---------------------------------------+------------------+----------------------------------------------------+
| corpstats.view_alliance_corpstats | None | Can view corp stats of members of their alliance. |
+---------------------------------------+------------------+----------------------------------------------------+
| corpstats.view_blue_corpstats | None | Can view corp stats of blue corporations. |
+---------------------------------------+------------------+----------------------------------------------------+
| corpstats.add_corpstats | Can create model | Can add new corpstats using an SSO token. |
+---------------------------------------+------------------+----------------------------------------------------+
| corpstats.change_corpstats | Can edit model | None. |
+---------------------------------------+------------------+----------------------------------------------------+
| corpstats.remove_corpstats | Can delete model | None. |
+---------------------------------------+------------------+----------------------------------------------------+
```
Typical use-cases would see the bundling of `corp_apis` and `view_corp_corpstats`, same for alliances and blues.
Alliance permissions supersede corp permissions. Note that these evaluate against the user's main character.
## Troubleshooting
### Failure to create Corp Stats
>Unrecognized corporation. Please ensure it is a member of the alliance or a blue.
Corp Stats can only be created for corporations who have a model in the database. These only exist for tenant corps,
corps of tenant alliances, blue corps, and members of blue alliances.
>Selected corp already has a statistics module.
Only one Corp Stats may exist at a time for a given corporation.
>Failed to gather corporation statistics with selected token.
During initial population, the EVE Swagger Interface did not return any member data. This aborts the creation process. Please wait for the API to start working before attempting to create again.
### Failure to update Corp Stats
Any of the following errors will result in a notification to the owning user, and deletion of the Corp Stats model.
>Your token has expired or is no longer valid. Please add a new one to create a new CorpStats.
This occurs when the SSO token is invalid, which can occur when deleted by the user, the character is transferred between accounts, or the API is having a bad day.
>CorpStats for corp_name cannot update with your ESI token as you have left corp.
The SSO token's character is no longer in the corp which the Corp Stats is for, and therefore membership data cannot be retrieved.
>HTTPForbidden
The SSO token lacks the required scopes to update membership data.

View File

@ -6,4 +6,5 @@
:caption: Contents :caption: Contents
hrapplications hrapplications
corpstats
``` ```

View File

@ -16,41 +16,35 @@ They're handled as strings because when settings are exported from shell command
When changing these booleans, edit the setting within the brackets (eg `('AA_MEMBER_CORP_GROUPS', 'True')` vs `('AA_MEMBER_CORP_GROUPS', 'False')`) and not the `True` earlier in the statement. Otherwise these will have unexpected behaviours. When changing these booleans, edit the setting within the brackets (eg `('AA_MEMBER_CORP_GROUPS', 'True')` vs `('AA_MEMBER_CORP_GROUPS', 'False')`) and not the `True` earlier in the statement. Otherwise these will have unexpected behaviours.
## Fields to Modify # Fields to Modify
### Required ## Required
- [SECRET_KEY](#secret_key) - [SECRET_KEY](#secret_key)
- Use [this tool](http://www.miniwebtool.com/django-secret-key-generator/) to generate a key on initial install - Use [this tool](http://www.miniwebtool.com/django-secret-key-generator/) to generate a key on initial install
- [DEBUG](#debug) - [DEBUG](#debug)
- If issues are encountered, set this to `True` to view a more detailed error report, otherwise set `False` - If issues are encountered, set this to `True` to view a more detailed error report, otherwise set `False`
- [ALLOWED_HOSTS](#allowed_hosts) - [ALLOWED_HOSTS](#allowed_hosts)
- This restricts web addresses auth will answer to. Separate with commas.
- Should include localhost `127.0.0.1` and `yourdomain.com` - Should include localhost `127.0.0.1` and `yourdomain.com`
- To allow from all, include `'*'`
- [DATABASES](#databases) - [DATABASES](#databases)
- Fill out the database name and user credentials to manage the auth database. - Fill out the database name and user credentials to manage the auth database.
- [IS_CORP](#is_corp)
- Set to `True` to run in corp mode, or `False` to run in alliance mode
- [DOMAIN](#domain) - [DOMAIN](#domain)
- Set to the domain name AllianceAuth will be accessible under - Set to the domain name AllianceAuth will be accessible under
- [EMAIL_HOST_USER](#email_host_user) - [EMAIL_HOST_USER](#email_host_user)
- Username to send emails from. If gmail account, the full gmail address. - Username to send emails from. If gmail account, the full gmail address.
- [EMAIL_HOST_PASSWORD](#email_host_password) - [EMAIL_HOST_PASSWORD](#email_host_password)
- Password for the email user. - Password for the email user.
- [CORP_ID](#corp_id) - [CORP_IDS](#corp_ids)
- If running in corp mode, set to the corp ID of the owning corp. - List of corp IDs who are members. Exclude if their alliance is in `ALLIANCE_IDS`
- [CORP_NAME](#corp_name) - [ALLIANCE_IDS](#alliance_ids)
- If running in corp mode, set to the name of the owning corp. - List of alliance IDs who are members.
- [ALLIANCE_ID](#alliance_id) - [ESI_SSO_CLIENT_ID](#esi_sso_client_id)
- If running in alliance mode, set to the alliance ID of the owning alliance. - EVE application ID from the developers site. See the [SSO Configuration Instruction](#ESI_SSO_CLIENT_ID)
- [ALLIANCE_NAME](#alliance_name) - [ESI_SSO_CLIENT_SECRET](#esi_sso_client_secret)
- If running in alliance mode, set to the name of the owning alliance. - EVE application secret from the developers site.
- [MEMBER_API_MASK](#member_api_mask) - [ESI_SSO_CALLBACK_URL](#esi_sso_callback_url)
- Set the minimum access mask for member API keys. - OAuth callback URL. Should be `https://mydomain.com/sso/callback`
- [MEMBER_API_ACCOUNT](#member_api_account)
- Set to `True` to require member API keys be account keys.
- [BLUE_API_MASK](#blue_api_mask)
- Set the minimum access mask for blue API keys.
- [BLUE_API_ACCOUNT](#blue_api_account)
- Set to `True` to require blue API keys be account keys.
## Services ## Services
### Member Services ### Member Services
@ -130,6 +124,7 @@ If connecting to Discourse, set the following
- [DISCOURSE_URL](#discourse_url) - [DISCOURSE_URL](#discourse_url)
- [DISCOURSE_API_USERNAME](#discourse_api_username) - [DISCOURSE_API_USERNAME](#discourse_api_username)
- [DISCOURSE_API_KEY](#discourse_api_key) - [DISCOURSE_API_KEY](#discourse_api_key)
- [DISCOURSE_SSO_SECRET](#discourse_sso_secret)
### IPSuite4 ### IPSuite4
If using IPSuite4 (aka IPBoard4) the following are required: If using IPSuite4 (aka IPBoard4) the following are required:
@ -184,9 +179,6 @@ Absolute URL to serve static files from.
Root folder to store static files in. Root folder to store static files in.
### SUPERUSER_STATE_BYPASS ### SUPERUSER_STATE_BYPASS
Overrides superuser account states to always return True on membership tests. If issues are encountered, or you want to test access to certain portions of the site, set to False to disable. Overrides superuser account states to always return True on membership tests. If issues are encountered, or you want to test access to certain portions of the site, set to False to disable.
## ALLIANCE / CORP TOGGLE
### IS_CORP
Used to determine the criteria used for member and blue validation, either requiring membership in the corp or alliance specified later, and being a standing of the corp or alliance specified later.
## EMAIL SETTINGS ## EMAIL SETTINGS
### DOMAIN ### DOMAIN
The URL to which emails will link. The URL to which emails will link.
@ -195,11 +187,11 @@ The host address of the email server.
### EMAIL_PORT ### EMAIL_PORT
The host port of the email server. The host port of the email server.
### EMAIL_HOST_USER ### EMAIL_HOST_USER
The username to authenticate as on the email server. The username to authenticate as on the email server. For GMail, this is the full address.
### EMAIL_HOST_PASSWORD ### EMAIL_HOST_PASSWORD
The password of the user used to authenticate on the email server. The password of the user used to authenticate on the email server.
### EMAIL_USE_TLS ### EMAIL_USE_TLS
Enable TLS connections to the email server. Enable TLS connections to the email server. Default is True.
## Front Page Links ## Front Page Links
### KILLBOARD_URL ### KILLBOARD_URL
Link to a killboard. Link to a killboard.
@ -207,13 +199,15 @@ Link to a killboard.
Link to another media site, eg YouTube channel. Link to another media site, eg YouTube channel.
### FORUM_URL ### FORUM_URL
Link to forums. Also used as the phpbb3 URL if enabled. Link to forums. Also used as the phpbb3 URL if enabled.
### SITE_NAME
Name to show in the top-left corner of auth.
## SSO Settings ## SSO Settings
If defined below, a `LOG IN WITH EVE ONLINE` button will be present on the login page. This allows registered users to log in as their characters instead of username/password. An application will need to be created on the developers site. Please select `Authenticated API Access`, and choose all scopes starting with `esi`.
### EVE_SSO_CLIENT_ID ### ESI_SSO_CLIENT_ID
The application cliend ID generated from the [developers site.](https://developers.eveonline.com) The application cliend ID generated from the [developers site.](https://developers.eveonline.com)
### EVE_SSO_CLIENT_SECRET ### ESI_SSO_CLIENT_SECRET
The application secret key generated from the [developers site.](https://developers.eveonline.com) The application secret key generated from the [developers site.](https://developers.eveonline.com)
### EVE_SSO_CALLBACK_URL ### ESI_SSO_CALLBACK_URL
The callback URL for authentication handshake. Should be `https://mydomain.com/sso/callback`. The callback URL for authentication handshake. Should be `https://mydomain.com/sso/callback`.
## Default Group Settings ## Default Group Settings
### DEFAULT_AUTH_GROUP ### DEFAULT_AUTH_GROUP
@ -276,20 +270,22 @@ Allow blues of the owning corp or alliance to generate accounts on a SMF install
Allow blues of the owning corp or alliance to generate accounts on an alliance market install. Allow blues of the owning corp or alliance to generate accounts on an alliance market install.
### ENABLE_BLUE_XENFORO ### ENABLE_BLUE_XENFORO
Allow blues of the owning corp or alliance to generate accounts on a XenForo install. Allow blues of the owning corp or alliance to generate accounts on a XenForo install.
## Corp Configuration ## Tenant Configuration
### CORP_ID Characters of any corp or alliance with their ID here will be treated as a member.
EVE corp ID of the owning corp, if `IS_CORP` is set to `True` ### CORP_IDS
## CORP_NAME EVE corp IDs of member corps. Separate with a comma.
Name of the owning corp, if `IS_CORP` is set to `True` ### ALLIANCE_IDS
## CORP_API_ID EVE alliance IDs of member alliances. Separate with a comma.
## Standings Configuration
To allow blues to access auth, standings must be pulled from a corp-level API. This API needs access mask 16 (ContactList).
### CORP_API_ID
The ID of an API key for a corp from which to pull standings, if desired. Needed for blues to gain access. The ID of an API key for a corp from which to pull standings, if desired. Needed for blues to gain access.
## CORP_API_VCODE ### CORP_API_VCODE
The verification code of an API key for a corp from which to pull standings, if desired. Needed for blues to gain access. The verification code of an API key for a corp from which to pull standings, if desired. Needed for blues to gain access.
## Alliance Configuration ### BLUE_STANDING
### ALLIANCE_ID The minimum standing value to consider blue. Default is 5.0
EVE alliance ID of the owning alliance, if `IS_CORP` is set to `False` ### STANDING_LEVEL
### ALLIANCE_NAME Standings from the API come at two levels: `corp` and `alliance`. Select which level to consider here.
Name of the owning alliance, if `IS_CORP` is set to `False`
## API Configuration ## API Configuration
### MEMBER_API_MASK ### MEMBER_API_MASK
Required access mask for members' API keys to be considered valid. Required access mask for members' API keys to be considered valid.
@ -303,10 +299,28 @@ If `True`, require API keys from blues to be account-wide, not character-restric
Require each submitted API be newer than the latest submitted API. Protects against recycled or stolen API keys. Require each submitted API be newer than the latest submitted API. Protects against recycled or stolen API keys.
### REJECT_OLD_APIS_MARGIN ### REJECT_OLD_APIS_MARGIN
Allows newly submitted APIs to have their ID this value lower than the highest API ID on record and still be accepted. Default is 50, 0 is safest. Allows newly submitted APIs to have their ID this value lower than the highest API ID on record and still be accepted. Default is 50, 0 is safest.
## EVE Provider Settings
Data about EVE objects (characters, corps, alliances) can come from two sources: the XML API or the EVE Swagger Interface.
These settings define the default source.
For most situations, the EVE Swagger Interface is best. But if it goes down or experiences issues, these can be reverted to the XML API.
Accepted values are `esi` and `xml`.
### EVEONLINE_CHARACTER_PROVIDER
The default data source to get character information. Default is `esi`
### EVEONLINE_CORP_PROVIDER
The default data source to get corporation information. Default is `esi`
### EVEONLINE_ALLIANCE_PROVIDER
The default data source to get alliance information. Default is `esi`
## Alliance Market
### MARKET_URL
The web address to access the Evernus Alliance Market application.
### MARKET_DB
The Evernus Alliance Market database connection information.
## HR Configuration ## HR Configuration
### JACK_KNIFE_URL ### JACK_KNIFE_URL
Link to an install of [eve-jackknife](https://code.google.com/archive/p/eve-jackknife/) Link to an install of [eve-jackknife](https://code.google.com/archive/p/eve-jackknife/)
## Forum Configuration ## IPBoard3 Configuration
### IPBOARD_ENDPOINT ### IPBOARD_ENDPOINT
URL to the `index.php` file of a IPBoard install's API server. URL to the `index.php` file of a IPBoard install's API server.
### IPBOARD_APIKEY ### IPBOARD_APIKEY
@ -340,6 +354,8 @@ Name of the broadcast service running on an Openfire install. Usually `broadcast
## Mumble Configuration ## Mumble Configuration
### MUMBLE_URL ### MUMBLE_URL
Address to instruct members to connect their Mumble clients to. Address to instruct members to connect their Mumble clients to.
### MUMBLE_SERVER_ID
Depreciated. We're too scared to delete it.
## Teamspeak3 Configuration ## Teamspeak3 Configuration
### TEAMSPEAK3_SERVER_IP ### TEAMSPEAK3_SERVER_IP
IP of a Teamspeak3 server on which to manage users. Usually `127.0.0.1` IP of a Teamspeak3 server on which to manage users. Usually `127.0.0.1`
@ -375,11 +391,13 @@ The web address of the Discourse server to direct users to.
Username of the account which generated the API key on Discourse. Username of the account which generated the API key on Discourse.
### DISCOURSE_API_KEY ### DISCOURSE_API_KEY
API key defined on Discourse. API key defined on Discourse.
### DISCOURSE_SSO_SECRET
The SSO secret key defined on Discourse.
## IPS4 Configuration ## IPS4 Configuration
### IPS4_URL ### IPS4_URL
URL of the IPSuite4 install to direct users to. URL of the IPSuite4 install to direct users to.
### IPS4_API_KEY ### IPS4_API_KEY
Depreciated. Depreciated. We're too scared to delete it.
### IPS4_DB ### IPS4_DB
The database connection to manage users on. The database connection to manage users on.
## SMF Configuration ## SMF Configuration
@ -398,3 +416,7 @@ API ID as [defined on Fleet-Up.](http://fleet-up.com/Api/MyKeys)
The group ID from which to pull data. Can be [retrieved from Fleet-Up](http://fleet-up.com/Api/Endpoints#groups_mygroupmemberships) The group ID from which to pull data. Can be [retrieved from Fleet-Up](http://fleet-up.com/Api/Endpoints#groups_mygroupmemberships)
## Logging Configuration ## Logging Configuration
This section is used to manage how logging messages are processed. This section is used to manage how logging messages are processed.
To turn off logging notifications, change the `handlers` `notifications` `class` to `logging.NullHandler`
## Everything below logging is magic. Do Not Touch

View File

@ -23,7 +23,7 @@ class EveCharacterAdmin(admin.ModelAdmin):
@staticmethod @staticmethod
def main_character(obj): def main_character(obj):
if obj.user: if obj.user:
auth = AuthServicesInfo.objects.get_or_create(user=obj.user)[0] auth = AuthServicesInfo.objects.get(user=obj.user)
if auth and auth.main_char_id: if auth and auth.main_char_id:
try: try:
return EveCharacter.objects.get(character_id=auth.main_char_id) return EveCharacter.objects.get(character_id=auth.main_char_id)

View File

@ -77,7 +77,7 @@ def refresh_user_apis(user):
for x in apis: for x in apis:
refresh_api(x) refresh_api(x)
# Check our main character # Check our main character
auth = AuthServicesInfo.objects.get_or_create(user=user)[0] auth = AuthServicesInfo.objects.get(user=user)
if auth.main_char_id: if auth.main_char_id:
if EveCharacter.objects.filter(character_id=auth.main_char_id).exists() is False: if EveCharacter.objects.filter(character_id=auth.main_char_id).exists() is False:
logger.info( logger.info(

View File

@ -51,7 +51,7 @@ def add_api_key(request):
logger.info("Successfully processed api add form for user %s" % request.user) logger.info("Successfully processed api add form for user %s" % request.user)
if not settings.API_SSO_VALIDATION: if not settings.API_SSO_VALIDATION:
messages.success(request, 'Added API key %s to your account.' % form.cleaned_data['api_id']) messages.success(request, 'Added API key %s to your account.' % form.cleaned_data['api_id'])
auth = AuthServicesInfo.objects.get_or_create(user=request.user)[0] auth = AuthServicesInfo.objects.get(user=request.user)
if not auth.main_char_id: if not auth.main_char_id:
return redirect('auth_characters') return redirect('auth_characters')
return redirect("auth_dashboard") return redirect("auth_dashboard")
@ -88,7 +88,7 @@ def api_sso_validate(request, token, api_id):
api.save() api.save()
EveCharacter.objects.filter(character_id__in=characters).update(user=request.user, api_id=api_id) EveCharacter.objects.filter(character_id__in=characters).update(user=request.user, api_id=api_id)
messages.success(request, 'Confirmed ownership of API %s' % api.api_id) messages.success(request, 'Confirmed ownership of API %s' % api.api_id)
auth, c = AuthServicesInfo.objects.get_or_create(user=request.user) auth = AuthServicesInfo.objects.get(user=request.user)
if not auth.main_char_id: if not auth.main_char_id:
return redirect('auth_characters') return redirect('auth_characters')
return redirect('auth_dashboard') return redirect('auth_dashboard')
@ -100,7 +100,7 @@ def api_sso_validate(request, token, api_id):
@login_required @login_required
def dashboard_view(request): def dashboard_view(request):
logger.debug("dashboard_view called by user %s" % request.user) logger.debug("dashboard_view called by user %s" % request.user)
auth_info = AuthServicesInfo.objects.get_or_create(user=request.user)[0] auth_info = AuthServicesInfo.objects.get(user=request.user)
apikeypairs = EveManager.get_api_key_pairs(request.user.id) apikeypairs = EveManager.get_api_key_pairs(request.user.id)
sso_validation = settings.API_SSO_VALIDATION or False sso_validation = settings.API_SSO_VALIDATION or False
api_chars = [] api_chars = []
@ -124,7 +124,7 @@ def dashboard_view(request):
@login_required @login_required
def api_key_removal(request, api_id): def api_key_removal(request, api_id):
logger.debug("api_key_removal called by user %s for api id %s" % (request.user, api_id)) logger.debug("api_key_removal called by user %s for api id %s" % (request.user, api_id))
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
EveManager.delete_api_key_pair(api_id, request.user.id) EveManager.delete_api_key_pair(api_id, request.user.id)
EveManager.delete_characters_by_api_id(api_id, request.user.id) EveManager.delete_characters_by_api_id(api_id, request.user.id)
messages.success(request, 'Deleted API key %s' % api_id) messages.success(request, 'Deleted API key %s' % api_id)
@ -140,7 +140,7 @@ def api_key_removal(request, api_id):
def characters_view(request): def characters_view(request):
logger.debug("characters_view called by user %s" % request.user) logger.debug("characters_view called by user %s" % request.user)
render_items = {'characters': EveManager.get_characters_by_owner_id(request.user.id), render_items = {'characters': EveManager.get_characters_by_owner_id(request.user.id),
'authinfo': AuthServicesInfo.objects.get_or_create(user=request.user)[0]} 'authinfo': AuthServicesInfo.objects.get(user=request.user)}
return render(request, 'registered/characters.html', context=render_items) return render(request, 'registered/characters.html', context=render_items)

View File

@ -86,7 +86,7 @@ def group_membership_list(request, group_id):
members = list() members = list()
for member in group.user_set.all().order_by('username'): for member in group.user_set.all().order_by('username'):
authinfo = AuthServicesInfo.objects.get_or_create(user=member)[0] authinfo = AuthServicesInfo.objects.get(user=member)
members.append({ members.append({
'user': member, 'user': member,
@ -294,7 +294,7 @@ def group_request_add(request, group_id):
logger.info("%s joining %s as is an open group" % (request.user, group)) logger.info("%s joining %s as is an open group" % (request.user, group))
request.user.groups.add(group) request.user.groups.add(group)
return redirect("auth_groups") return redirect("auth_groups")
auth_info = AuthServicesInfo.objects.get_or_create(user=request.user)[0] auth_info = AuthServicesInfo.objects.get(user=request.user)
grouprequest = GroupRequest() grouprequest = GroupRequest()
grouprequest.status = _('Pending') grouprequest.status = _('Pending')
grouprequest.group = group grouprequest.group = group
@ -325,7 +325,7 @@ def group_request_leave(request, group_id):
logger.info("%s leaving %s as is an open group" % (request.user, group)) logger.info("%s leaving %s as is an open group" % (request.user, group))
request.user.groups.remove(group) request.user.groups.remove(group)
return redirect("auth_groups") return redirect("auth_groups")
auth_info = AuthServicesInfo.objects.get_or_create(user=request.user)[0] auth_info = AuthServicesInfo.objects.get(user=request.user)
grouprequest = GroupRequest() grouprequest = GroupRequest()
grouprequest.status = _('Pending') grouprequest.status = _('Pending')
grouprequest.group = group grouprequest.group = group

View File

@ -19,7 +19,7 @@ logger = logging.getLogger(__name__)
def create_application_test(user): def create_application_test(user):
auth, c = AuthServicesInfo.objects.get_or_create(user=user) auth = AuthServicesInfo.objects.get(user=user)
if auth.main_char_id: if auth.main_char_id:
return True return True
else: else:
@ -31,7 +31,7 @@ def hr_application_management_view(request):
logger.debug("hr_application_management_view called by user %s" % request.user) logger.debug("hr_application_management_view called by user %s" % request.user)
corp_applications = [] corp_applications = []
finished_corp_applications = [] finished_corp_applications = []
auth_info, c = AuthServicesInfo.objects.get_or_create(user=request.user) auth_info = AuthServicesInfo.objects.get(user=request.user)
main_char = None main_char = None
if auth_info.main_char_id: if auth_info.main_char_id:
try: try:

View File

@ -37,7 +37,7 @@ def add_optimer_view(request):
# Get Current Time # Get Current Time
post_time = timezone.now() post_time = timezone.now()
# Get character # Get character
auth_info = AuthServicesInfo.objects.get_or_create(user=request.user)[0] auth_info = AuthServicesInfo.objects.get(user=request.user)
character = EveManager.get_character_by_id(auth_info.main_char_id) character = EveManager.get_character_by_id(auth_info.main_char_id)
# handle valid form # handle valid form
op = optimer() op = optimer()
@ -88,7 +88,7 @@ def edit_optimer(request, optimer_id):
form = opForm(request.POST) form = opForm(request.POST)
logger.debug("Received POST request containing update optimer form, is valid: %s" % form.is_valid()) logger.debug("Received POST request containing update optimer form, is valid: %s" % form.is_valid())
if form.is_valid(): if form.is_valid():
auth_info = AuthServicesInfo.objects.get_or_create(user=request.user)[0] auth_info = AuthServicesInfo.objects.get(user=request.user)
character = EveManager.get_character_by_id(auth_info.main_char_id) character = EveManager.get_character_by_id(auth_info.main_char_id)
op.doctrine = form.cleaned_data['doctrine'] op.doctrine = form.cleaned_data['doctrine']
op.system = form.cleaned_data['system'] op.system = form.cleaned_data['system']

View File

@ -325,7 +325,7 @@ class EveApiManager:
raise e raise e
except (requests.exceptions.RequestExeception, HTTPError, URLError) as e: except (requests.exceptions.RequestExeception, HTTPError, URLError) as e:
raise EveApiManager.ApiServerUnreachableError(e) raise EveApiManager.ApiServerUnreachableError(e)
auth, c = AuthServicesInfo.objects.get_or_create(user=user) auth = AuthServicesInfo.objects.get(user=user)
states = [auth.state] states = [auth.state]
from authentication.tasks import determine_membership_by_character # circular import issue from authentication.tasks import determine_membership_by_character # circular import issue
chars = info['characters'] chars = info['characters']

View File

@ -30,7 +30,7 @@ def m2m_changed_user_groups(sender, instance, action, *args, **kwargs):
def trigger_service_group_update(): def trigger_service_group_update():
logger.debug("Triggering service group update for %s" % instance) logger.debug("Triggering service group update for %s" % instance)
auth, c = AuthServicesInfo.objects.get_or_create(user=instance) auth = AuthServicesInfo.objects.get(user=instance)
if auth.jabber_username: if auth.jabber_username:
update_jabber_groups.delay(instance.pk) update_jabber_groups.delay(instance.pk)
if auth.teamspeak3_uid: if auth.teamspeak3_uid:

View File

@ -169,7 +169,7 @@ def disable_market():
def deactivate_services(user): def deactivate_services(user):
change = False change = False
logger.debug("Deactivating services for user %s" % user) logger.debug("Deactivating services for user %s" % user)
authinfo = AuthServicesInfo.objects.get_or_create(user=user)[0] authinfo = AuthServicesInfo.objects.get(user=user)
if authinfo.mumble_username and authinfo.mumble_username != "": if authinfo.mumble_username and authinfo.mumble_username != "":
logger.debug("User %s has mumble account %s. Deleting." % (user, authinfo.mumble_username)) logger.debug("User %s has mumble account %s. Deleting." % (user, authinfo.mumble_username))
MumbleManager.delete_user(authinfo.mumble_username) MumbleManager.delete_user(authinfo.mumble_username)
@ -235,7 +235,7 @@ def validate_services(self, user, state):
deactivate_services(user) deactivate_services(user)
return return
logger.debug('Ensuring user %s services are available to state %s' % (user, state)) logger.debug('Ensuring user %s services are available to state %s' % (user, state))
auth = AuthServicesInfo.objects.get_or_create(user=user)[0] auth = AuthServicesInfo.objects.get(user=user)
if auth.mumble_username and not getattr(settings, 'ENABLE_%s_MUMBLE' % setting_string, False): if auth.mumble_username and not getattr(settings, 'ENABLE_%s_MUMBLE' % setting_string, False):
MumbleManager.delete_user(auth.mumble_username) MumbleManager.delete_user(auth.mumble_username)
AuthServicesInfoManager.update_user_mumble_info("", user) AuthServicesInfoManager.update_user_mumble_info("", user)

View File

@ -142,7 +142,7 @@ def jabber_broadcast_view(request):
@members_and_blues() @members_and_blues()
def services_view(request): def services_view(request):
logger.debug("services_view called by user %s" % request.user) logger.debug("services_view called by user %s" % request.user)
auth = AuthServicesInfo.objects.get_or_create(user=request.user)[0] auth = AuthServicesInfo.objects.get(user=request.user)
char = None char = None
if auth.main_char_id: if auth.main_char_id:
try: try:
@ -185,7 +185,7 @@ def superuser_test(user):
@members_and_blues() @members_and_blues()
def activate_forum(request): def activate_forum(request):
logger.debug("activate_forum called by user %s" % request.user) logger.debug("activate_forum called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
# Valid now we get the main characters # Valid now we get the main characters
character = EveManager.get_character_by_id(authinfo.main_char_id) character = EveManager.get_character_by_id(authinfo.main_char_id)
logger.debug("Adding phpbb user for user %s with main character %s" % (request.user, character)) logger.debug("Adding phpbb user for user %s with main character %s" % (request.user, character))
@ -213,7 +213,7 @@ def activate_forum(request):
@members_and_blues() @members_and_blues()
def deactivate_forum(request): def deactivate_forum(request):
logger.debug("deactivate_forum called by user %s" % request.user) logger.debug("deactivate_forum called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = Phpbb3Manager.disable_user(authinfo.forum_username) result = Phpbb3Manager.disable_user(authinfo.forum_username)
# false we failed # false we failed
if result: if result:
@ -230,7 +230,7 @@ def deactivate_forum(request):
@members_and_blues() @members_and_blues()
def reset_forum_password(request): def reset_forum_password(request):
logger.debug("reset_forum_password called by user %s" % request.user) logger.debug("reset_forum_password called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = Phpbb3Manager.update_user_password(authinfo.forum_username, authinfo.main_char_id) result = Phpbb3Manager.update_user_password(authinfo.forum_username, authinfo.main_char_id)
# false we failed # false we failed
if result != "": if result != "":
@ -252,7 +252,7 @@ def reset_forum_password(request):
@members_and_blues() @members_and_blues()
def activate_xenforo_forum(request): def activate_xenforo_forum(request):
logger.debug("activate_xenforo_forum called by user %s" % request.user) logger.debug("activate_xenforo_forum called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
character = EveManager.get_character_by_id(authinfo.main_char_id) character = EveManager.get_character_by_id(authinfo.main_char_id)
logger.debug("Adding XenForo user for user %s with main character %s" % (request.user, character)) logger.debug("Adding XenForo user for user %s with main character %s" % (request.user, character))
result = XenForoManager.add_user(character.character_name, request.user.email) result = XenForoManager.add_user(character.character_name, request.user.email)
@ -278,7 +278,7 @@ def activate_xenforo_forum(request):
@members_and_blues() @members_and_blues()
def deactivate_xenforo_forum(request): def deactivate_xenforo_forum(request):
logger.debug("deactivate_xenforo_forum called by user %s" % request.user) logger.debug("deactivate_xenforo_forum called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = XenForoManager.disable_user(authinfo.xenforo_username) result = XenForoManager.disable_user(authinfo.xenforo_username)
if result.status_code == 200: if result.status_code == 200:
AuthServicesInfoManager.update_user_xenforo_info("", request.user) AuthServicesInfoManager.update_user_xenforo_info("", request.user)
@ -293,7 +293,7 @@ def deactivate_xenforo_forum(request):
@members_and_blues() @members_and_blues()
def reset_xenforo_password(request): def reset_xenforo_password(request):
logger.debug("reset_xenforo_password called by user %s" % request.user) logger.debug("reset_xenforo_password called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = XenForoManager.reset_password(authinfo.xenforo_username) result = XenForoManager.reset_password(authinfo.xenforo_username)
# Based on XenAPI's response codes # Based on XenAPI's response codes
if result['response']['status_code'] == 200: if result['response']['status_code'] == 200:
@ -322,7 +322,7 @@ def set_xenforo_password(request):
if form.is_valid(): if form.is_valid():
password = form.cleaned_data['password'] password = form.cleaned_data['password']
logger.debug("Form contains password of length %s" % len(password)) logger.debug("Form contains password of length %s" % len(password))
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = XenForoManager.update_user_password(authinfo.xenforo_username, password) result = XenForoManager.update_user_password(authinfo.xenforo_username, password)
if result['response']['status_code'] == 200: if result['response']['status_code'] == 200:
logger.info("Successfully reset XenForo password for user %s" % request.user) logger.info("Successfully reset XenForo password for user %s" % request.user)
@ -344,7 +344,7 @@ def set_xenforo_password(request):
@members_and_blues() @members_and_blues()
def activate_ipboard_forum(request): def activate_ipboard_forum(request):
logger.debug("activate_ipboard_forum called by user %s" % request.user) logger.debug("activate_ipboard_forum called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
# Valid now we get the main characters # Valid now we get the main characters
character = EveManager.get_character_by_id(authinfo.main_char_id) character = EveManager.get_character_by_id(authinfo.main_char_id)
logger.debug("Adding ipboard user for user %s with main character %s" % (request.user, character)) logger.debug("Adding ipboard user for user %s with main character %s" % (request.user, character))
@ -371,7 +371,7 @@ def activate_ipboard_forum(request):
@members_and_blues() @members_and_blues()
def deactivate_ipboard_forum(request): def deactivate_ipboard_forum(request):
logger.debug("deactivate_ipboard_forum called by user %s" % request.user) logger.debug("deactivate_ipboard_forum called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = IPBoardManager.disable_user(authinfo.ipboard_username) result = IPBoardManager.disable_user(authinfo.ipboard_username)
# false we failed # false we failed
if result: if result:
@ -388,7 +388,7 @@ def deactivate_ipboard_forum(request):
@members_and_blues() @members_and_blues()
def reset_ipboard_password(request): def reset_ipboard_password(request):
logger.debug("reset_ipboard_password called by user %s" % request.user) logger.debug("reset_ipboard_password called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = IPBoardManager.update_user_password(authinfo.ipboard_username, request.user.email) result = IPBoardManager.update_user_password(authinfo.ipboard_username, request.user.email)
if result != "": if result != "":
logger.info("Successfully reset ipboard password for user %s" % request.user) logger.info("Successfully reset ipboard password for user %s" % request.user)
@ -409,7 +409,7 @@ def reset_ipboard_password(request):
@members_and_blues() @members_and_blues()
def activate_jabber(request): def activate_jabber(request):
logger.debug("activate_jabber called by user %s" % request.user) logger.debug("activate_jabber called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
character = EveManager.get_character_by_id(authinfo.main_char_id) character = EveManager.get_character_by_id(authinfo.main_char_id)
logger.debug("Adding jabber user for user %s with main character %s" % (request.user, character)) logger.debug("Adding jabber user for user %s with main character %s" % (request.user, character))
info = OpenfireManager.add_user(character.character_name) info = OpenfireManager.add_user(character.character_name)
@ -436,7 +436,7 @@ def activate_jabber(request):
@members_and_blues() @members_and_blues()
def deactivate_jabber(request): def deactivate_jabber(request):
logger.debug("deactivate_jabber called by user %s" % request.user) logger.debug("deactivate_jabber called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = OpenfireManager.delete_user(authinfo.jabber_username) result = OpenfireManager.delete_user(authinfo.jabber_username)
# If our username is blank means we failed # If our username is blank means we failed
if result: if result:
@ -453,7 +453,7 @@ def deactivate_jabber(request):
@members_and_blues() @members_and_blues()
def reset_jabber_password(request): def reset_jabber_password(request):
logger.debug("reset_jabber_password called by user %s" % request.user) logger.debug("reset_jabber_password called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = OpenfireManager.update_user_pass(authinfo.jabber_username) result = OpenfireManager.update_user_pass(authinfo.jabber_username)
# If our username is blank means we failed # If our username is blank means we failed
if result != "": if result != "":
@ -476,7 +476,7 @@ def reset_jabber_password(request):
@members_and_blues() @members_and_blues()
def activate_mumble(request): def activate_mumble(request):
logger.debug("activate_mumble called by user %s" % request.user) logger.debug("activate_mumble called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
character = EveManager.get_character_by_id(authinfo.main_char_id) character = EveManager.get_character_by_id(authinfo.main_char_id)
ticker = character.corporation_ticker ticker = character.corporation_ticker
@ -513,7 +513,7 @@ def activate_mumble(request):
@members_and_blues() @members_and_blues()
def deactivate_mumble(request): def deactivate_mumble(request):
logger.debug("deactivate_mumble called by user %s" % request.user) logger.debug("deactivate_mumble called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
# if we successfully remove the user or the user is already removed # if we successfully remove the user or the user is already removed
if MumbleManager.delete_user(authinfo.mumble_username) or not MumbleManager.user_exists(authinfo.mumble_username): if MumbleManager.delete_user(authinfo.mumble_username) or not MumbleManager.user_exists(authinfo.mumble_username):
AuthServicesInfoManager.update_user_mumble_info("", request.user) AuthServicesInfoManager.update_user_mumble_info("", request.user)
@ -529,7 +529,7 @@ def deactivate_mumble(request):
@members_and_blues() @members_and_blues()
def reset_mumble_password(request): def reset_mumble_password(request):
logger.debug("reset_mumble_password called by user %s" % request.user) logger.debug("reset_mumble_password called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = MumbleManager.update_user_password(authinfo.mumble_username) result = MumbleManager.update_user_password(authinfo.mumble_username)
# if blank we failed # if blank we failed
@ -552,7 +552,7 @@ def reset_mumble_password(request):
@members_and_blues() @members_and_blues()
def activate_teamspeak3(request): def activate_teamspeak3(request):
logger.debug("activate_teamspeak3 called by user %s" % request.user) logger.debug("activate_teamspeak3 called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
character = EveManager.get_character_by_id(authinfo.main_char_id) character = EveManager.get_character_by_id(authinfo.main_char_id)
ticker = character.corporation_ticker ticker = character.corporation_ticker
@ -583,7 +583,7 @@ def activate_teamspeak3(request):
@members_and_blues() @members_and_blues()
def verify_teamspeak3(request): def verify_teamspeak3(request):
logger.debug("verify_teamspeak3 called by user %s" % request.user) logger.debug("verify_teamspeak3 called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
if not authinfo.teamspeak3_uid: if not authinfo.teamspeak3_uid:
logger.warn("Unable to validate user %s teamspeak: no teamspeak data" % request.user) logger.warn("Unable to validate user %s teamspeak: no teamspeak data" % request.user)
return redirect("auth_services") return redirect("auth_services")
@ -606,7 +606,7 @@ def verify_teamspeak3(request):
@members_and_blues() @members_and_blues()
def deactivate_teamspeak3(request): def deactivate_teamspeak3(request):
logger.debug("deactivate_teamspeak3 called by user %s" % request.user) logger.debug("deactivate_teamspeak3 called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = Teamspeak3Manager.delete_user(authinfo.teamspeak3_uid) result = Teamspeak3Manager.delete_user(authinfo.teamspeak3_uid)
# if false we failed # if false we failed
@ -624,7 +624,7 @@ def deactivate_teamspeak3(request):
@members_and_blues() @members_and_blues()
def reset_teamspeak3_perm(request): def reset_teamspeak3_perm(request):
logger.debug("reset_teamspeak3_perm called by user %s" % request.user) logger.debug("reset_teamspeak3_perm called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
character = EveManager.get_character_by_id(authinfo.main_char_id) character = EveManager.get_character_by_id(authinfo.main_char_id)
logger.debug("Deleting TS3 user for user %s" % request.user) logger.debug("Deleting TS3 user for user %s" % request.user)
Teamspeak3Manager.delete_user(authinfo.teamspeak3_uid) Teamspeak3Manager.delete_user(authinfo.teamspeak3_uid)
@ -656,7 +656,7 @@ def reset_teamspeak3_perm(request):
@members_and_blues() @members_and_blues()
def deactivate_discord(request): def deactivate_discord(request):
logger.debug("deactivate_discord called by user %s" % request.user) logger.debug("deactivate_discord called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = DiscordOAuthManager.delete_user(authinfo.discord_uid) result = DiscordOAuthManager.delete_user(authinfo.discord_uid)
if result: if result:
AuthServicesInfoManager.update_user_discord_info("", request.user) AuthServicesInfoManager.update_user_discord_info("", request.user)
@ -672,7 +672,7 @@ def deactivate_discord(request):
@members_and_blues() @members_and_blues()
def reset_discord(request): def reset_discord(request):
logger.debug("reset_discord called by user %s" % request.user) logger.debug("reset_discord called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = DiscordOAuthManager.delete_user(authinfo.discord_uid) result = DiscordOAuthManager.delete_user(authinfo.discord_uid)
if result: if result:
AuthServicesInfoManager.update_user_discord_info("", request.user) AuthServicesInfoManager.update_user_discord_info("", request.user)
@ -729,7 +729,7 @@ def set_forum_password(request):
if form.is_valid(): if form.is_valid():
password = form.cleaned_data['password'] password = form.cleaned_data['password']
logger.debug("Form contains password of length %s" % len(password)) logger.debug("Form contains password of length %s" % len(password))
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = Phpbb3Manager.update_user_password(authinfo.forum_username, authinfo.main_char_id, result = Phpbb3Manager.update_user_password(authinfo.forum_username, authinfo.main_char_id,
password=password) password=password)
if result != "": if result != "":
@ -759,7 +759,7 @@ def set_mumble_password(request):
if form.is_valid(): if form.is_valid():
password = form.cleaned_data['password'] password = form.cleaned_data['password']
logger.debug("Form contains password of length %s" % len(password)) logger.debug("Form contains password of length %s" % len(password))
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = MumbleManager.update_user_password(authinfo.mumble_username, password=password) result = MumbleManager.update_user_password(authinfo.mumble_username, password=password)
if result != "": if result != "":
logger.info("Successfully reset forum password for user %s" % request.user) logger.info("Successfully reset forum password for user %s" % request.user)
@ -788,7 +788,7 @@ def set_jabber_password(request):
if form.is_valid(): if form.is_valid():
password = form.cleaned_data['password'] password = form.cleaned_data['password']
logger.debug("Form contains password of length %s" % len(password)) logger.debug("Form contains password of length %s" % len(password))
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = OpenfireManager.update_user_pass(authinfo.jabber_username, password=password) result = OpenfireManager.update_user_pass(authinfo.jabber_username, password=password)
if result != "": if result != "":
logger.info("Successfully set jabber password for user %s" % request.user) logger.info("Successfully set jabber password for user %s" % request.user)
@ -818,7 +818,7 @@ def set_ipboard_password(request):
if form.is_valid(): if form.is_valid():
password = form.cleaned_data['password'] password = form.cleaned_data['password']
logger.debug("Form contains password of length %s" % len(password)) logger.debug("Form contains password of length %s" % len(password))
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = IPBoardManager.update_user_password(authinfo.ipboard_username, request.user.email, result = IPBoardManager.update_user_password(authinfo.ipboard_username, request.user.email,
plain_password=password) plain_password=password)
if result != "": if result != "":
@ -841,7 +841,7 @@ def set_ipboard_password(request):
@members_and_blues() @members_and_blues()
def activate_ips4(request): def activate_ips4(request):
logger.debug("activate_ips4 called by user %s" % request.user) logger.debug("activate_ips4 called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
# Valid now we get the main characters # Valid now we get the main characters
character = EveManager.get_character_by_id(authinfo.main_char_id) character = EveManager.get_character_by_id(authinfo.main_char_id)
logger.debug("Adding IPS4 user for user %s with main character %s" % (request.user, character)) logger.debug("Adding IPS4 user for user %s with main character %s" % (request.user, character))
@ -869,7 +869,7 @@ def activate_ips4(request):
@members_and_blues() @members_and_blues()
def reset_ips4_password(request): def reset_ips4_password(request):
logger.debug("reset_ips4_password called by user %s" % request.user) logger.debug("reset_ips4_password called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = Ips4Manager.update_user_password(authinfo.ips4_username) result = Ips4Manager.update_user_password(authinfo.ips4_username)
# false we failed # false we failed
if result != "": if result != "":
@ -898,7 +898,7 @@ def set_ips4_password(request):
if form.is_valid(): if form.is_valid():
password = form.cleaned_data['password'] password = form.cleaned_data['password']
logger.debug("Form contains password of length %s" % len(password)) logger.debug("Form contains password of length %s" % len(password))
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = Ips4Manager.update_custom_password(authinfo.ips4_username, plain_password=password) result = Ips4Manager.update_custom_password(authinfo.ips4_username, plain_password=password)
if result != "": if result != "":
logger.info("Successfully set IPS4 password for user %s" % request.user) logger.info("Successfully set IPS4 password for user %s" % request.user)
@ -920,7 +920,7 @@ def set_ips4_password(request):
@members_and_blues() @members_and_blues()
def deactivate_ips4(request): def deactivate_ips4(request):
logger.debug("deactivate_ips4 called by user %s" % request.user) logger.debug("deactivate_ips4 called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = Ips4Manager.delete_user(authinfo.ips4_id) result = Ips4Manager.delete_user(authinfo.ips4_id)
if result != "": if result != "":
AuthServicesInfoManager.update_user_ips4_info("", "", request.user) AuthServicesInfoManager.update_user_ips4_info("", "", request.user)
@ -936,7 +936,7 @@ def deactivate_ips4(request):
@members_and_blues() @members_and_blues()
def activate_smf(request): def activate_smf(request):
logger.debug("activate_smf called by user %s" % request.user) logger.debug("activate_smf called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
# Valid now we get the main characters # Valid now we get the main characters
character = EveManager.get_character_by_id(authinfo.main_char_id) character = EveManager.get_character_by_id(authinfo.main_char_id)
logger.debug("Adding smf user for user %s with main character %s" % (request.user, character)) logger.debug("Adding smf user for user %s with main character %s" % (request.user, character))
@ -964,7 +964,7 @@ def activate_smf(request):
@members_and_blues() @members_and_blues()
def deactivate_smf(request): def deactivate_smf(request):
logger.debug("deactivate_smf called by user %s" % request.user) logger.debug("deactivate_smf called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = smfManager.disable_user(authinfo.smf_username) result = smfManager.disable_user(authinfo.smf_username)
# false we failed # false we failed
if result: if result:
@ -981,7 +981,7 @@ def deactivate_smf(request):
@members_and_blues() @members_and_blues()
def reset_smf_password(request): def reset_smf_password(request):
logger.debug("reset_smf_password called by user %s" % request.user) logger.debug("reset_smf_password called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = smfManager.update_user_password(authinfo.smf_username, authinfo.main_char_id) result = smfManager.update_user_password(authinfo.smf_username, authinfo.main_char_id)
# false we failed # false we failed
if result != "": if result != "":
@ -1010,7 +1010,7 @@ def set_smf_password(request):
if form.is_valid(): if form.is_valid():
password = form.cleaned_data['password'] password = form.cleaned_data['password']
logger.debug("Form contains password of length %s" % len(password)) logger.debug("Form contains password of length %s" % len(password))
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = smfManager.update_user_password(authinfo.smf_username, authinfo.main_char_id, password=password) result = smfManager.update_user_password(authinfo.smf_username, authinfo.main_char_id, password=password)
if result != "": if result != "":
logger.info("Successfully set smf password for user %s" % request.user) logger.info("Successfully set smf password for user %s" % request.user)
@ -1032,7 +1032,7 @@ def set_smf_password(request):
@members_and_blues() @members_and_blues()
def activate_market(request): def activate_market(request):
logger.debug("activate_market called by user %s" % request.user) logger.debug("activate_market called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
# Valid now we get the main characters # Valid now we get the main characters
character = EveManager.get_character_by_id(authinfo.main_char_id) character = EveManager.get_character_by_id(authinfo.main_char_id)
logger.debug("Adding market user for user %s with main character %s" % (request.user, character)) logger.debug("Adding market user for user %s with main character %s" % (request.user, character))
@ -1060,7 +1060,7 @@ def activate_market(request):
@members_and_blues() @members_and_blues()
def deactivate_market(request): def deactivate_market(request):
logger.debug("deactivate_market called by user %s" % request.user) logger.debug("deactivate_market called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = marketManager.disable_user(authinfo.market_username) result = marketManager.disable_user(authinfo.market_username)
# false we failed # false we failed
if result: if result:
@ -1077,7 +1077,7 @@ def deactivate_market(request):
@members_and_blues() @members_and_blues()
def reset_market_password(request): def reset_market_password(request):
logger.debug("reset_market_password called by user %s" % request.user) logger.debug("reset_market_password called by user %s" % request.user)
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = marketManager.update_user_password(authinfo.market_username) result = marketManager.update_user_password(authinfo.market_username)
# false we failed # false we failed
if result != "": if result != "":
@ -1106,7 +1106,7 @@ def set_market_password(request):
if form.is_valid(): if form.is_valid():
password = form.cleaned_data['password'] password = form.cleaned_data['password']
logger.debug("Form contains password of length %s" % len(password)) logger.debug("Form contains password of length %s" % len(password))
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
result = marketManager.update_custom_password(authinfo.market_username, password) result = marketManager.update_custom_password(authinfo.market_username, password)
if result != "": if result != "":
logger.info("Successfully reset market password for user %s" % request.user) logger.info("Successfully reset market password for user %s" % request.user)
@ -1129,7 +1129,7 @@ def discourse_sso(request):
## Check if user has access ## Check if user has access
auth, c = AuthServicesInfo.objects.get_or_create(user=request.user) auth = AuthServicesInfo.objects.get(user=request.user)
if not request.user.is_superuser: if not request.user.is_superuser:
if not settings.ENABLE_AUTH_DISCOURSE and auth.state == MEMBER_STATE: if not settings.ENABLE_AUTH_DISCOURSE and auth.state == MEMBER_STATE:
messages.error(request, 'Members are not authorized to access Discourse.') messages.error(request, 'Members are not authorized to access Discourse.')

View File

@ -104,7 +104,7 @@ def srp_fleet_add_view(request):
form = SrpFleetMainForm(request.POST) form = SrpFleetMainForm(request.POST)
logger.debug("Request type POST contains form valid: %s" % form.is_valid()) logger.debug("Request type POST contains form valid: %s" % form.is_valid())
if form.is_valid(): if form.is_valid():
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
character = EveManager.get_character_by_id(authinfo.main_char_id) character = EveManager.get_character_by_id(authinfo.main_char_id)
srp_fleet_main = SrpFleetMain() srp_fleet_main = SrpFleetMain()
@ -231,7 +231,7 @@ def srp_request_view(request, fleet_srp):
logger.debug("Request type POST contains form valid: %s" % form.is_valid()) logger.debug("Request type POST contains form valid: %s" % form.is_valid())
if form.is_valid(): if form.is_valid():
authinfo = AuthServicesInfo.objects.get_or_create(user=request.user)[0] authinfo = AuthServicesInfo.objects.get(user=request.user)
character = EveManager.get_character_by_id(authinfo.main_char_id) character = EveManager.get_character_by_id(authinfo.main_char_id)
srp_fleet_main = SrpFleetMain.objects.get(fleet_srp_code=fleet_srp) srp_fleet_main = SrpFleetMain.objects.get(fleet_srp_code=fleet_srp)
post_time = timezone.now() post_time = timezone.now()

View File

@ -20,7 +20,7 @@ logger = logging.getLogger(__name__)
def timer_util_test(user): def timer_util_test(user):
return AuthServicesInfo.objects.get_or_create(user=user)[0].state in [BLUE_STATE, MEMBER_STATE] return AuthServicesInfo.objects.get(user=user).state in [BLUE_STATE, MEMBER_STATE]
@login_required @login_required
@ -28,7 +28,7 @@ def timer_util_test(user):
@permission_required('auth.timer_view') @permission_required('auth.timer_view')
def timer_view(request): def timer_view(request):
logger.debug("timer_view called by user %s" % request.user) logger.debug("timer_view called by user %s" % request.user)
auth_info = AuthServicesInfo.objects.get_or_create(user=request.user)[0] auth_info = AuthServicesInfo.objects.get(user=request.user)
char = EveManager.get_character_by_id(auth_info.main_char_id) char = EveManager.get_character_by_id(auth_info.main_char_id)
if char: if char:
corp = EveManager.get_corporation_info_by_id(char.corporation_id) corp = EveManager.get_corporation_info_by_id(char.corporation_id)
@ -64,7 +64,7 @@ def add_timer_view(request):
logger.debug("Request type POST contains form valid: %s" % form.is_valid()) logger.debug("Request type POST contains form valid: %s" % form.is_valid())
if form.is_valid(): if form.is_valid():
# Get character # Get character
auth_info = AuthServicesInfo.objects.get_or_create(user=request.user)[0] auth_info = AuthServicesInfo.objects.get(user=request.user)
character = EveManager.get_character_by_id(auth_info.main_char_id) character = EveManager.get_character_by_id(auth_info.main_char_id)
corporation = EveManager.get_corporation_info_by_id(character.corporation_id) corporation = EveManager.get_corporation_info_by_id(character.corporation_id)
logger.debug( logger.debug(
@ -127,7 +127,7 @@ def edit_timer(request, timer_id):
form = TimerForm(request.POST) form = TimerForm(request.POST)
logger.debug("Received POST request containing updated timer form, is valid: %s" % form.is_valid()) logger.debug("Received POST request containing updated timer form, is valid: %s" % form.is_valid())
if form.is_valid(): if form.is_valid():
auth_info = AuthServicesInfo.objects.get_or_create(user=request.user)[0] auth_info = AuthServicesInfo.objects.get(user=request.user)
character = EveManager.get_character_by_id(auth_info.main_char_id) character = EveManager.get_character_by_id(auth_info.main_char_id)
corporation = EveManager.get_corporation_info_by_id(character.corporation_id) corporation = EveManager.get_corporation_info_by_id(character.corporation_id)
logger.debug( logger.debug(