Exemplo n.º 1
0
def ticket_submit(request):
    user = request.user
    if request.method == "POST":
        form = TicketForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            thread = TicketThread()
            thread.user = user
            thread.subject = cd['subject']
            thread.save()
            ticket = Ticket()
            ticket.thread = thread
            ticket.subject = thread.subject
            ticket.content = cd['content']
            ticket.sender = user.username
            ticket.save()
            send_ticket_mail(user,ticket)
            return HttpResponseRedirect("/home/ticket/")
        else:
            c = {"form":form,
                 "user":user,
                 "message_count":message_count(request.user),
                 "ticket_count":ticket_count(request.user),
                 "active":"ticket"}
            c.update(csrf(request))
            return render_to_response("ticket_submit.html",c)
    else:
        form = TicketForm()
        c = {"form":form,
             "user":user,
             "message_count":message_count(request.user),
             "ticket_count":ticket_count(request.user),
             "active":"ticket"}
        c.update(csrf(request))
        return render_to_response("ticket_submit.html",c)
Exemplo n.º 2
0
def change_password(request, username):
    if request.method == "POST":
        form = ChangePasswdForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            user = request.user
            old_password = cd['old_password']
            new_password = cd['new_password']
            try:
                account = Account.objects.get(user=user, username=username)
                if account.password == old_password:
                    account.password = new_password
                    account.save()
                    return HttpResponseRedirect("/home/account/")
                else:
                    form = ChangePasswdForm()
                    form.errors['old_password'] = u"密码错误!"
                    c = {
                        'form': form,
                        'message_count': message_count(request.user),
                        'ticket_count': ticket_count(request.user),
                        'active': 'account',
                        'user': request.user
                    }
                    c.update(csrf(request))
                    return render_to_response("change_password.html", c)
            except Account.DoesNotExist:
                form = ChangePasswdForm()
                form.errors['old_password'] = u"帐号不存在!"
                c = {
                    'form': form,
                    'message_count': message_count(request.user),
                    'ticket_count': ticket_count(request.user),
                    'active': 'account',
                    'user': request.user
                }
                c.update(csrf(request))
                return render_to_response("change_password.html", c)
        else:
            c = {
                'form': form,
                'message_count': message_count(request.user),
                'ticket_count': ticket_count(request.user),
                'active': 'account',
                'user': request.user
            }
            c.update(csrf(request))
            return render_to_response("change_password.html", c)
    else:
        form = ChangePasswdForm()
        c = {
            'form': form,
            'message_count': message_count(request.user),
            'ticket_count': ticket_count(request.user),
            'active': 'account',
            'user': request.user
        }
        c.update(csrf(request))
        return render_to_response("change_password.html", c)
Exemplo n.º 3
0
def profile(request):
    user = request.user
    if request.method == 'POST':
        form = ProfileForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            firstname = cd['firstname']
            lastname = cd['lastname']
            email = cd['email']
            password = cd['newpassword']
            user.first_name = firstname
            user.last_name = lastname
            user.email = email
            if password:
                user.set_password(password)
            user.save()
            c = {
                'form': form,
                'user': request.user,
                "message_count": message_count(request.user),
                "ticket_count": ticket_count(request.user),
                'active': 'profile'
            }
            c.update(csrf(request))
            return render_to_response('profile.html', c)
        else:
            c = {
                'form': form,
                'user': request.user,
                "message_count": message_count(request.user),
                "ticket_count": ticket_count(request.user),
                'active': 'profile'
            }
            c.update(csrf(request))
            return render_to_response('profile.html', c)
    else:
        data = {
            'firstname': user.first_name,
            'lastname': user.last_name,
            'username': user.username,
            'email': user.email
        }
        form = ProfileForm(data)
        c = {
            'form': form,
            'user': request.user,
            "message_count": message_count(request.user),
            "ticket_count": ticket_count(request.user),
            'active': 'profile'
        }
        c.update(csrf(request))
        return render_to_response('profile.html', c)
