Esempio n. 1
0
def deleteBrandWithReason(request, brand):
    if request.method != 'POST':
        deleteForm = RejectionReason()
        context = {
            'form': deleteForm,
            'userPending': countUserPending(request)
        }
        return render(request, 'deletionReason.html', context)
    else:
        deleteReason = request.POST.get('reason')
        try:
            getBrand = Brand.objects.get(brandName=brand)

            domain = get_current_site(request).domain
            sendMail(domain, getBrand, 'admin_brand_delete', deleteReason)

            userAuth = auth_user.objects.get(username=getBrand.brandName)
            userAuth.groups.clear()
            userAuth.delete()

            getBrand.delete()

            return redirect('brandcontrol')

        except Exception as e:
            print(e)
            context = {'message': 'error'}
            return render(request, 'error.html', context)
Esempio n. 2
0
def deleteUser(request, auth_token):
    if request.method != 'POST':
        rejectionForm = RejectionReason()
        context = {
            'form': rejectionForm,
            'userPending': countUserPending(request)
        }
        return render(request, 'deletionReason.html', context)
    else:
        rejectionReason = request.POST.get('reason')
        try:
            profile_obj = User.objects.get(auth_token=auth_token)
            if profile_obj:
                if profile_obj.roleId == 'Mus_Store':
                    musicStore = MusicStoreData.objects.select_related(
                        'userID').get(userID__userName=profile_obj.userName)
                    if os.path.exists(musicStore.musicStorePicture.name
                                      ) and os.path.exists(
                                          musicStore.musicStorePicture2.name
                                      ) and os.path.exists(
                                          musicStore.musicStorePicture3.name):
                        os.remove(musicStore.musicStorePicture.name)
                        os.remove(musicStore.musicStorePicture2.name)
                        os.remove(musicStore.musicStorePicture3.name)
                    else:
                        pass
                else:
                    if os.path.exists(profile_obj.profilePicture.name):
                        os.remove(profile_obj.profilePicture.name)
                    else:
                        pass

                domain = get_current_site(request).domain
                sendMail(domain, profile_obj, 'admin_delete', rejectionReason)

                userAuth = auth_user.objects.get(username=profile_obj.userName)
                userAuth.groups.clear()
                userAuth.delete()

                profile_obj.delete()

                webRender = 'success.html'
                return redirect('usercontrol')
            else:
                raise Exception("User Empty")

        except Exception as e:
            print(e)
            context = {'message': 'error'}
            return render(request, 'error.html', context)
Esempio n. 3
0
def rejectReport(request, user_select, brand, productName):
    try:
        if request.method != 'POST':
            rejectionForm = RejectionReason()
            context = {
                'form': rejectionForm,
                'userPending': countUserPending(request)
            }
            return render(request, 'rejectionReason.html', context)
        else:
            rejectionReason = request.POST.get('reason')

            getProduct = Product.objects.select_related('brandId').get(
                productName=productName, brandId__brandName=brand)

            obj = Review.objects.select_related('userID').get(
                productId=getProduct.productId, userID__userName=user_select)

            getReportReviewData = Report.objects.select_related(
                'reviewId', 'userID').filter(reviewId__reviewId=obj.reviewId)

            getUserEmailList = []

            for email in getReportReviewData:
                getUserEmailList.append(email.userID.email)

            domain = get_current_site(request).domain
            message = """ 
                        Hello Users!!,
                        Unfortunately your review report about \" """ + obj.title + """ \" from """ + user_select + """
                        in """ + getProduct.productName + """, has been rejected by admin because:\n\n
                        """ + rejectionReason + """
                        \n\n
                        thank you
                        http://""" + domain + """
                    """
            getUser = User.objects.get(userName=user_select)
            sendMail(domain, getUserEmailList, 'reject_report', message)

            getReportReviewData.delete()

            return redirect('reportList')

    except Exception as e:
        print(e)
        context = {'message': 'error'}
        return render(request, 'error.html', context)

    return 'success'
