Esempio n. 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'),
        }
Esempio n. 2
0
def register(request):
    message = None
    form = RegistrationForm()

    if request.method == 'POST' and request.POST['action_type'] == 'login':
        username = slughifi(request.POST['username'])
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
                response = HttpResponseRedirect(reverse('home'))
                # get_invite_cookie(request, response, user)
                return response
            else:
                message = _("Account inactive.")
        else:
            message = _("Entered nickname and password combination is not correct")

    if request.method == 'POST' and request.POST['action_type'] == 'register':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            profile = UserProfile()
            profile.user = User.objects.create_user(form.cleaned_data['username'], form.cleaned_data['email'],
                                                    form.cleaned_data['password1'])
            profile.username = form.cleaned_data['username']
            profile.add_log(log_type='register', log_type_id=profile.user.id, log='from web',
                            ip=request.META.get('REMOTE_ADDR'))

            # create city
            from crims.city.models import CityMap, Sector

            city = CityMap()
            city.owner_id = profile.user.id
            city.orig_owner_id = profile.user.id
            city.name = profile.username
            city.population = settings.DEFAULT_CITY_POPULATION
            city.sector, city.position = Sector.objects.next_cords()
            city.save()

            profile.default_city_id = city.id
            profile.active_city_id = city.id
            profile.save()

            # profile.user.is_active = False
            # profile.user.save()

            # refresh city task
            from crims.common.models import Task

            task = Task()
            task.source = 'city'
            task.user_id = profile.user.id
            task.task = city.id
            task.save()

            user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password1'])
            login(request, user)

            logging.info("%s registered on the web" % form.cleaned_data['username'])

            response = HttpResponseRedirect(reverse('home'))
            # get_invite_cookie(request, response, profile)
            return response

        # extra actions
        # message="Account created. Check your email and wait for link to activate your account."

    return render_to_response('main/preview.html', {
        'form': form,
        'message': message,
    }, context_instance=RequestContext(request))