Exemplo n.º 1
0
def security(request, template='security/security.html'):
    char = gtc(request)
    if request.method == 'POST':
        if request.POST.get('type') == 'entry':
            try:
                try:
                    time = make_aware(parse(request.POST.get('time')),
                                      timezone.get_default_timezone())
                except ValueError:
                    raise ValidationError("Invalid time; window not created.")
                except NonExistentTimeError:
                    raise ValidationError(
                        "Go google 'Daylight Saving Time' and try again.")
                if time < now():
                    raise ValidationError("Start time must be in the future.")
                try:
                    location = SecureLocation.objects.get(
                        room=request.POST.get('room').strip())
                except SecureLocation.DoesNotExist:
                    raise ValidationError("No secure location in room %s." %
                                          request.POST.get('room').strip())
                new = EntryWindow.objects.create(
                    location=location,
                    start_time=time,
                    creator=char,
                    person=request.POST.get('person'))
                messages.success(request, "Window created!")
                check_inspiration(request)
            except ValidationError, e:
                messages.error(request, e.messages[0])
        else:
            try:
                try:
                    time = make_aware(parse(request.POST.get('time')),
                                      timezone.get_default_timezone())
                except NonExistentTimeError:
                    raise ValidationError(
                        "Go google 'Daylight Saving Time' and try again.")
                except ValueError:
                    raise ValidationError("Invalid time; window not created.")
                if time < now():
                    raise ValidationError("Start time must be in the future.")
                try:
                    location = SecureLocation.objects.get(
                        room=request.POST.get('room').strip())
                except SecureLocation.DoesNotExist:
                    raise ValidationError("No secure location in room %s." %
                                          request.POST.get('room').strip())
                new = SecurityWindow.objects.create(location=location,
                                                    start_time=time,
                                                    creator=char)
                messages.success(request, "Window created!")
                check_inspiration(request)
            except ValidationError, e:
                messages.error(request, e.messages[0])
Exemplo n.º 2
0
def mail_home(request, template="messaging/mail_home.html"):
    char = gtc(request)
    context = {
        # 'special_mailboxes': Mailbox.objects.filter(public=True, type=0).order_by('name'),
        'char_mailboxes':
        Mailbox.objects.filter(public=True, type=1).order_by('name'),
        'group_mailboxes':
        Mailbox.objects.filter(public=True, type=2).order_by('name'),
        'send_mailboxes':
        Mailbox.objects.filter(
            Q(character=char)
            | Q(line__lineorder__order=1, line__lineorder__character=char)).
        order_by('type'),
        'read_mailboxes':
        Mailbox.objects.filter(
            Q(character=char) | Q(line__lineorder__character=char))
    }
    if request.method == 'POST':
        try:
            context['mail_text'] = request.POST.get('text')
            new_mail = Message()
            new_mail.sender = Mailbox.objects.get(
                code=request.POST.get('from_code'))
            try:
                new_mail.to = Mailbox.objects.get(
                    code=request.POST.get('to_code'))
            except Mailbox.DoesNotExist:
                try:
                    new_mail.to = Mailbox.objects.get(
                        name=request.POST.get('to_name'))
                except Mailbox.DoesNotExist:
                    raise ValidationError("That mailbox doesn't exist.")
            new_mail.text = request.POST.get('text')
            new_mail.subject = request.POST.get('subject')
            new_mail.anon = request.POST.get('anon') == 'on'
            new_mail.save()
            if new_mail.anon:
                check_inspiration(request)
            try:
                subprocess.Popen([
                    'zwrite', '-d', '-c', 'consortium-sekrit-auto', '-m',
                    "Mail from %s to %s\nSubject: %s\n%s" %
                    (new_mail.sender.name, new_mail.to.name, new_mail.subject,
                     new_mail.text.replace('"', "'"))
                ])
            except:
                pass
            messages.success(request, "Sent mail to %s" % new_mail.to.name)
            context['mail_text'] = ''
        except ValidationError, e:
            messages.error(request, e.messages[0])
