Ejemplo n.º 1
0
 def add_task(self, source='engine', task='', comment=''):
     t = Task()
     t.user_id = self.user.user.id
     t.source = source
     t.task = task
     t.comment = comment
     t.save()
Ejemplo 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))