]> git.openstreetmap.org Git - osqa.git/blob - forum/authentication/__init__.py
initial import
[osqa.git] / forum / authentication / __init__.py
1 import re
2 import django.dispatch
3 from forum.modules import get_modules_script_classes
4 from forum.authentication.base import AuthenticationConsumer, ConsumerTemplateContext
5
6 class ConsumerAndContext:
7     def __init__(self, id, consumer, context):
8         self.id = id
9         self._consumer = consumer
10
11         context.id = id
12         self.context = context
13
14     @property
15     def consumer(self):
16         return self._consumer()
17
18 consumers = dict([
19             (re.sub('AuthConsumer$', '', name).lower(), cls) for name, cls
20             in get_modules_script_classes('authentication', AuthenticationConsumer).items()
21             if not re.search('AbstractAuthConsumer$', name)
22         ])
23
24 contexts = dict([
25             (re.sub('AuthContext$', '', name).lower(), cls) for name, cls
26             in get_modules_script_classes('authentication', ConsumerTemplateContext).items()
27         ])
28
29 AUTH_PROVIDERS = dict([
30             (name, ConsumerAndContext(name, consumers[name], contexts[name])) for name in consumers.keys()
31             if name in contexts
32         ])
33
34
35 #todo: probably this don't belong here, also this post_stored routine needs a lot of work
36 user_logged_in = django.dispatch.Signal(providing_args=["user", "old_session"])
37 user_updated = django.dispatch.Signal(providing_args=["instance", "updated_by"])
38
39 def post_stored_anonymous_content(user,old_session,**kwargs):
40     from forum.models import AnonymousQuestion, AnonymousAnswer
41     aq_list = AnonymousQuestion.objects.filter(session_key = old_session)
42     aa_list = AnonymousAnswer.objects.filter(session_key = old_session)
43     import settings
44     if settings.EMAIL_VALIDATION == 'on':#add user to the record
45         for aq in aq_list:
46             aq.author = user
47             aq.save()
48         for aa in aa_list:
49             aa.author = user
50             aa.save()
51         #maybe add pending posts message?
52     else: #just publish the questions
53         for aq in aq_list:
54             aq.publish(user)
55         for aa in aa_list:
56             aa.publish(user)
57
58 user_logged_in.connect(post_stored_anonymous_content)