Exemplo n.º 4
0
def change_password(request,username):
  if request.method == "POST":
    form = ChangePasswdForm(request.POST)
    if form.is_valid():
      cd = form.cleaned_data
      user = request.user
      old_password = cd['old_password']
      new_password = cd['new_password']
      try:
	account = Account.objects.get(user=user,username=username)
	if account.password == old_password:
	    account.password = new_password
	    account.save()
	    return HttpResponseRedirect("/home/account/")
	else:
	     form = ChangePasswdForm()
	     form.errors['old_password'] = u"密码错误!"
             c = {'form':form,
                  'message_count':message_count(request.user),
                  'ticket_count':ticket_count(request.user),
                  'active':'account',
                  'user':request.user}
             c.update(csrf(request))
	     return render_to_response("change_password.html",c)
      except Account.DoesNotExist:
	form = ChangePasswdForm()
	form.errors['old_password'] = u"帐号不存在!"
        c = {'form':form,
             'message_count':message_count(request.user),
             'ticket_count':ticket_count(request.user),
             'active':'account',
             'user':request.user}
        c.update(csrf(request))
	return render_to_response("change_password.html",c)
    else:
      c = {'form':form,
           'message_count':message_count(request.user),
           'ticket_count':ticket_count(request.user),
           'active':'account',
           'user':request.user}
      c.update(csrf(request))
      return render_to_response("change_password.html",c)
  else:
    form = ChangePasswdForm()
    c = {'form':form,
         'message_count':message_count(request.user),
         'ticket_count':ticket_count(request.user),
         'active':'account',
         'user':request.user}
    c.update(csrf(request))
    return render_to_response("change_password.html",c)
Exemplo n.º 5
0
def order(request):
    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            order = Order()
            order.user = request.user
            order.username = cd['username']
            order.password = cd['password']
            cycle = Cycle.objects.get(name=cd['cycle'])
            plan = Plan.objects.get(name=cd['plan'])
            code = cd['promotion']
            order.cycle = cycle
            order.plan = plan
            if promotion_is_valid(request.user, code, plan):
                promotion = Promotion.objects.get(code=code, plan=plan)
                order.price = int(
                    cycle.quota / 30) * cycle.discount * plan.discount * (
                        plan.price - promotion.price) * promotion.discount
                order.promotion = promotion.code
                order.discount = cycle.discount * plan.discount * promotion.discount
            else:
                order.price = int(
                    cycle.quota /
                    30) * cycle.discount * plan.price * plan.discount
                order.discount = cycle.discount * plan.discount
            order.save()
            send_order_mail(request.user, order)
            return HttpResponseRedirect("/home/order/")
        else:
            c = {
                'form': form,
                'user': request.user,
                'message_count': message_count(request.user),
                'ticket_count': ticket_count(request.user),
                'active': 'order'
            }
            c.update(csrf(request))
            return render_to_response("order.html", c)
    else:
        form = OrderForm()
        c = {
            'form': form,
            'user': request.user,
            'message_count': message_count(request.user),
            'ticket_count': ticket_count(request.user),
            'active': 'order'
        }
        c.update(csrf(request))
        return render_to_response("order.html", c)
Exemplo n.º 6
0
def account_list(request):
    vpn_accounts = []
    user = request.user
    accounts = Account.objects.filter(user=user)
    for account in accounts:
        vpn_accounts.append({
            'username':
            account.username,
            'password':
            account.password,
            'plan':
            account.plan.detail,
            'cycle':
            account.cycle.detail,
            'promotion':
            account.promotion,
            'quota_bytes':
            str("%.2f" % (float(account.quota_bytes) / 1048576.00)) + "MB",
            'quota_used':
            str("%.2f" % (float(quota_used(account)) / 1048576.00)) + "MB",
            'expiry':
            account.creation + timedelta(days=account.quota_cycle),
            "status": (account.active and account.enabled)
        })
    return render_to_response(
        "account_list.html", {
            'vpn_accounts': vpn_accounts,
            'user': request.user,
            "message_count": message_count(request.user),
            "ticket_count": ticket_count(request.user),
            'active': 'account'
        })
