示例#1
0
def saveFaq(request, uinfo):
    if request.method == 'POST':
        access_token = get_access_token(
            request, request.build_absolute_uri(reverse('home:gettoken')))
        if not access_token:
            return HttpResponse("You are not logged in")
        user = get_me(access_token)
        username = user['mail'].replace("@iitg.ac.in", "")
        if username != uinfo:
            return HttpResponse("You are not authorized")

        faq_list = []
        if request.POST.get('newQ') != '' and request.POST.get('newA') != '':
            faq_list.append({
                'q': request.POST.get('newQ'),
                'a': request.POST.get('newA')
            })
        for i in range(int(request.POST.get('numberOfFAQ'))):
            if request.POST.get('q' + str(i + 1)) != '' and request.POST.get(
                    'a' + str(i + 1)) != '':
                faq_list.append({
                    'q': request.POST.get('q' + str(i + 1)),
                    'a': request.POST.get('a' + str(i + 1))
                })

        faq_dict = {'qa': faq_list}
        db.collection(u'Homepage').document(u'faq').set(faq_dict)

        return HttpResponseRedirect("/users/" + username + "/editFaq/")
    return HttpResponseRedirect(reverse('home:home'))
示例#2
0
def saveHome(request, uinfo):
    if request.method == 'POST':
        access_token = get_access_token(
            request, request.build_absolute_uri(reverse('home:gettoken')))
        if not access_token:
            return HttpResponse("You are not logged in")
        user = get_me(access_token)
        username = user['mail'].replace("@iitg.ac.in", "")
        if username != uinfo:
            return HttpResponse("You are not authorized")

        home_list = []
        if request.POST.get('newT') != '' and request.POST.get('newC') != '':
            home_list.append({
                'title': request.POST.get('newT'),
                'text': request.POST.get('newC')
            })
        for i in range(int(request.POST.get('section_no'))):
            if request.POST.get('t' + str(i + 1)) != '' and request.POST.get(
                    'c' + str(i + 1)) != '':
                home_list.append({
                    'title': request.POST.get('t' + str(i + 1)),
                    'text': request.POST.get('c' + str(i + 1))
                })

        home_dict = {'paragraphs': home_list}
        db.collection(u'Homepage').document(u'homepage').set(home_dict)

        return HttpResponseRedirect("/users/" + username + "/editHome/")
    return HttpResponseRedirect(reverse('home:home'))
示例#3
0
def editProfile(request, uinfo):
    access_token = get_access_token(
        request, request.build_absolute_uri(reverse('home:gettoken')))
    if not access_token:
        return HttpResponse("You are not logged in")
    user = get_me(access_token)
    username = user['mail'].replace("@iitg.ac.in", "")
    if username != uinfo:
        return HttpResponse("You are not authorized")
    user = db.collection(u'Users').document(username).get()
    user_dict = user.to_dict()
    user_dict["id"] = user.id
    t = 0
    if user_dict["Designation"] == "Student":
        t = 1
    if user_dict["Designation"] == "Faculty":
        t = 0
    context = {'isStudent': t, 'user': user_dict}
    context = loginFLOW(request, context)
    if 'isAdmin' in user_dict:
        context["isAdmin"] = "True"
    else:
        context["isAdmin"] = "False"
    context['Designation'] = user_dict['Designation']
    return render(request, 'home/editProfile.html', context)
示例#4
0
def redirect_user(request):
    access_token = get_access_token(
        request, request.build_absolute_uri(reverse('home:gettoken')))
    if not access_token:
        return HttpResponse("You are not logged in")
    user = get_me(access_token)
    username = user['mail'].replace("@iitg.ac.in", "")
    return HttpResponseRedirect("http://localhost:8000/users/" + username)
示例#5
0
def ViewUser(request, uinfo):
    access_token = get_access_token(
        request, request.build_absolute_uri(reverse('home:gettoken')))
    if not access_token:
        return HttpResponse("You are not logged in")
    user = get_me(access_token)
    username = user['mail']
    username = username.replace("@iitg.ac.in", "")
    if username != uinfo:
        return HttpResponse("Error")

    context = {'username': uinfo}
    return render(request, 'home/user.html', context)
示例#6
0
def edit(request, uinfo):
    if request.method == 'POST':
        access_token = get_access_token(
            request, request.build_absolute_uri(reverse('home:gettoken')))
        if not access_token:
            return HttpResponse("You are not logged in")
        user = get_me(access_token)
        username = user['mail'].replace("@iitg.ac.in", "")
        if username != uinfo:
            return HttpResponse("Error")
        user = db.collection(u'Users').document(username).get()
        user_dict = user.to_dict()
        user_dict["About"] = request.POST.get('about_me')
        user_dict["Contact"] = request.POST.get('contact')
        user_dict["URL"]["Github"] = request.POST.get('github')
        user_dict["URL"]["Linkedin"] = request.POST.get('linkedin')
        user_dict["URL"]["Homepage"] = request.POST.get('homepage')
        db.collection(u'Users').document(username).set(user_dict)
        return HttpResponseRedirect("http://localhost:8000/users/" + username)
示例#7
0
def saveContact(request, uinfo):
    if request.method == 'POST':
        access_token = get_access_token(
            request, request.build_absolute_uri(reverse('home:gettoken')))
        if not access_token:
            return HttpResponse("You are not logged in")
        user = get_me(access_token)
        username = user['mail'].replace("@iitg.ac.in", "")
        if username != uinfo:
            return HttpResponse("You are not authorized")

        contact = db.collection(u'Homepage').document(u'contactUs').get()
        contact_dict = contact.to_dict()

        contact_dict["Email"] = request.POST.get('email')
        contact_dict["Location"] = request.POST.get('address')
        contact_dict["PhoneNumber"] = request.POST.get('phone')

        db.collection(u'Homepage').document(u'contactUs').set(contact_dict)
        return HttpResponseRedirect("/users/" + username)
    return HttpResponseRedirect(reverse('home:home'))