示例#1
0
def index(request):
    if request.session.get('log'):
        return redirect(homeIndex)
    if request.method == "POST":
        mail = request.POST.get('email')
        userInfo = UsersData.objects.filter(mail=mail).first()
        if userInfo == None:
            return error(request, "Your mail is not registered to us", "Home",
                         "/")
        otp = otpGenerate()
        try:
            send_mail(
                "OTP | E Note Book",
                f'Hey your OTP to reset password is {otp}',
                settings.EMAIL_HOST_USER,
                [mail],
                fail_silently=False,
            )
            tempUser = ForgotTempData(otp=otp, mail=mail)
            tempUser.save()
            userDict = {"mail": mail}
        except:
            return error(request, "There are some internal issue", "Home", "/")
        return render(request, "forgotOtpCheck.html", userDict)
    return render(request, "fIndex.html")
示例#2
0
def giveAccess(request):
    if request.method == "POST":
        if not request.session.get('log'):
            return error(request, "Login first", "Home", "/")
        targetUser = request.POST.get("targetUser")
        slug = request.POST.get("slug")
        manageAccess(request, slug, targetUser, True)
    return redirect("/")
示例#3
0
def makePrivate(request):
    if request.method == "POST":
        slug = request.POST.get("slug")
        notebook = NoteBook.objects.filter(slug=slug).first()
        notebook.isPublic = False
        notebook.save()
        return successMessage(request, "Note is Private now", "Home", "/")
    return error(request, "Not Allowed", "Home", "/")
示例#4
0
def share(request, slug):
    if not request.session.get('log'):
        return error(request, "Login first", "Home", "/")
    notebook = NoteBook.objects.filter(slug=slug).first()
    if notebook.bookOwner != request.session.get('userName'):
        return error(request, "You are not allowed to edit this book",
                     "Back to Home", "/")
    rawList = notebook.shareList
    userList = rawList.split('"')
    for item in userList:
        if item == '':
            userList.remove(item)
    noteDict = {
        "bookName": notebook.noteName,
        "isPublic": notebook.isPublic,
        "slug": slug,
        "userList": userList,
    }
    return render(request, "share.html", noteDict)
示例#5
0
def otpcheck(request):
    if request.session.get('log'):
        return redirect(homeIndex)
    if request.method == "POST":
        mail = request.POST.get('mail')
        userOtp = request.POST.get('otp')
        tempUserData = ForgotTempData.objects.filter(mail=mail).first()
        if userOtp == tempUserData.otp:
            userDict = {"mail": tempUserData.mail}
            tempUserData.delete()
            return render(request, "resetPassword.html", userDict)
        tempUserData.delete()
        return error(request, "OTP not matched", "Try Again", "/forgot")
    return render(request, "forgotOtpCheck.html")
示例#6
0
def resetPass(request):
    if request.session.get('log'):
        return redirect(homeIndex)
    if request.method == "POST":
        newPass = request.POST.get('newPass')
        newConPass = request.POST.get('newConPass')
        mail = request.POST.get('mail')
        if newConPass == newPass:
            userInfo = UsersData.objects.filter(mail=mail).first()
            userInfo.password = make_password(newPass)
            userInfo.save()
            return successMessage(request, "Password reset done", "Home", "/")
        return error(request, "New password & confirm password not matched",
                     "Try Again", "/forgot")
    return redirect(index)
示例#7
0
def manageAccess(request, slug, targetUser, adding):
    if request.method == "POST":
        print("in fun")
        if not request.session.get('log'):
            return error(request, "Login first", "Home", "/")
        print("log check")
        getUser = UsersData.objects.filter(mail=targetUser).first()
        print(getUser)
        if getUser is None:
            return error(request, "User Not Found", "Back", "/")
        print("target check")
        getNote = NoteBook.objects.filter(slug=slug).first()
        if getNote is None:
            return error(request, "Note not found", "Back", "/")
        print("note check")
        print("all check passed")
        print(f"Note is {getNote.shareList}")
        if getNote.shareList is not None:
            getNote.shareList += json.dumps(targetUser)
        else:
            getNote.shareList = json.dumps(targetUser)
        getNote.save()
        print("last part")
    return redirect(f"/share/{slug}/")