Exemplo n.º 7
0
def order_list(request):
    vpn_orders = []
    user = request.user
    orders = Order.objects.filter(user=user)
    for order in orders:
        vpn_orders.append({
            'order_id': order.order_id,
            'order_time': order.order_time,
            'username': order.username,
            'password': order.password,
            'cycle': order.cycle.detail,
            'plan': order.plan.detail,
            'price': order.price,
            'discount': order.discount,
            'promotion': order.promotion,
            'status': order.status
        })
    return render_to_response(
        "order_list.html", {
            'vpn_orders': vpn_orders,
            'user': request.user,
            "message_count": message_count(request.user),
            "ticket_count": ticket_count(request.user),
            'active': 'order'
        })
Exemplo n.º 8
0
def ticket(request, thread_id):
    user = request.user
    thread_id = int(thread_id)
    try:
        thread = TicketThread.objects.get(user=user, id=thread_id)
        thread.status = False
        thread.save()
        tickets = Ticket.objects.filter(thread=thread)
        if request.method == "POST":
            form = TicketForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                newticket = Ticket()
                newticket.subject = cd['subject']
                newticket.content = cd['content']
                newticket.sender = user.username
                newticket.thread = thread
                newticket.save()
            c = {
                "thread": thread,
                "tickets": tickets,
                "form": form,
                "user": user,
                "message_count": message_count(request.user),
                "ticket_count": ticket_count(request.user),
                "active": "ticket"
            }
            c.update(csrf(request))
            return render_to_response("ticket_thread.html", c)
        else:
            data = {"subject": "RE:" + thread.subject}
            form = TicketForm(data)
            c = {
                "thread": thread,
                "tickets": tickets,
                "form": form,
                "user": user,
                "message_count": message_count(request.user),
                "ticket_count": ticket_count(request.user),
                "active": "ticket"
            }
            c.update(csrf(request))
            return render_to_response("ticket_thread.html", c)
    except TicketThread.DoesNotExist:
        return HttpResponseRedirect("/home/ticket/")
Exemplo n.º 9
0
def message_list(request):
    user = request.user
    messages = Message.objects.filter(user=user)
    return render_to_response("message_list.html",{
        "messages":messages,
        "user":request.user,
        "message_count":message_count(request.user),
        "ticket_count":ticket_count(request.user),
        "active":"message"})
Exemplo n.º 10
0
def ticket_list(request):
    user = request.user
    threads = TicketThread.objects.filter(user=user)
    return render_to_response("ticket_list.html",{
        "threads":threads,
        "user":user,
        "message_count":message_count(request.user),
        "ticket_count":ticket_count(request.user),
        "active":"ticket"})
Exemplo n.º 11
0
def profile(request):
  user = request.user
  if request.method == 'POST':
      form = ProfileForm(request.POST)
      if form.is_valid():
	cd = form.cleaned_data
	firstname = cd['firstname']
	lastname = cd['lastname']
        email = cd['email']
        password = cd['newpassword']
        user.first_name = firstname
        user.last_name = lastname
        user.email = email
        if password:
            user.set_password(password)
        user.save()
        c = {'form':form,
            'user':request.user,
            "message_count":message_count(request.user),
            "ticket_count":ticket_count(request.user),
            'active':'profile'}
        c.update(csrf(request))
        return render_to_response('profile.html',c)
      else:
        c = {'form':form,
            'user':request.user,
            "message_count":message_count(request.user),
            "ticket_count":ticket_count(request.user),
            'active':'profile'}
        c.update(csrf(request))
        return render_to_response('profile.html',c)
  else:
      data = {'firstname':user.first_name,
              'lastname':user.last_name,
              'username':user.username,
              'email':user.email}
      form = ProfileForm(data)
      c = {'form':form,
           'user':request.user,
            "message_count":message_count(request.user),
            "ticket_count":ticket_count(request.user),
           'active':'profile'}
      c.update(csrf(request))
      return render_to_response('profile.html',c)
