Exemple #1
0
def signup(request):
    "Handles signup requests. If user already registered, re-direct to main page"
    user = users.get_current_user()
    if not user:
        return HttpResponseRedirect(login_url)
    if get_rgs_user(guser=user):
        return HttpResponseRedirect('/')

    if request.method == 'POST':
        results = {}
        nick = string.lower(escape(string.strip(request.POST.get('nick',''))))
        email = string.lower(escape(string.strip(request.POST.get('email',''))))
        if not new_user(nick=nick, email=email, user=user, results=results):
             return HttpResponseRedirect('/signup?rc=%d' % results['retcode'])
        return HttpResponseRedirect(request.POST.get('cont','/'))
    elif request.method == 'GET':
        error_str = get_error_str(escape(request.GET.get('rc', '')))
        return render_to_response('signup.html', 
                                  {'user_nick':user.nickname(), 
                                   'user_email':user.email(), 
                                   'error_str':error_str,
                                   'cont':request.GET.get("cont", "/"), 
                                   'act':request.GET.get("act",""), 
                                   'actarg':request.GET.get("actarg",""), 
                                  }, context_instance=RequestContext(request))
    return HttpResponseRedirect('/')
Exemple #2
0
def post(request):
    "Handles post/source submission requests"
    ruser = get_rgs_user()
    if request.method == 'GET':
        error_str = get_error_str(escape(request.GET.get('rc', '')))
        return render_to_response('post.html',
                                   {
                                    'ruser' : ruser,
                                    'logout_url':logout_url,
                                    'error_str':error_str,
                                   },
                                  context_instance=RequestContext(request))
    elif request.method == 'POST':
        title = string.strip(escape(request.POST.get('title','')))
        url = string.lower(string.strip(escape(request.POST.get('url',''))))
        retcode = submit_post(title=title, url=url, ruser=ruser)
        return HttpResponseRedirect('/post?rc=%d' % retcode)
    return HttpResponseRedirect('/')