Ejemplo n.º 1
0
def process(request):
    if request.method == 'POST':
        rf = RegisterForm(request.POST)
        if rf.is_valid():
            account = rf.save(commit=False)
            account.password = sha1(rf.cleaned_data['login'].encode('utf-8').lower()+rf.cleaned_data['password'].encode('utf-8')).hexdigest()

            account.id = None
            account.save()
           
            rc = RegisterConfirmation()
            rc.account = account
            rc.key = sha1(str(datetime.now()) + 'ourwearyeyesstillstraytothehorizon').hexdigest()
            while True:     # Make it so key is truly unique
                try:
                    rc.save()
                except IntegrityError:
                    rc.key = sha1(rc.key + 'theteaset' + str(datetime.now())).hexdigest()
                else:
                    break

            resp = render_to_string('register/register/mail.txt', {'key':rc.key,
                                                                   'password':rf.cleaned_data['password'],
                                                                   'login':account.login,
                                                                   'empire':account.empire})
            send(account.email, u'Bellum - aktywacja konta', unicode(resp, 'UTF-8'))

            return render_to_response('register/register/success.html', {})
       
    try:
        rf
    except:
        rf = RegisterForm()
   
    return render_to_response('register/register/register.html', {'form':rf, 'sup':sup})
Ejemplo n.º 2
0
def process(request):
    if request.method == 'POST':
        rf = RemindForm(request.POST)
        if rf.is_valid():
            acc = Account.objects.get(email=rf.cleaned_data['email'])
            if acc.passwordremindtoken_set.count() > 0:
                acc.passwordremindtoken_set.all().delete()
                didRemovePrevious = True
            else:
                didRemovePrevious = False
            prt = PasswordRemindToken(account=acc)

            prt.key = sha1(str(datetime.now()) + 'thelightwasbrighter').hexdigest()
            while True:     # Make it so key is truly unique
                try:
                    prt.save()      # chance is 1:2^160 that key repeats, but the chance is
                except IntegrityError:
                    prt.key = sha1(prt.key + 'hellocharlie' + str(datetime.now())).hexdigest()
                else:
                    break
            try:
                resp = render_to_string('register/passremind/mail.txt', {'key':prt.key,
                                                                         'login':acc.login,
                                                                         'accname':acc.empire,
                                                                         'newpass':prt.newpassword})
                send(acc.email, u'Bellum - przypomnienie hasła', unicode(resp, 'UTF-8'))
            except Exception, e:
                # something has FEHLED
                prt.delete()
                raise e
            return render_to_response('register/passremind/success.html', {'key':prt.key,
                                                            'newpassword':prt.newpassword,
                                                            'didRemovePrevious':didRemovePrevious})
Ejemplo n.º 3
0
def p_secm(request, x, y):
    '''Generate sector map'''
    planets = Planet.objects.filter(        # might even not exist. We don't care.
                            Q(x__gt=x-QRADIUS) & Q(x__lt=x+QRADIUS) &
                            Q(y__gt=y-QRADIUS) & Q(y__lt=y+QRADIUS)
                                 )
    return render_to_string('space/regionmap/generator/sector.html', {'x':x, 'y':y, 'planets':planets})
Ejemplo n.º 4
0
def p_commands(request, planet, source, reinforcements=False):
    '''Source is either None(mothership) or a bellum.province.models.Province instance.
    If reinforcements, then severely limit commandeering capability'''
    return render_to_string('space/troopmove/generator/commands.html', {'display_mother':source!=None,
                                                                        'source':source,
                                                                        'mother':getCurrentMother(request),
                                                                        'planet':planet,
                                                                        'limit_comandeering':reinforcements})
Ejemplo n.º 5
0
def retr(request, pvmsg_id):        # retrieve a message/report
    acc = getAccount(request)

    try:
        pmsg = LCDMessage.objects.get(id=pvmsg_id)
    except ObjectDoesNotExist:
        return HttpResponse(dumps(None))

    if pmsg.recipient != acc: return HttpResponse('NOT YOURS HACKER')
    msg_cont = pmsg.mapRef()           # extract reference - a Report object in this case
    if pmsg.msgtype != LCDMT_PRIVATE:       # this is not a private message, this is a REPORT
        try:
            am = AllianceMembership.objects.get(account=getAccount(request))
        except:
            am = None
        
        if isinstance(msg_cont.data, WarfareReport):
            f = render_to_string('stats/reports/WarfareReport/report.html', {'r':msg_cont.data, 'membership':am})
        if isinstance(msg_cont.data, ScanReportv01):
            f = render_to_string('stats/reports/ScanReportv01/report.html', {'r':msg_cont.data, 'membership':am})
        if isinstance(msg_cont.data, RadarReportv01):
            f = render_to_string('stats/reports/RadarReportv01/report.html', {'r':msg_cont.data, 'membership':am})

        if pmsg.relayed != None:
            rp = (pmsg.id, pmsg.msgtype, f, msg_cont.title, True, pmsg.relayed.id, pmsg.relayed.empire)
        else:
            rp = (pmsg.id, pmsg.msgtype, f, msg_cont.title, False)

    else:           # this is a private message
        rp = (pmsg.id, pmsg.msgtype, escape(msg_cont.text).replace('\n', '<br>'), pmsg.author.id, pmsg.author.empire)
        cacheContactAcc(request, pmsg.author)

    if pmsg.readed == 0:
        pmsg.readed = 1
        pmsg.save()

    return HttpResponse(dumps(rp))