Exemplo n.º 12
0
def order_list(request):
  vpn_orders = []
  user = request.user
  orders = Order.objects.filter(user=user)
  return render_to_response("order_list.html",{
      'orders':orders,
      'user':request.user,
      "message_count":message_count(request.user),
      "ticket_count":ticket_count(request.user),
      'active':'order'})
Exemplo n.º 13
0
def order(request):
  if request.method == 'POST':
      form = OrderForm(request.POST)
      if form.is_valid():
	cd = form.cleaned_data
	order = Order()
	order.user = request.user
	order.username = cd['username']
	order.password = cd['password']
	cycle = Cycle.objects.get(name=cd['cycle'])
	plan = Plan.objects.get(name=cd['plan'])
        code = cd['promotion']
	order.cycle = cycle
	order.plan = plan
        if promotion_is_valid(request.user,code,plan):
            promotion = Promotion.objects.get(code=code,plan=plan)
            order.price = int(cycle.quota/30) * cycle.discount * plan.discount * ( plan.price - promotion.price ) * promotion.discount
            order.promotion = promotion.code
            order.discount = cycle.discount * plan.discount * promotion.discount
        else:
            order.price = int(cycle.quota/30) * cycle.discount * plan.price * plan.discount
            order.discount = cycle.discount * plan.discount
	order.save()
	send_order_mail(request.user,order)
	return HttpResponseRedirect("/home/order/")
      else:
        c = {'form':form,
            'user':request.user,
            'message_count':message_count(request.user),
            'ticket_count':ticket_count(request.user),
            'active':'order'}
        c.update(csrf(request))
	return render_to_response("order.html",c)
  else:	
      form = OrderForm()
      c = {'form':form,
           'user':request.user,
            'message_count':message_count(request.user),
            'ticket_count':ticket_count(request.user),
           'active':'order'}
      c.update(csrf(request))
      return render_to_response("order.html",c)
Exemplo n.º 14
0
def ticket_list(request):
    user = request.user
    threads = TicketThread.objects.filter(user=user)
    return render_to_response(
        "ticket_list.html", {
            "threads": threads,
            "user": user,
            "message_count": message_count(request.user),
            "ticket_count": ticket_count(request.user),
            "active": "ticket"
        })
Exemplo n.º 15
0
def message_list(request):
    user = request.user
    messages = Message.objects.filter(user=user)
    return render_to_response(
        "message_list.html", {
            "messages": messages,
            "user": request.user,
            "message_count": message_count(request.user),
            "ticket_count": ticket_count(request.user),
            "active": "message"
        })
Exemplo n.º 16
0
def ticket(request,thread_id):
    user = request.user
    thread_id = int(thread_id)
    try:
        thread = TicketThread.objects.get(user=user,id=thread_id)
        thread.status = False
        thread.save()
        tickets = Ticket.objects.filter(thread=thread)
        if request.method == "POST":
            form = TicketForm(request.POST)
            if form.is_valid():
                cd = form.cleaned_data
                newticket = Ticket()
                newticket.subject = cd['subject']
                newticket.content = cd['content']
                newticket.sender = user.username
                newticket.thread = thread
                newticket.save()
            c = {"thread":thread,
                 "tickets":tickets,
                 "form":form,
                 "user":user,
                 "message_count":message_count(request.user),
                 "ticket_count":ticket_count(request.user),
                 "active":"ticket"}
            c.update(csrf(request))
            return render_to_response("ticket_thread.html",c)
        else:
            data = {"subject":"RE:"+thread.subject}
            form = TicketForm(data)
            c = {"thread":thread,
                 "tickets":tickets,
                 "form":form,
                 "user":user,
                 "message_count":message_count(request.user),
                 "ticket_count":ticket_count(request.user),
                 "active":"ticket"}
            c.update(csrf(request))
            return render_to_response("ticket_thread.html",c)
    except TicketThread.DoesNotExist:
        return HttpResponseRedirect("/home/ticket/")