Esempio n. 4
0
def approveReport(request, user_select, brand, productName):
    try:
        getProduct = Product.objects.select_related('brandId').get(
            productName=productName, brandId__brandName=brand)

        obj = Review.objects.select_related('userID').get(
            productId=getProduct.productId, userID__userName=user_select)

        getReportReason = Report.objects.select_related('reviewId').filter(
            reviewId__reviewId=obj.reviewId).values('reason').distinct()

        getReasonArray = []

        i = 0
        while i < len(getReportReason):
            getReasonArray.append(getReportReason[i]['reason'])
            i += 1

        reason = ""
        for item in getReasonArray:
            reason += '- ' + item + '\n'

        domain = get_current_site(request).domain
        message = """ 
                    hi """ + user_select + """,
                    we like to inform you about your review with a title \" """ + obj.title + """ \"
                    in """ + getProduct.productName + """, has been reported due to: \n
                    """ + reason + """
                    \n
                    thank you
                    http://""" + domain + """
                """
        getUser = User.objects.get(userName=user_select)
        sendMail(domain, getUser, 'approve_report', message)

        obj.delete()
        updateReviewAvg(getProduct)

        return redirect('reportList')
    except Exception as e:
        print(e)
        context = {'message': 'error'}
        return render(request, 'error.html', context)
Esempio n. 5
0
def approve (request,auth_token):
    webRender = ''
    try:
        profile_obj = User.objects.filter(auth_token = auth_token).first()
        if profile_obj:
            profile_obj.status = 'Verified'
            profile_obj.save()

            domain = get_current_site(request).domain
            sendMail (domain, profile_obj, 'admin_approve','')

            webRender = 'success.html'
        else:
            context = {
                'message': 'error'
            }
            return render(request,'error.html', context)
    except Exception as e:
        print (e)   

    return render(request,webRender)
Esempio n. 6
0
def inviteBrand(request):
    if request.method != 'POST':
        inviteForm = InviteBrandForm()
        context = {'form': inviteForm, 'context': 'Invite Brand'}
        return render(request, 'addInviteRegisterBrand.html', context)
    else:
        brandName = request.POST.get('brandName')
        email = request.POST.get('email')
        message = request.POST.get('message')
        brandData = []
        try:
            if brandName == '':
                raise Exception("required field Empty")
            if email == '':
                raise Exception("required field Empty")
            if message == '':
                raise Exception("required field Empty")

            brand_obj = Brand.objects.get(brandName=brandName)
            if brand_obj.status != 'No_User':
                messages.success(
                    request, 'Brand is Already receive email / have account ')
                return redirect('inviteBrand')

            token = str(uuid.uuid4())
            brandData.append(email)
            brandData.append(token)

            domain = get_current_site(request).domain
            sendMail(domain, brandData, 'brand_invitation', message)

            brand_obj.status = 'User_Verif'
            brand_obj.auth_token = token
            brand_obj.save()

            return redirect('brandcontrol')
        except Exception as e:
            context = {'message': 'error'}
            return render(request, 'error.html', context)
Esempio n. 7
0
def registerMember (request):
    if request.method != 'POST':
        regis_form = UserForm()
        context = {
            'form': regis_form,
            'role': 'Member'
        }
        return render(request,'registerMember.html', context)
    else :
        username = request.POST.get('username')
        email = request.POST.get('email')
        password = request.POST.get('password')
        conf_pass = request.POST.get('confirm_pass')

        web_direct = ''

        try: 
            if username == '':
                raise Exception("required field Empty")
            if email == '':
                raise Exception("required field Empty")
            if password == '':
                raise Exception("required field Empty")
            if conf_pass == '':
                raise Exception("required field Empty")

            if len(username) > 20:
                messages.success(request, 'User Name has tobe less than or equal 20 characters')
                return redirect ('addProduct')

            if checkChar (username) == False:
                messages.success(request, 'Name cannot contain / , # , and ?')
                return redirect ('regularUser')

            if User.objects.filter(userName = username).first():
                messages.success(request, 'Username is Taken')
                return redirect ('regularUser')

            if User.objects.filter(email = email).first():
                messages.success(request, 'email is Taken')
                return redirect ('regularUser')
            
            check_pass = weakPassword (password)
            if check_pass != 'True':
                messages.success(request, check_pass)
                return redirect ('regularUser')

            if (conf_pass != password):
                messages.success(request, 'confirm password should be same as password')
                return redirect ('regularUser')

            token = str (uuid.uuid4())
            
            profile_obj = User.objects.create(
                userName = username,
                email = email, 
                password = make_password(password),
                roleId = 'Reg_User',
                description = '',
                status = 'Pending',
                dtm_crt = datetime.now(),
                verified_at = None,
                auth_token = token
            )

            profile_obj.save()

            regisUserAuth(profile_obj)

            domain = get_current_site(request).domain

            sendMail (domain, profile_obj ,'verification', '')
            web_direct = 'token-send.html'
            return render(request,'token-send.html') 

        except Exception as e:
            print(e)
            web_direct = 'error.html'

    return render(request,web_direct)
