Пример #1
0
    def __init__(self, engine):
        self.engine = engine

        if self.engine.source == 'fb':
            from django.contrib.auth.models import User

            try:
                self.profile = UserProfile.objects.get(fb_id=self.engine.request.facebook.uid)
            except UserProfile.DoesNotExist:
                profile = UserProfile()
                profile.user = User.objects.create_user("fb_%s" % self.engine.request.facebook.uid,
                                                        "*****@*****.**" % self.engine.request.facebook.uid,
                                                        User.objects.make_random_password(length=10,
                                                                                          allowed_chars='abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'))
                profile.username = "******" % self.engine.request.facebook.uid
                profile.fb_id = self.engine.request.facebook.uid
                profile.save()
                self.profile = profile

                # extra actions
                self.profile.add_log(log_type='register', log_type_id=self.profile.user.id, log='from facebook',
                                     ip=self.engine.request.META.get('REMOTE_ADDR'))

        else:
            self.profile = UserProfile.objects.get_by_id(self.engine.request.user.id)
            if self.profile is None:
                from django.contrib.auth import logout

                logout(self.engine.request)

        self.user = self.profile.user

        # username bug workaround
        if self.profile.username == '':
            self.profile.username = self.user.username
            self.profile.save()
            logging.warning('fixed username of %s' % self.user.username)

        self.SKILL = {
            'driving': _('Driving'),
            'shooting': _('Shooting'),
            'stealing': _('Stealing'),
            'security_breaking': _('Security breaking'),
            'negotiating': _('Negotiating'),
            'marketing': _('Marketing'),
            'business': _('Business running'),
            'smuggling': _('Smuggling'),
            'hacking': _('Hacking'),
            'natural_resources': _('Natural resource management'),
        }