Exemplo n.º 17
0
def order_list(request):
    vpn_orders = []
    user = request.user
    orders = Order.objects.filter(user=user)
    return render_to_response(
        "order_list.html", {
            'orders': orders,
            'user': request.user,
            "message_count": message_count(request.user),
            "ticket_count": ticket_count(request.user),
            'active': 'order'
        })
Exemplo n.º 18
0
def ticket_submit(request):
    user = request.user
    if request.method == "POST":
        form = TicketForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            thread = TicketThread()
            thread.user = user
            thread.subject = cd['subject']
            thread.save()
            ticket = Ticket()
            ticket.thread = thread
            ticket.subject = thread.subject
            ticket.content = cd['content']
            ticket.sender = user.username
            ticket.save()
            send_ticket_mail(user, ticket)
            return HttpResponseRedirect("/home/ticket/")
        else:
            c = {
                "form": form,
                "user": user,
                "message_count": message_count(request.user),
                "ticket_count": ticket_count(request.user),
                "active": "ticket"
            }
            c.update(csrf(request))
            return render_to_response("ticket_submit.html", c)
    else:
        form = TicketForm()
        c = {
            "form": form,
            "user": user,
            "message_count": message_count(request.user),
            "ticket_count": ticket_count(request.user),
            "active": "ticket"
        }
        c.update(csrf(request))
        return render_to_response("ticket_submit.html", c)
Exemplo n.º 19
0
def message(request,message_id):
    user = request.user
    message_id = int(message_id)
    try:
        message = Message.objects.get(user=user,id=message_id)
        message.active = False
        message.save()
        return render_to_response("message.html",{
            "message":message,
            "user":user,
            "message_count":message_count(request.user),
            "ticket_count":ticket_count(request.user),
            "active":"message"})
    except Message.DoesNotExist:
        return HttpResponseRedirect("/home/message/")
Exemplo n.º 20
0
def message(request, message_id):
    user = request.user
    message_id = int(message_id)
    try:
        message = Message.objects.get(user=user, id=message_id)
        message.active = False
        message.save()
        return render_to_response(
            "message.html", {
                "message": message,
                "user": user,
                "message_count": message_count(request.user),
                "ticket_count": ticket_count(request.user),
                "active": "message"
            })
    except Message.DoesNotExist:
        return HttpResponseRedirect("/home/message/")
Exemplo n.º 21
0
def account_list(request):
  vpn_accounts = []
  user = request.user
  accounts = Account.objects.filter(user=user)
  for account in accounts:
    vpn_accounts.append({
        'username':account.username,
        'password':account.password,
        'plan':account.plan.detail,
        'cycle':account.cycle.detail,
        'promotion':account.promotion,
        'quota_bytes':str("%.2f"%(float(account.quota_bytes)/1048576.00))+"MB",
        'quota_used':str("%.2f"%(float(quota_used(account))/1048576.00))+"MB",
        'expiry':account.creation+timedelta(days=account.quota_cycle),
        "status":(account.active and account.enabled)})
  return render_to_response("account_list.html",{
      'vpn_accounts':vpn_accounts,
      'user':request.user,
      "message_count":message_count(request.user),
      "ticket_count":ticket_count(request.user),
      'active':'account'})
Exemplo n.º 22
0
def order_list(request):
  vpn_orders = []
  user = request.user
  orders = Order.objects.filter(user=user)
  for order in orders:
    vpn_orders.append({
        'order_id':order.order_id,
        'order_time':order.order_time,
        'username':order.username,
        'password':order.password,
        'cycle':order.cycle.detail,
        'plan':order.plan.detail,
        'price':order.price,
        'discount':order.discount,
        'promotion':order.promotion,
        'status':order.status})
  return render_to_response("order_list.html",{
      'vpn_orders':vpn_orders,
      'user':request.user,
      "message_count":message_count(request.user),
      "ticket_count":ticket_count(request.user),
      'active':'order'})