Esempio n. 8
0
def registerMusicStore (request):
    if request.method != 'POST':
        regis_form = MusicStoreForm()
        context = {
            'form': regis_form
        }
        return render(request,'registerMusicStore.html', context)
    else:
        musicStoreName = request.POST.get('username')
        address = request.POST.get('address')
        email = request.POST.get('email')
        password = request.POST.get('password')
        conf_pass = request.POST.get('confirm_pass')
        contact = request.POST.get('contact')
        msPicture = request.FILES['musicStorePicture']
        msPicture.name = musicStoreName+'.jpg'
        msPicture2 = request.FILES['musicStorePicture2']
        msPicture2.name = musicStoreName+'2.jpg'
        msPicture3 = request.FILES['musicStorePicture3']
        msPicture3.name = musicStoreName+'3.jpg'
        description = request.POST.get('description')

        web_direct = ''

        try: 

            if musicStoreName == '':
                raise Exception("required field Empty")
            if address == '':
                raise Exception("required field Empty")
            if email == '':
                raise Exception("required field Empty")
            if password == '':
                raise Exception("required field Empty")
            if conf_pass == '':
                raise Exception("required field Empty")
            if contact == '':
                raise Exception("required field Empty")
            if msPicture == '' or msPicture == None:
                raise Exception("required field Empty")
            if msPicture2 == '' or msPicture2 == None:
                raise Exception("required field Empty")
            if msPicture3 == '' or msPicture3 == None:
                raise Exception("required field Empty")
            if description == '':
                raise Exception("required field Empty")

            if checkChar (musicStoreName) == False:
                messages.success(request, 'Name cannot contain / , # , and ?')
                return redirect ('musicStore')

            if len(musicStoreName) > 20:
                messages.success(request, 'Music Store Name has tobe less than or equal 20 characters')
                return redirect ('musicStore')

            if User.objects.filter(userName = musicStoreName).first():
                messages.success(request, 'Music Store Name is Taken')
                return redirect ('musicStore')

            if User.objects.filter(email = email).first():
                messages.success(request, 'email is Taken')
                return redirect ('musicStore')

            check_pass = weakPassword (password)
            if check_pass != 'True':
                messages.success(request, check_pass)
                return redirect ('musicStore')

            if (conf_pass != password):
                messages.success(request, 'confirm password should be same as password')
                return redirect ('musicStore')

            token = str (uuid.uuid4())

            profile_obj = User.objects.create(
                userName = musicStoreName,
                email = email, 
                password = make_password(password),
                roleId = 'Mus_Store',
                description = description,
                status = 'Pending',
                dtm_crt = datetime.now(),
                verified_at = None,
                auth_token = token
            )

            profile_obj.save()
            
            mStore_obj = MusicStoreData.objects.create(
                userID = profile_obj,
                address = address,
                musicStorePicture = msPicture,
                musicStorePicture2 = msPicture2,
                musicStorePicture3 = msPicture3,
                contact = contact
            ) 
            mStore_obj.save()

            img1 = Image.open(mStore_obj.musicStorePicture.path)
            img1 = make_square(img1)
            img1.save(mStore_obj.musicStorePicture.path)

            img2 = Image.open(mStore_obj.musicStorePicture2.path)
            img2 = make_square(img2)
            img2.save(mStore_obj.musicStorePicture2.path)

            img3 = Image.open(mStore_obj.musicStorePicture3.path)
            img3 = make_square(img3)
            img3.save(mStore_obj.musicStorePicture3.path)

            regisUserAuth(profile_obj)



            domain = get_current_site(request).domain

            sendMail(domain, profile_obj, 'verification', '')
            web_direct = 'token-send.html'

        except Exception as e:
            print(e)
            web_direct = 'error.html'

    return render(request,web_direct)