Ejemplo n.º 6
0
def p_plm(request, planet, highlight_preference=None):
    '''Generate planet map
    highlight preference is a province instance'''
    allegiance_tab = {}
    for province in planet.province_set.all():
        # 0 - MINE, 1 - ENEMY, 2 - ALLIED, 3 - NOBODYS
        try:
            province.provintionalpresence
        except:
           allegiance_tab[province.id] = 'gray'
        else:
            if province.provintionalpresence.owner == getAccount(request):
                allegiance_tab[province.id] = 'green'
            elif isAllied(getAccount(request), province.provintionalpresence.owner):
                allegiance_tab[province.id] = 'blue'
            else:
                allegiance_tab[province.id] = 'red'

    x = render_to_string('space/troopmove/generator/pla.html', {'planet':planet,
                                                                'wctg':lambda x: int((x+100.0)*(345.0/200.0)),
                                                                'allegiance_strings':allegiance_tab,
                                                                'highlight_preference':highlight_preference})
    return x
Ejemplo n.º 7
0
def p_garrison_prov_dx(request, garrison, race):
    '''Directly provides with garrison HTML. Unfortunately, by being direct, it is also quite dumb'''
    return render_to_string('space/troopmove/generator/garrison.html', {'garrison':garrison,
                                                                        'race':race})
Ejemplo n.º 8
0
def p_galm(request):
    '''Generate galaxy map'''
    return render_to_string('space/regionmap/generator/galaxy.html', {})
Ejemplo n.º 9
0
def p_regm(request, bx, by):
    '''Generate region map'''
    return render_to_string('space/regionmap/generator/region.html', {'bx':bx, 'by':by})
Ejemplo n.º 10
0
def dx_html(request, prov, mum=None):

    ## Uh, take a note that this still needs to limit displaying provinces we don't have a ship at
    if mum == None:
        mum = getCurrentMother(request)

    mother_evacs = LandarmyMotherPickupOrder.objects.filter(province=prov).filter(mother__owner=getAccount(request))
    outgoing_units = LandarmyProvintionalStrikeOrder.objects.filter(srcprovince=prov)


    try:
        prov.presence
    except ObjectDoesNotExist:
            # MY drops incoming at THIS province
        mother_drops = LandarmyPlanetaryStrikeOrder.objects.filter(province=prov).filter(mother__owner=getAccount(request))
            # MY attacks INCOMING at THIS province
        prov_target = LandarmyProvintionalStrikeOrder.objects.filter(dstprovince=prov).filter(attacker=getAccount(request))

        return render_to_string('space/planetview/generator/unclaimed.html',{'pgo':PrimaryGUIObject(request),
                                                                             'my_land_inbound':prov_target,
                                                                             'my_drop_inbound':mother_drops,
                                                                             'province':prov,
                                                                             'race':getRace(request)})

    if prov.presence.owner != getAccount(request):
            # MY drops incoming at THIS province
        mother_drops = LandarmyPlanetaryStrikeOrder.objects.filter(province=prov).filter(mother__owner=getAccount(request))
            # MY moves INCOMING at THIS province
        prov_target = LandarmyProvintionalStrikeOrder.objects.filter(dstprovince=prov).filter(attacker=getAccount(request))
        try:
            reif = Reinforcement.objects.filter(owner=getAccount(request)).get(presence=prov.presence)
        except:
            return render_to_string('space/planetview/generator/public.html',{'pgo':PrimaryGUIObject(request),
                                                                       'my_land_inbound':prov_target,
                                                                       'my_drop_inbound':mother_drops,
                                                                       'race':getRace(request),
                                                                       'province':prov})
        else:
            return render_to_string('space/planetview/generator/reinforcer.html',{'pgo':PrimaryGUIObject(request),
                                                                       'reinforcement':reif,
                                                                       'my_land_inbound':prov_target,
                                                                       'my_drop_inbound':mother_drops,
                                                                       'province':prov,
                                                                       'race':getRace(request)})


    pbs = prov.presence.getPendingBuilds()
    d = {}
    for b in pbs:
        d[b.slot] = b

    firstclear = None
    costs = {}

    for i in xrange(0, prov.slots):
        otype, olvl = prov.presence.getPair(i)
        if otype == 0:
            if firstclear == None:
                firstclear = i
        else:
            costs[i] = getCosts(prov.presence, getRace(request), olvl, otype)

    gcosts = {}
    canerect = {}
    for i in xrange(1, MPBI+1):
        gcosts[i] = getCosts(prov.presence, getRace(request), 0, i)
        canerect[i] = True

    canerect[1] = (prov.titan_coef > 0)
    canerect[2] = (prov.pluton_coef > 0)
    canerect[3] = (prov.town_coef > 0)

        # ANY drops incoming at THIS province
    drops = LandarmyPlanetaryStrikeOrder.objects.filter(province=prov)
        # MY moves INCOMING at THIS province
    prov_target = LandarmyProvintionalStrikeOrder.objects.filter(dstprovince=prov)
        # MY moves OUTBOUND from THIS province
    outgoing_units = LandarmyProvintionalStrikeOrder.objects.filter(srcprovince=prov)
        # MY evacuations from THIS province
    evacs = LandarmyMotherPickupOrder.objects.filter(province=prov)
    return render_to_string('space/planetview/generator/private.html',{'pgo':PrimaryGUIObject(request),
                                                            'race':getRace(request),
                                                            'costs':costs,
                                                            'gcosts':gcosts,
                                                            'land_inbound':prov_target,
                                                            'drop_inbound':drops,
                                                            'evacs_bound':evacs,
                                                            'land_outbound':outgoing_units,
                                                            'province':prov,
                                                            'builds':d,
                                                            'canerect':canerect,
                                                            'account':getAccount(request),
                                                            'first_slot_clear':firstclear})