Exemplo n.º 3
0
def unlock(request, from_hex, to_hex):
    """
    Unlock a node.  Does error checking.
    """
    char = gtc(request)
    from_node = Node.by_hex(from_hex)
    to_node = Node.by_hex(to_hex)
    print from_hex, HOME_NODE
    if not (char.has_node(from_node) or int(from_hex) == HOME_NODE):
        messages.error(request,
            _("You didn't have node %s unlocked...?") % from_hex)
        return home(request)

    if char.has_node(to_node):
        messages.warning(request,
            _("You already had node %s unlocked!") % to_hex)
        return redirect(node, to_hex)

    if char.points < 1:
        messages.error(request, _("You don't have any Market points!"))
        return redirect(node, from_hex)

    # Error checking done

    char.points -= 1
    char.save()

    char.unlock_node_final(to_node)
    event = NodeEvent.objects.create(
        where=from_node,
        who=char,
        day=GameDay.get_day(),
        who_disguised=char.is_disguised,
        type=EVENT_UNLOCK_2
    )

    char.revert_disguise(request)
    check_inspiration(request)

    messages.success(request,
        _("%(from_node_name)s introduces you to %(to_node_name)s." %
        {"from_node_name": from_node.name,
         "to_node_name": to_node.name}))

    return redirect(node, to_hex)
Exemplo n.º 4
0
def security(request, template='security/security.html'):
    char = gtc(request)
    if request.method == 'POST':
        if request.POST.get('type') == 'entry':
            try:
                try:
                    time = make_aware(parse(request.POST.get('time')), timezone.get_default_timezone())
                except ValueError:
                    raise ValidationError("Invalid time; window not created.")
                except NonExistentTimeError:
                    raise ValidationError("Go google 'Daylight Saving Time' and try again.")
                if time < now():
                    raise ValidationError("Start time must be in the future.")
                try:
                    location = SecureLocation.objects.get(room=request.POST.get('room').strip())
                except SecureLocation.DoesNotExist:
                    raise ValidationError("No secure location in room %s." % request.POST.get('room').strip())
                new = EntryWindow.objects.create(location=location, start_time=time, creator=char, person=request.POST.get('person'))
                messages.success(request, "Window created!")
                check_inspiration(request)
            except ValidationError, e:
                messages.error(request, e.messages[0])
        else:
            try:
                try:
                    time = make_aware(parse(request.POST.get('time')), timezone.get_default_timezone())
                except NonExistentTimeError:
                    raise ValidationError("Go google 'Daylight Saving Time' and try again.")
                except ValueError:
                    raise ValidationError("Invalid time; window not created.")
                if time < now():
                    raise ValidationError("Start time must be in the future.")
                try:
                    location = SecureLocation.objects.get(room=request.POST.get('room').strip())
                except SecureLocation.DoesNotExist:
                    raise ValidationError("No secure location in room %s." % request.POST.get('room').strip())
                new = SecurityWindow.objects.create(location=location, start_time=time, creator=char)
                messages.success(request, "Window created!")
                check_inspiration(request)
            except ValidationError, e:
                messages.error(request, e.messages[0])
Exemplo n.º 5
0
def mail_home(request, template="messaging/mail_home.html"):
    char = gtc(request)
    context = {
        # 'special_mailboxes': Mailbox.objects.filter(public=True, type=0).order_by('name'),
        'char_mailboxes': Mailbox.objects.filter(public=True, type=1).order_by('name'),
        'group_mailboxes': Mailbox.objects.filter(public=True, type=2).order_by('name'),
        'send_mailboxes': Mailbox.objects.filter(Q(character=char) | Q(line__lineorder__order=1, line__lineorder__character=char)).order_by('type'),
        'read_mailboxes': Mailbox.objects.filter(Q(character=char) | Q(line__lineorder__character=char))

    }
    if request.method == 'POST':
        try:
            context['mail_text'] = request.POST.get('text')
            new_mail = Message()
            new_mail.sender = Mailbox.objects.get(code=request.POST.get('from_code'))
            try:
                new_mail.to = Mailbox.objects.get(code=request.POST.get('to_code'))
            except Mailbox.DoesNotExist:
                try:
                    new_mail.to = Mailbox.objects.get(name=request.POST.get('to_name'))
                except Mailbox.DoesNotExist:
                    raise ValidationError("That mailbox doesn't exist.")
            new_mail.text = request.POST.get('text')
            new_mail.subject = request.POST.get('subject')
            new_mail.anon = request.POST.get('anon') == 'on'
            new_mail.save()
            if new_mail.anon:
                check_inspiration(request)
            try:
                subprocess.Popen(['zwrite', '-d', '-c', 'consortium-sekrit-auto', '-m', "Mail from %s to %s\nSubject: %s\n%s" % (new_mail.sender.name,
                new_mail.to.name, new_mail.subject, new_mail.text.replace('"', "'"))])
            except:
                pass
            messages.success(request, "Sent mail to %s" % new_mail.to.name)
            context['mail_text'] = ''
        except ValidationError, e:
            messages.error(request, e.messages[0])