def sendcoin_offsite_test(user_id, sendto, amount, comment):
    """
    Withdrawl offsite
    :param user_id:
    :param sendto:
    :param amount:
    :param comment:
    :return:
    """
    type_transaction = 2
    getwallet = BtcWalletFeeTest.query.get(1)
    walletfee = getwallet.btc

    a = checkbalance(user_id=user_id, amount=amount)
    if a == 1:
        userswallet_test = BtcWalletTest.query.filter_by(
            user_id=user_id).first()

        strcomment = str(comment)

        timestamp = datetime.utcnow()

        amountdecimal = Decimal(amount)
        # make decimal 8th power
        amounttomod = floating_decimals(amountdecimal, 8)
        # gets current balance
        curbalance = floating_decimals(userswallet_test.currentbalance, 8)
        # gets amount and fee
        amountandfee = floating_decimals(amounttomod + walletfee, 8)
        # subtracts amount and fee from current balance
        userfinalbalance = floating_decimals(curbalance - amountandfee, 8)
        # set balance as new amount
        userswallet_test.currentbalance = floating_decimals(
            userfinalbalance, 8)

        wallet_test = BtcWalletWorkTest(
            user_id=user_id,
            type=type_transaction,
            amount=amount,
            sendto=sendto,
            comment=0,
            created=timestamp,
            txtcomment=strcomment,
        )

        db.session.add(wallet_test)
        db.session.add(userswallet_test)
        db.session.commit()
    else:
        add_new_notification(user_id=user_id,
                             subid=0,
                             subname='',
                             postid=0,
                             commentid=0,
                             msg=101)
Example #2
0
def bch_cash_send_coin_offsite(user_id, sendto, amount, comment):
    """
    Add work order to send off site.  more secure using db
    :param user_id:
    :param sendto:
    :param amount:
    :param comment:
    :return:
    """
    getwallet = BchWalletFee.query.get(1)
    walletfee = getwallet.bch
    type_transaction = 2

    a = checkbalance(user_id=user_id, amount=amount)
    if a == 1:
        userswallet = BchWallet.query.filter(BchWallet.user_id == user_id).first()

        strcomment = str(comment)
        timestamp = datetime.utcnow()

        # turn sting to a decimal
        amountdecimal = Decimal(amount)
        # make decimal 8th power
        amounttomod = floating_decimals(amountdecimal, 8)
        # gets current balance
        curbalance = floating_decimals(userswallet.currentbalance, 8)
        # gets amount and fee
        amountandfee = floating_decimals(amounttomod + walletfee, 8)
        # subtracts amount and fee from current balance
        newamount = floating_decimals(curbalance - amountandfee, 8)
        # set balance as new amount
        userswallet.currentbalance = floating_decimals(newamount, 8)

        sendcoinwork = BchWalletWork(
            user_id=user_id,
            type=type_transaction,
            amount=amount,
            sendto=sendto,
            comment=0,
            created=timestamp,
            txtcomment=strcomment,
        )

        db.session.add(sendcoinwork)
        db.session.add(userswallet)
        db.session.commit()

    else:
        add_new_notification(user_id=user_id,
                             subid=0,
                             subname='',
                             postid=0,
                             commentid=0,
                             msg=201
                             )
def monerosendcoin_stagenet(user_id, sendto, amount):
    """
    # OFF SITE
    # withdrawl
    :param user_id:
    :param sendto:
    :param amount:
    :return:
    """
    getwallet = MoneroWalletFeeStagenet.query.get(1)
    walletfee = getwallet.amount
    a = monero_checkbalance_stagenet(user_id=user_id, amount=amount)
    if a == 1:

        timestamp = datetime.utcnow()
        userswallet = MoneroWalletStagenet.query.filter_by(user_id=user_id).first()
        # turn sting to a decimal
        amountdecimal = Decimal(amount)
        # make decimal 8th power
        amounttomod = floating_decimals(amountdecimal, 8)
        # gets current balance
        curbalance = floating_decimals(userswallet.currentbalance, 8)
        # gets amount and fee
        amountandfee = floating_decimals(amounttomod + walletfee, 8)
        # subtracts amount and fee from current balance
        y = floating_decimals(curbalance - amountandfee, 8)
        # set balance as new amount
        userswallet.currentbalance = floating_decimals(y, 8)
        # create the work
        wallet = MoneroWalletWorkStagenet(
            user_id=user_id,
            type=1,
            amount=amount,
            sendto=sendto,
            created=timestamp,

        )
        # save it
        db.session.add(wallet)
        db.session.add(userswallet)
        db.session.commit()

    else:
        add_new_notification(user_id=user_id,
                             subid=0,
                             subname='',
                             postid=0,
                             commentid=0,
                             msg=301)
Example #4
0
def comment_edit_text(commentid):
    editcommenttextform = EditCommentForm()
    if request.method == 'POST':
        if editcommenttextform.validate_on_submit():

            thecomment = db.session \
                .query(Comments) \
                .filter(Comments.id == int(commentid)) \
                .first()
            thesub = db.session \
                .query(SubForums) \
                .filter(thecomment.subcommon_id == SubForums.id) \
                .first()
            transformed_text, notifyuser = transform_image_links_markdown(str(editcommenttextform.postmessage.data))

            if notifyuser is not None:
                # add info
                add_new_notification(user_id=notifyuser.id,
                                     subid=thesub.id,
                                     subname=thesub.subcommon_name,
                                     postid=thecomment.commons_post_id,
                                     commentid=0,
                                     msg=32
                                     )
            # see if user is a creator
            if thecomment.user_id == current_user.id:
                thecomment.body = transformed_text
                db.session.add(thecomment)
                db.session.commit()
                flash("Updated Comment.", category="success")
                return redirect(url_for('subforum.viewpost',
                                        subname=thesub.subcommon_name,
                                        postid=thecomment.commons_post_id))
            else:
                flash("You are not the creator of this post.", category="danger")
                return redirect(url_for('subforum.viewpost',
                                        subname=thesub.subcommon_name,
                                        postid=thecomment.commons_post_id))
        else:
            for errors in editcommenttextform.postmessage.errors:
                flash(errors, category="danger")
            return redirect((request.args.get('next', request.referrer)))
Example #5
0
def create_message():
    now = datetime.utcnow()

    form = CreateAMsg()
    theposts = db.session.query(LegalMessages)
    theposts = theposts.filter(
        or_(LegalMessages.rec_user_id == current_user.id,
            LegalMessages.sender_user_id == current_user.id))
    theposts = theposts.order_by(LegalMessages.last_message.desc())
    posts = theposts.limit(100)

    if request.method == 'GET':

        return render_template('/legal/create_msg.html',
                               form=form,
                               posts=posts)

    if request.method == 'POST':

        the_user = User.query.filter(User.id == 1).first()
        if the_user is None:
            flash("User Not Found.  Did you spell it correctly?",
                  category="success")
            return redirect((url_for('legal.create_message')))

        if the_user.id == current_user.id:
            flash("Can not message yourself", category="success")
            return redirect((url_for('legal.create_message')))
        # see if blocked
        isuserblocked = BlockedUser.query.filter(
            BlockedUser.user_id == the_user.id,
            BlockedUser.blocked_user == current_user.id).first()

        isuserbeingblocked = BlockedUser.query.filter(
            BlockedUser.user_id == current_user.id,
            BlockedUser.blocked_user == the_user.id).first()
        if isuserblocked is not None or isuserbeingblocked is not None:
            flash("User isnt accepting messages.", category="danger")
            return redirect(url_for('index'))

        seeifpostexists = db.session.query(LegalMessages)
        seeifpostexists = seeifpostexists.filter(
            LegalMessages.sender_user_id == current_user.id)
        seeifpostexists = seeifpostexists.filter(
            LegalMessages.rec_user_id == the_user.id)
        seeifpostexists = seeifpostexists.first()

        if seeifpostexists is None:

            newmsg = LegalMessages(
                created=now,
                read_rec=1,
                read_send=0,
                msg_type=1,
                sender_user_id=current_user.id,
                sender_user_user_name=current_user.user_name,
                rec_user_id=1,
                rec_user_user_name='tipvote',
                body='',
                biz_id=None,
                biz_name='',
                last_message=now)
            db.session.add(newmsg)
            db.session.commit()

            newreply = LegalReply(
                created=now,
                message_id=newmsg.id,
                sender_user_id=current_user.id,
                sender_user_user_name=current_user.user_name,
                rec_user_id=1,
                rec_user_user_name='tipvote',
                body=form.postmessage.data,
                biz_id=None,
                biz_name='',
            )

            # add notification for poster about new comment
            add_new_notification(
                user_id=the_user.id,
                subid=0,
                subname='',
                postid=newmsg.id,
                commentid=0,
                msg=50,
            )

            db.session.add(newreply)
            db.session.commit()
            flash("Message Sent", category="success")
            return redirect((url_for('legal.main')))
        else:

            if seeifpostexists.rec_user_id == current_user.id:
                otheruserid = seeifpostexists.sender_user_id
                otherusername = seeifpostexists.sender_user_user_name

            elif seeifpostexists.sender_user_id == current_user.id:
                otheruserid = seeifpostexists.rec_user_id
                otherusername = seeifpostexists.rec_user_user_name
            else:
                otheruserid = current_user.id
                otherusername = current_user.id

            if seeifpostexists is not None:
                seeifpostexists.last_message = now

                if seeifpostexists.sender_user_id == current_user.id:
                    if seeifpostexists.read_send == 0:
                        seeifpostexists.read_send = 1

                        db.session.add(seeifpostexists)

                if seeifpostexists.rec_user_id == current_user.id:
                    if seeifpostexists.read_rec == 0:
                        seeifpostexists.read_rec = 1

                        db.session.add(seeifpostexists)

            newreply = LegalReply(
                created=now,
                message_id=seeifpostexists.id,
                sender_user_id=current_user.id,
                sender_user_user_name=current_user.user_name,
                rec_user_id=otheruserid,
                rec_user_user_name=otherusername,
                body=form.postmessage.data,
                biz_id=seeifpostexists.biz_id,
                biz_name=seeifpostexists.biz_name,
            )

            db.session.add(newreply)
            db.session.add(seeifpostexists)
            # add notification for poster about new comment
            add_new_notification(
                user_id=otheruserid,
                subid=0,
                subname='',
                postid=seeifpostexists.id,
                commentid=0,
                msg=55,
            )

            db.session.commit()

            flash("Reply Sent", category="success")
            return redirect((url_for('legal.view_message',
                                     msgid=seeifpostexists.id)))
Example #6
0
def reply_message(msgid):
    now = datetime.utcnow()

    form = ReplyToMsg()
    if request.method == 'POST':
        thepost = LegalMessages.query.filter(
            LegalMessages.id == msgid).first_or_404()

        if (thepost.rec_user_id == current_user.id) or (thepost.sender_user_id
                                                        == current_user.id):
            if thepost.rec_user_id == current_user.id:
                otheruserid = thepost.sender_user_id
                otherusername = thepost.sender_user_user_name

            elif thepost.sender_user_id == current_user.id:
                otheruserid = thepost.rec_user_id
                otherusername = thepost.rec_user_user_name
            else:
                otheruserid = current_user.id
                otherusername = current_user.id

            if request.method == 'POST':
                if thepost.rec_user_id == current_user.id:
                    if thepost.read_send == 0:
                        thepost.read_send = 1

                        db.session.add(thepost)

                if thepost.sender_user_id == current_user.id:
                    if thepost.read_rec == 0:
                        thepost.read_rec = 1

                        db.session.add(thepost)

                thepost.last_message = now
                newreply = LegalReply(
                    created=now,
                    message_id=msgid,
                    sender_user_id=current_user.id,
                    sender_user_user_name=current_user.user_name,
                    rec_user_id=otheruserid,
                    rec_user_user_name=otherusername,
                    body=form.postmessage.data,
                    biz_id=thepost.biz_id,
                    biz_name=thepost.biz_name,
                )

                db.session.add(newreply)
                db.session.add(thepost)
                # add notification for poster about new comment
                add_new_notification(
                    user_id=otheruserid,
                    subid=0,
                    subname='',
                    postid=msgid,
                    commentid=0,
                    msg=54,
                )

                db.session.commit()

                flash("Reply Sent", category="success")
                return redirect((url_for('legal.view_message',
                                         msgid=thepost.id)))
        else:

            flash("Message not found", category="danger")
            return redirect((url_for('index')))
    if request.method == 'GET':
        return redirect((url_for('index')))
Example #7
0
def post_edit_text(postid):
    now = datetime.utcnow()
    editposttextform = EditPostTextForm()
    id_pic1 = id_generator_picture1()

    thepost = db.session \
        .query(CommonsPost) \
        .filter(CommonsPost.id == int(postid)) \
        .first()

    if request.method == 'POST':

        if editposttextform.validate_on_submit():
            if editposttextform.delete.data:
                delete_image_server_one(user_id=current_user.id, postid=postid)
                return redirect((request.args.get('next', request.referrer)))

            if editposttextform.submit.data:
                urlfound, urltitlefound, urldescriptionfound, urlimagefound = geturl(editposttextform.postmessage.data)
                transformed_text, notifyuser = transform_image_links_markdown(str(editposttextform.postmessage.data))

                getpostnodelocation = postnodelocation(x=thepost.id)
                postlocation = os.path.join(UPLOADED_FILES_DEST,
                                            current_disk,
                                            "post",
                                            getpostnodelocation,
                                            str(thepost.id))
                thepost.post_text = transformed_text

                if urlfound:
                    delete_image_url_server(user_id=current_user.id, postid=postid)
                    thepost.url_image = urlimagefound
                    thepost.url_title = urltitlefound
                    thepost.url_of_post = urlfound
                    thepost.url_description = urldescriptionfound
                    post_get_image(url=thepost.url_image, imagelocation=postlocation, thepost=thepost)

                if editposttextform.image_one.data:
                    mkdir_p(path=postlocation)
                    filename = secure_filename(editposttextform.image_one.data.filename)
                    postimagefilepath = os.path.join(postlocation, filename)
                    editposttextform.image_one.data.save(postimagefilepath)
                    filenamenew, file_extension = os.path.splitext(postimagefilepath)
                    newfilename = id_pic1 + file_extension
                    filenamenewfull = filenamenew + file_extension
                    newfilenamedestination = os.path.join(postlocation, newfilename)
                    os.rename(filenamenewfull, newfilenamedestination)
                    post_convert_image(imagelocation=postlocation, imagename=newfilename, thepost=thepost)

                if notifyuser is not None:
                    # add info
                    add_new_notification(user_id=notifyuser.id,
                                         subid=thepost.subcommon_id,
                                         subname=thepost.subcommon_name,
                                         postid=thepost.id,
                                         commentid=0,
                                         msg=32
                                         )
            thepost.edited = now
            db.session.commit()

            flash("Post edited", category="success")
            return redirect(url_for('subforum.viewpost', subname=thepost.subcommon_name, postid=thepost.id))
        else:
            flash("form error")
            for errors in editposttextform.postmessage.errors:
                flash(errors, category="danger")
            return redirect((request.args.get('next', request.referrer)))
Example #8
0
def create_message_business(bizid):
    now = datetime.utcnow()

    form = CreateAMsgUser()
    the_biz = Business.query.filter(Business.id == bizid).first()

    if the_biz is None:
        flash(
            "Business is Not Found. Try Back Later or post this issue on /a/bugs",
            category="success")
        return redirect((url_for('index')))

    theposts = db.session.query(Messages)
    theposts = theposts.filter(
        or_(Messages.rec_user_id == current_user.id,
            Messages.sender_user_id == current_user.id))
    theposts = theposts.order_by(Messages.last_message.desc())
    posts = theposts.limit(100)

    seeifpostexists = db.session.query(Messages)
    seeifpostexists = seeifpostexists.filter(
        Messages.rec_user_id == current_user.id)
    seeifpostexists = seeifpostexists.filter(
        Messages.sender_user_id == the_biz.user_id)
    seeifpostexists = seeifpostexists.first()

    seeifotherpostexists = db.session.query(Messages)
    seeifotherpostexists = seeifotherpostexists.filter(
        Messages.sender_user_id == the_biz.user_id)
    seeifotherpostexists = seeifotherpostexists.filter(
        Messages.rec_user_id == current_user.id)
    seeifotherpostexists = seeifotherpostexists.first()

    if request.method == 'GET':
        return render_template('/msg/create_msg_biz.html',
                               form=form,
                               the_biz=the_biz,
                               posts=posts)

    if request.method == 'POST':

        if the_biz.user_id == current_user.id:
            flash("Can not message yourself", category="success")
            return redirect((url_for('message.create_message')))

        if seeifpostexists is None and seeifotherpostexists is None:

            newmsg = Messages(created=now,
                              read=0,
                              msg_type=2,
                              sender_user_id=current_user.id,
                              sender_user_user_name=current_user.user_name,
                              rec_user_id=the_biz.user_id,
                              rec_user_user_name=the_biz.user_name,
                              body='',
                              biz_id=the_biz.id,
                              biz_name=the_biz.business_name,
                              last_message=now)

            db.session.add(newmsg)
            db.session.commit()

            newreply = Reply(
                created=now,
                message_id=newmsg.id,
                sender_user_id=current_user.id,
                sender_user_user_name=current_user.user_name,
                rec_user_id=the_biz.user_id,
                rec_user_user_name=the_biz.user_name,
                body=form.postmessage.data,
                biz_id=the_biz.id,
                biz_name=the_biz.business_name,
            )

            # add notification for poster about new comment
            add_new_notification(
                user_id=the_biz.user_id,
                subid=0,
                subname='',
                postid=newmsg.id,
                commentid=0,
                msg=52,
            )

            db.session.add(newreply)
            db.session.commit()
            flash("Message Sent", category="success")
            return redirect((url_for('message.view_message', msgid=newmsg.id)))

        else:

            if seeifpostexists.rec_user_id == current_user.id:
                otheruserid = seeifpostexists.sender_user_id
                otherusername = seeifpostexists.sender_user_user_name

            elif seeifpostexists.sender_user_id == current_user.id:
                otheruserid = seeifpostexists.rec_user_id
                otherusername = seeifpostexists.rec_user_user_name
            else:
                otheruserid = current_user.id
                otherusername = current_user.id

            if seeifpostexists is not None:
                seeifpostexists.last_message = now

                if seeifpostexists.sender_user_id == current_user.id:
                    if seeifpostexists.read_send == 0:
                        seeifpostexists.read_send = 1

                        db.session.add(seeifpostexists)

                if seeifpostexists.rec_user_id == current_user.id:
                    if seeifpostexists.read_rec == 0:
                        seeifpostexists.read_rec = 1

                        db.session.add(seeifpostexists)

            if seeifotherpostexists is not None:

                seeifotherpostexists.last_message = now

                if seeifotherpostexists.sender_user_id == current_user.id:
                    if seeifpostexists.read_send == 0:
                        seeifpostexists.read_send = 1

                        db.session.add(seeifpostexists)

                if seeifpostexists.rec_user_id == current_user.id:
                    if seeifpostexists.read_rec == 0:
                        seeifpostexists.read_rec = 1

                        db.session.add(seeifpostexists)

            seeifpostexists.last_message = now
            newreply = Reply(
                created=now,
                message_id=seeifpostexists.id,
                sender_user_id=current_user.id,
                sender_user_user_name=current_user.user_name,
                rec_user_id=otheruserid,
                rec_user_user_name=otherusername,
                body=form.postmessage.data,
                biz_id=seeifpostexists.biz_id,
                biz_name=seeifpostexists.biz_name,
            )

            db.session.add(newreply)
            db.session.add(seeifpostexists)
            # add notification for poster about new comment
            add_new_notification(
                user_id=otheruserid,
                subid=0,
                subname='',
                postid=seeifpostexists.id,
                commentid=0,
                msg=51,
            )

            db.session.commit()

            flash("Reply Sent", category="success")
            return redirect((url_for('message.view_message',
                                     msgid=seeifpostexists.id)))
Example #9
0
def create_message_specific_user(user_name):
    now = datetime.utcnow()

    form = CreateAMsgUser()
    the_user = db.session \
        .query(User) \
        .filter(User.user_name == user_name) \
        .first()

    posts = db.session \
        .query(Messages) \
        .filter(or_(Messages.rec_user_id == current_user.id,
                    Messages.sender_user_id == current_user.id)) \
        .order_by(Messages.last_message.desc()) \
        .limit(100)

    seeifpostexists = db.session \
        .query(Messages) \
        .filter(Messages.rec_user_id == current_user.id) \
        .filter(Messages.sender_user_id == the_user.id) \
        .first()

    seeifotherpostexists = db.session \
        .query(Messages) \
        .filter(Messages.sender_user_id == the_user.id) \
        .filter(Messages.rec_user_id == current_user.id) \
        .first()

    if the_user is None:
        flash("User is Not Found.  Did you spell it correctly?",
              category="success")
        return redirect((url_for('message.create_message_specific_user',
                                 user_name=user_name)))

    if request.method == 'GET':
        return render_template(
            '/msg/create_msg_user.html',
            form=form,
            the_user=the_user,
            posts=posts,
        )

    if request.method == 'POST':
        # see if blocked
        isuserblocked = db.session \
            .query(BlockedUser) \
            .filter(BlockedUser.user_id == the_user.id,
                    BlockedUser.blocked_user == current_user.id) \
            .first()

        isuserbeingblocked = db.session \
            .query(BlockedUser) \
            .filter(BlockedUser.user_id == current_user.id,
                    BlockedUser.blocked_user == the_user.id) \
            .first()
        if isuserblocked is not None or isuserbeingblocked is not None:
            flash("User isnt accepting messages.", category="danger")
            return redirect(url_for('index'))

        if the_user.id == current_user.id:
            flash("Can not message yourself", category="success")
            return redirect((url_for('message.create_message')))

        if seeifpostexists is None and seeifotherpostexists is None:

            newmsg = Messages(created=now,
                              read_rec=1,
                              read_send=0,
                              msg_type=1,
                              sender_user_id=current_user.id,
                              sender_user_user_name=current_user.user_name,
                              rec_user_id=the_user.id,
                              rec_user_user_name=the_user.user_name,
                              body='',
                              biz_id=None,
                              biz_name='',
                              last_message=now)

            db.session.add(newmsg)
            db.session.commit()

            newreply = Reply(
                created=now,
                message_id=newmsg.id,
                sender_user_id=current_user.id,
                sender_user_user_name=current_user.user_name,
                rec_user_id=the_user.id,
                rec_user_user_name=the_user.user_name,
                body=form.postmessage.data,
                biz_id=None,
                biz_name='',
            )

            # add notification for poster about new comment
            add_new_notification(
                user_id=the_user.id,
                subid=0,
                subname='',
                postid=newmsg.id,
                commentid=0,
                msg=50,
            )

            db.session.add(newreply)
            db.session.commit()
            flash("Message Sent", category="success")
            return redirect((url_for('message.view_message', msgid=newmsg.id)))

        else:

            if seeifpostexists.rec_user_id == current_user.id:
                otheruserid = seeifpostexists.sender_user_id
                otherusername = seeifpostexists.sender_user_user_name

            elif seeifpostexists.sender_user_id == current_user.id:
                otheruserid = seeifpostexists.rec_user_id
                otherusername = seeifpostexists.rec_user_user_name
            else:
                otheruserid = current_user.id
                otherusername = current_user.id

            if seeifpostexists is not None:
                seeifpostexists.last_message = now

                if seeifpostexists.sender_user_id == current_user.id:
                    if seeifpostexists.read_send == 0:
                        seeifpostexists.read_send = 1

                        db.session.add(seeifpostexists)

                if seeifpostexists.rec_user_id == current_user.id:
                    if seeifpostexists.read_rec == 0:
                        seeifpostexists.read_rec = 1

                        db.session.add(seeifpostexists)

            if seeifotherpostexists is not None:
                seeifotherpostexists.last_message = now

                if seeifotherpostexists.sender_user_id == current_user.id:
                    if seeifpostexists.read_send == 0:
                        seeifpostexists.read_send = 1

                        db.session.add(seeifpostexists)

                if seeifpostexists.rec_user_id == current_user.id:
                    if seeifpostexists.read_rec == 0:
                        seeifpostexists.read_rec = 1

                        db.session.add(seeifpostexists)

            seeifpostexists.last_message = now
            newreply = Reply(
                created=now,
                message_id=seeifpostexists.id,
                sender_user_id=current_user.id,
                sender_user_user_name=current_user.user_name,
                rec_user_id=otheruserid,
                rec_user_user_name=otherusername,
                body=form.postmessage.data,
                biz_id=seeifpostexists.biz_id,
                biz_name=seeifpostexists.biz_name,
            )

            db.session.add(newreply)
            db.session.add(seeifpostexists)
            # add notification for poster about new comment
            add_new_notification(
                user_id=otheruserid,
                subid=0,
                subname='',
                postid=seeifpostexists.id,
                commentid=0,
                msg=51,
            )

            db.session.commit()

            flash("Reply Sent", category="success")
            return redirect((url_for('message.view_message',
                                     msgid=seeifpostexists.id)))
Example #10
0
def create_post_room_all(userid):

    now = datetime.utcnow()
    id_pic1 = id_generator_picture1()
    wall_post_form = MainPostForm()
    uniqueid = id_generator(size=15)

    if request.method == 'POST':

        usersubforums = db.session \
            .query(Subscribed) \
            .join(SubForums, (Subscribed.subcommon_id == SubForums.id)) \
            .filter(current_user.id == Subscribed.user_id) \
            .all()

        wall_post_form.roomname.choices = [(str(row.subscriber.id),
                                            str(row.subscriber.subcommon_name))
                                           for row in usersubforums]

        theuser = User.query \
            .filter(User.id == userid) \
            .first()
        getuser_timers = db.session \
            .query(UserTimers) \
            .filter_by(user_id=current_user.id) \
            .first()
        user_stats = db.session \
            .query(UserStats) \
            .filter(UserStats.user_id == current_user.id) \
            .first()

        if wall_post_form.validate_on_submit():

            # see if user posted comment
            if wall_post_form.post_message.data == '':
                score_1 = 0
            else:
                score_1 = 1
            if wall_post_form.image_one.data:
                score_2 = 1
            else:
                score_2 = 0
            total_score = score_1 + score_2

            if total_score == 0:
                flash("You need to post some content", category="success")
                return redirect((request.args.get('next', request.referrer)))

            getmatchingsubcommon = db.session \
                .query(SubForums) \
                .filter(SubForums.id == int(wall_post_form.roomname.data)) \
                .first()

            chosen_subcommon_id = getmatchingsubcommon.id
            chosen_subcommon_name = getmatchingsubcommon.subcommon_name

            newpostnumber = user_stats.total_posts + 1

            urlfound, urltitlefound, urldescriptionfound, urlimagefound = \
                geturl(wall_post_form.post_message.data)
            transformed_text, notifyuser = \
                transform_image_links_markdown(str(wall_post_form.post_message.data))
            # add post to db
            newpost = CommonsPost(
                title=wall_post_form.post_title.data,
                user_id=theuser.id,
                user_name=theuser.user_name,

                # location
                realid=uniqueid,
                subcommon_id=chosen_subcommon_id,
                subcommon_name=chosen_subcommon_name,
                type_of_post=0,

                # text
                post_text=transformed_text,

                # url
                url_of_post=urlfound,
                url_description=urldescriptionfound,
                url_image=urlimagefound,
                url_title=urltitlefound,
                url_image_server='',

                # images
                image_server_1='',

                # stats
                total_exp_commons=0,
                highest_exp_reached=0,
                upvotes_on_post=0,
                comment_count=0,
                vote_timestamp=now,
                last_active=now,
                hotness_rating_now=0,
                page_views=0,

                # admin
                sticky=0,
                active=1,
                locked=0,
                hidden=0,
                muted=0,
                created=now,
                edited=now,
            )

            getuser_timers.last_post = now
            user_stats.total_posts = newpostnumber

            db.session.add(user_stats)
            db.session.add(getuser_timers)
            db.session.add(newpost)
            db.session.commit()

            getusernodelocation = postnodelocation(x=newpost.id)
            postlocation = os.path.join(UPLOADED_FILES_DEST, current_disk,
                                        "post", getusernodelocation,
                                        str(newpost.id))

            # image from url
            if urlfound:
                post_get_image(url=newpost.url_image,
                               imagelocation=postlocation,
                               thepost=newpost)

            # image From User
            if wall_post_form.image_one.data:
                mkdir_p(path=postlocation)
                filename = secure_filename(
                    wall_post_form.image_one.data.filename)
                postimagefilepath = os.path.join(postlocation, filename)
                wall_post_form.image_one.data.save(postimagefilepath)
                # split file name and ending
                filenamenew, file_extension = os.path.splitext(
                    postimagefilepath)
                # gets new 64 digit filename
                newfilename = id_pic1 + file_extension
                # puts new name with ending
                filenamenewfull = filenamenew + file_extension
                # gets aboslute path of new file
                newfilenamedestination = os.path.join(postlocation,
                                                      newfilename)
                # renames file
                os.rename(filenamenewfull, newfilenamedestination)
                post_convert_image(imagelocation=postlocation,
                                   imagename=newfilename,
                                   thepost=newpost)

            if wall_post_form.image_one.data \
                    or (urlimagefound is not None and urlfound is not None):
                db.session.commit()

            if notifyuser is not None:
                # add info
                add_new_notification(user_id=notifyuser.id,
                                     subid=newpost.subcommon_id,
                                     subname=newpost.subcommon_name,
                                     postid=newpost.id,
                                     commentid=0,
                                     msg=32)

            # add exp points
            exppoint(user_id=current_user.id, category=1)

            return redirect((url_for('subforum.viewpost',
                                     subname=newpost.subcommon_name,
                                     postid=newpost.id)))
        else:

            flash("Post Creation Failure.", category="danger")
            for errors in wall_post_form.roomname.errors:
                flash(errors, category="danger")
            for errors in wall_post_form.post_message.errors:
                flash(
                    "Message Failure...a message is required and 3- 5000 characters",
                    category="danger")
                flash(errors, category="danger")
            for errors in wall_post_form.image_one.errors:
                flash(errors, category="danger")
            return redirect((request.args.get('next', request.referrer)))
Example #11
0
def create_tip_post_bch(subname, postid):
    """
    Creates a bch tip for a post
    """
    form_bch = CreateTipBCH()
    now = datetime.utcnow()

    # get the sub, post, comment
    thesub = db.session\
        .query(SubForums)\
        .filter(SubForums.subcommon_name == subname)\
        .first()
    post = db.session\
        .query(CommonsPost)\
        .get(postid)

    if post.shared_post != 0:
        idofpost = post.shared_post
    else:
        idofpost = post.id

    if thesub is None:
        flash("Sub does not exist", category="success")
        return redirect((request.args.get('next', request.referrer)))
    if post is None:
        flash("The post has been removed or doesnt exist", category="success")
        return redirect((request.args.get('next', request.referrer)))
    if post.hidden == 1:
        flash("Post Has been deleted", category="success")
        return redirect((request.args.get('next', request.referrer)))

    # get user stats
    changeuserbchstats = db.session\
        .query(UserStatsBCH)\
        .filter_by(user_id=current_user.id)\
        .first()
    # get poster stats
    changeposterbchstats = db.session\
        .query(UserStatsBCH)\
        .filter_by(user_id=post.content_user_id)\
        .first()
    if request.method == 'POST':
        if form_bch.validate_on_submit():
            # check to see if tipper != poster
            if post.content_user_id != current_user.id:

                # get amount donatred
                getcurrentprice = db.session\
                    .query(BchPrices)\
                    .get(1)
                bch_current_price_usd = getcurrentprice.price

                usercoinsamount = db.session\
                    .query(BchWallet)\
                    .filter(BchWallet.user_id == current_user.id)\
                    .first()

                if form_bch.submit.data:
                    seeifcoin = re.compile(btcamount)
                    doesitmatch = seeifcoin.match(form_bch.custom_amount.data)
                    varidoftip = 0
                    variable_amount = True
                    if doesitmatch:
                        bch_amount_for_submission = Decimal(
                            form_bch.custom_amount.data)
                        decimalform_of_amount = floating_decimals(
                            bch_amount_for_submission, 8)
                        bch_amount = decimalform_of_amount

                        # get usd amount
                        bt = (Decimal(getcurrentprice.price) * bch_amount)
                        formatteddollar = '{0:.2f}'.format(bt)
                        usd_amount = formatteddollar
                    else:
                        flash(
                            "Invalid coin amount.  Did you enter the amount wrong?",
                            category="danger")
                        return redirect(
                            url_for('tip.create_tip_post',
                                    subname=subname,
                                    postid=postid))

                elif form_bch.cent.data:
                    bch_amount = Decimal(0.01) / Decimal(bch_current_price_usd)
                    usd_amount = 0.01
                    varidoftip = 0
                    variable_amount = True

                elif form_bch.quarter.data:
                    bch_amount = Decimal(0.25) / Decimal(bch_current_price_usd)
                    usd_amount = 0.25
                    varidoftip = 0
                    variable_amount = True

                elif form_bch.dollar.data:
                    bch_amount = Decimal(1.00) / Decimal(bch_current_price_usd)
                    usd_amount = 1.00
                    varidoftip = 0
                    variable_amount = True

                elif form_bch.five_dollar.data:
                    bch_amount = Decimal(5.00) / Decimal(bch_current_price_usd)
                    usd_amount = 5.00
                    varidoftip = 0
                    variable_amount = True

                elif form_bch.ten_dollar.data:
                    bch_amount = Decimal(10.00) / Decimal(
                        bch_current_price_usd)
                    usd_amount = 10.00
                    varidoftip = 0
                    variable_amount = True

                elif form_bch.twentyfive_dollar.data:
                    bch_amount = Decimal(25.00) / Decimal(
                        bch_current_price_usd)
                    usd_amount = 25.00
                    varidoftip = 0
                    variable_amount = True

                elif form_bch.hundred_dollar.data:
                    bch_amount = Decimal(100.00) / Decimal(
                        bch_current_price_usd)
                    usd_amount = 100.00
                    varidoftip = 0
                    variable_amount = True

                elif form_bch.seven_zero.data:
                    bch_amount = Decimal(0.00000001)
                    usd_amount = 0.00
                    variable_amount = False
                    varidoftip = 1

                elif form_bch.six_zero.data:
                    bch_amount = Decimal(0.00000010)
                    usd_amount = 0.00
                    varidoftip = 2
                    variable_amount = False

                elif form_bch.five_zero.data:
                    bch_amount = Decimal(0.00000100)
                    usd_amount = 0.00
                    varidoftip = 3
                    variable_amount = False

                else:
                    flash("Tip Failure.", category="success")
                    return redirect(
                        url_for('tip.create_tip_post',
                                subname=subname,
                                postid=postid))

                final_amount = (floating_decimals(bch_amount, 8))
                lowestdonation = 0.00000100
                if final_amount >= lowestdonation:
                    percent_to_subowner = 0.07
                    payout = 1
                else:
                    percent_to_subowner = 0
                    payout = 0

                if Decimal(usercoinsamount.currentbalance) >= Decimal(
                        final_amount):
                    if variable_amount is True:
                        # btc amount
                        amount_to_subowner = Decimal(final_amount) * Decimal(
                            percent_to_subowner)
                        # get usd amount
                        subownerbt = (Decimal(getcurrentprice.price) *
                                      amount_to_subowner)
                        subownerformatteddollar = '{0:.2f}'.format(subownerbt)
                        subowner_usd_amount = float(subownerformatteddollar)

                        # Btc amount
                        amount_to_poster = Decimal(final_amount) - Decimal(
                            amount_to_subowner)
                        # get usd amount
                        posterbt = (Decimal(getcurrentprice.price) *
                                    bch_amount)
                        posterformatteddollar = '{0:.2f}'.format(posterbt)
                        poster_usd_amount = float(posterformatteddollar)
                    else:
                        if varidoftip == 1:
                            # btc_amount = 0.00000001
                            poster_usd_amount = 0.00
                            amount_to_poster = Decimal(0.00000001)
                            amount_to_subowner = Decimal(0)
                            subowner_usd_amount = 0.00

                        elif varidoftip == 2:
                            # btc_amount = 0.00000010
                            poster_usd_amount = 0.00
                            amount_to_poster = Decimal(0.00000009)
                            amount_to_subowner = Decimal(0.00000001)
                            subowner_usd_amount = 0.00

                        elif varidoftip == 3:
                            # btc_amount = 0.00000100
                            poster_usd_amount = 0.00
                            amount_to_poster = Decimal(0.00000093)
                            amount_to_subowner = Decimal(0.00000007)
                            subowner_usd_amount = 0.00

                        else:
                            poster_usd_amount = 0.00
                            amount_to_poster = Decimal(0.00000000)
                            amount_to_subowner = Decimal(0)
                            subowner_usd_amount = 0.00

                    if payout == 1:
                        # subowner gets payout
                        newpayout = PayoutSubOwner(
                            created=now,
                            subcommon_id=thesub.id,
                            subcommon_name=thesub.subcommon_name,
                            post_id=post.id,
                            comment_id=0,
                            sub_owner_user_id=thesub.creator_user_id,
                            sub_owner_user_name=thesub.creator_user_name,
                            tipper_user_id=current_user.id,
                            tipper_user_name=current_user.user_name,
                            currency_type=2,
                            amount_bch=amount_to_subowner,
                            amount_usd=subowner_usd_amount,
                        )
                        db.session.add(newpayout)

                    createnewtip = BchPostTips(
                        created=now,
                        created_user_id=current_user.id,
                        created_user_name=current_user.user_name,
                        recieved_user_id=post.content_user_id,
                        recieved_user_name=post.content_user_name,
                        subcommon_id=thesub.id,
                        subcommon_name=thesub.subcommon_name,
                        post_id=idofpost,
                        amount_bch=amount_to_poster,
                        amount_usd=poster_usd_amount,
                    )

                    createrecenttip = RecentTips(
                        created=now,
                        created_user_id=current_user.id,
                        created_user_name=current_user.user_name,
                        recieved_user_id=post.content_user_id,
                        recieved_user_name=post.content_user_name,
                        subcommon_id=thesub.id,
                        subcommon_name=thesub.subcommon_name,
                        post_id=idofpost,
                        comment_id=0,
                        currency_type=2,
                        amount_bch=amount_to_poster,
                        amount_usd=poster_usd_amount,
                    )

                    # add stats to user who donated
                    current_amount_donated_to_comments = changeuserbchstats.total_donated_to_postcomments_bch
                    newamount = (floating_decimals(
                        current_amount_donated_to_comments + final_amount, 8))
                    changeuserbchstats.total_donated_to_postcomments_bch = newamount
                    current_amount_donated_to_comments_usd = changeuserbchstats.total_donated_to_postcomments_usd
                    newamount_usd = (floating_decimals(
                        current_amount_donated_to_comments_usd +
                        Decimal(usd_amount), 2))
                    changeuserbchstats.total_donated_to_postcomments_usd = newamount_usd

                    # add stats to user who recieved coin
                    current_amount_recieved_to_posts = changeposterbchstats.total_recievedfromposts_bch
                    newamount_poster = (floating_decimals(
                        current_amount_recieved_to_posts + amount_to_poster,
                        8))
                    changeposterbchstats.total_recievedfromposts_bch = newamount_poster
                    current_amount_recieved_to_posts_usd = changeposterbchstats.total_recievedfromposts_usd
                    newamount_poster_usd = (floating_decimals(
                        current_amount_recieved_to_posts_usd +
                        Decimal(poster_usd_amount), 2))
                    changeposterbchstats.total_recievedfromposts_usd = newamount_poster_usd

                    seeifpostdonates = db.session\
                        .query(PostDonations)\
                        .filter(PostDonations.post_id == idofpost)\
                        .first()
                    if seeifpostdonates is None:

                        addstatstopost = PostDonations(
                            post_id=idofpost,
                            total_recieved_btc=0,
                            total_recieved_btc_usd=0,
                            total_recieved_bch=final_amount,
                            total_recieved_bch_usd=usd_amount,
                        )
                        db.session.add(addstatstopost)
                    else:
                        # modify comments to show it got btc
                        current_post_bch_amount = seeifpostdonates.total_recieved_bch
                        current_amount_bch_usd_amount = seeifpostdonates.total_recieved_bch_usd
                        newamount_for_post = (floating_decimals(
                            current_post_bch_amount + amount_to_poster, 8))
                        newamount_for_post_usd = (floating_decimals(
                            current_amount_bch_usd_amount +
                            Decimal(poster_usd_amount), 2))
                        seeifpostdonates.total_recieved_bch = newamount_for_post
                        seeifpostdonates.total_recieved_bch_usd = newamount_for_post_usd

                        db.session.add(seeifpostdonates)

                    add_new_notification(user_id=post.content_user_id,
                                         subid=thesub.id,
                                         subname=thesub.subcommon_name,
                                         postid=idofpost,
                                         commentid=0,
                                         msg=20)

                    if payout == 1:
                        add_new_notification(user_id=thesub.creator_user_id,
                                             subid=thesub.id,
                                             subname=thesub.subcommon_name,
                                             postid=post.id,
                                             commentid=0,
                                             msg=26)

                    # add exp points to donater
                    exppoint(user_id=current_user.id, category=5)
                    # add exp points to reciever
                    exppoint(user_id=post.content_user_id, category=6)

                    # create Wallet Transaction for both users
                    take_coin_from_tipper_bch_post(
                        sender_id=current_user.id,
                        amount=final_amount,
                        postid=idofpost,
                        recieverid=post.content_user_id)

                    # create Wallet Transaction for both users
                    sendcoin_to_poster_bch_post(
                        sender_id=current_user.id,
                        amount=amount_to_poster,
                        postid=idofpost,
                        recieverid=post.content_user_id)

                    if payout == 1:
                        # create Wallet Transaction for both users
                        sendcoin_subowner_bch_post(
                            sender_id=current_user.id,
                            amount=amount_to_subowner,
                            postid=idofpost,
                            recieverid=thesub.creator_user_id)
                    # daily challnge
                    if current_user.is_authenticated:
                        daily_challenge(user_id=current_user.id, category=7)

                    post.last_active = now
                    post.active = 1

                    db.session.add(createrecenttip)
                    db.session.add(createnewtip)
                    db.session.add(post)
                    db.session.add(changeposterbchstats)
                    db.session.add(changeuserbchstats)
                    db.session.commit()

                    flash("Tip was successful.", category="success")
                    return redirect(
                        url_for('subforum.viewpost',
                                subname=thesub.subcommon_name,
                                postid=post.id))
                else:
                    flash("Insufficient Funds.", category="danger")
                    return redirect(
                        url_for('tip.create_tip_post',
                                subname=subname,
                                postid=postid))
            else:
                flash(
                    "Cannot tip yourself.  You can promote your posts to boost visibility.  ",
                    category="success")
                return redirect(
                    url_for('subforum.viewpost',
                            subname=thesub.subcommon_name,
                            postid=post.id))
        else:
            flash("Invalid Form", category="success")
            return redirect(
                url_for('subforum.viewpost',
                        subname=thesub.subcommon_name,
                        postid=post.id))
    return redirect(
        url_for('subforum.viewpost',
                subname=thesub.subcommon_name,
                postid=post.id))
Example #12
0
def promotepost_xmr(subname, postid):
    """
    Promotes a post
    # xmr
    """
    if request.method == 'POST':
        form_xmr = CreatePromotePostXmr()
        now = datetime.utcnow()

        # get the sub, post, comment
        thesub = db.session.query(SubForums).filter(
            SubForums.subcommon_name == subname).first()
        post = db.session.query(CommonsPost).get(postid)

        # see if user has enough
        userwallet_xmr = db.session.query(MoneroWallet)
        userwallet_xmr = userwallet_xmr.filter(
            MoneroWallet.user_id == current_user.id)
        userwallet_xmr = userwallet_xmr.first()

        # get amount donated
        getcurrentprice_xmr = db.session.query(MoneroPrices).get(1)
        xmr_current_price_usd = getcurrentprice_xmr.price

        if post.shared_post != 0:
            idofpost = post.shared_post
        else:
            idofpost = post.id

        seeifpostpromotions = PostPromotions.query.\
            filter(PostPromotions.post_id == idofpost)\
            .first()
        if thesub is None:
            flash("Sub does not exist.", category="success")
            return redirect(url_for('index'))
        if post is None:
            flash("Post does not exist.", category="success")
            return redirect(
                url_for('subforum.sub', subname=thesub.subcommon_name))
        if post.hidden == 1:
            flash("Post has been removed.", category="success")
            return redirect(
                url_for('subforum.sub', subname=thesub.subcommon_name))
        # get user stats
        if form_xmr.validate_on_submit():

            if form_xmr.submit.data:
                seeifcoin = re.compile(btcamount)
                doesitmatch = seeifcoin.match(form_xmr.custom_amount.data)
                if doesitmatch:
                    xmr_amount_for_submission = Decimal(
                        form_xmr.custom_amount.data)
                    decimalform_of_amount = floating_decimals(
                        xmr_amount_for_submission, 12)

                    xmr_amount = decimalform_of_amount

                    # get usd amount
                    getcurrentprice = db.session.query(MoneroPrices).get(1)
                    bt = (Decimal(getcurrentprice.price) * xmr_amount)
                    formatteddollar = '{0:.2f}'.format(bt)
                    usd_amount = formatteddollar
                else:
                    flash(
                        "Invalid Amount.  Did you not enter the amount correctly?",
                        category="danger")
                    return redirect(
                        url_for('promote.promotepost',
                                subname=subname,
                                postid=postid))

            elif form_xmr.cent_xmr.data:
                xmr_amount = Decimal(0.01) / Decimal(xmr_current_price_usd)
                usd_amount = 0.01

            elif form_xmr.quarter_xmr.data:
                xmr_amount = Decimal(0.25) / Decimal(xmr_current_price_usd)
                usd_amount = 0.25

            elif form_xmr.dollar_xmr.data:
                xmr_amount = Decimal(1.00) / Decimal(xmr_current_price_usd)
                usd_amount = 1.00

            elif form_xmr.five_dollar_xmr.data:
                xmr_amount = Decimal(5.00) / Decimal(xmr_current_price_usd)
                usd_amount = 5.00

            elif form_xmr.ten_dollar_xmr.data:
                xmr_amount = Decimal(10.00) / Decimal(xmr_current_price_usd)
                usd_amount = 10.00

            elif form_xmr.twentyfive_dollar_xmr.data:
                xmr_amount = Decimal(25.00) / Decimal(xmr_current_price_usd)
                usd_amount = 25.00

            elif form_xmr.hundred_dollar_xmr.data:
                xmr_amount = Decimal(100.00) / Decimal(xmr_current_price_usd)
                usd_amount = 100.00
            else:
                flash("Post Promotion Failure.", category="success")
                return redirect(url_for('index'))

            final_amount_xmr = (floating_decimals(xmr_amount, 12))

            if Decimal(userwallet_xmr.currentbalance) >= Decimal(xmr_amount):
                if final_amount_xmr > 0:

                    createnewpomotion = PostPromote(
                        created=now,
                        created_user_id=current_user.id,
                        created_user_name=current_user.user_name,
                        subcommon_id=thesub.id,
                        subcommon_name=thesub.subcommon_name,
                        post_id=idofpost,
                        amount_bch=0,
                        amount_btc=0,
                        amount_xmr=final_amount_xmr,
                        amount_usd=usd_amount)
                    db.session.add(createnewpomotion)
                    db.session.commit()

                    changeuserxmrstats = db.session.query(UserStatsXMR)\
                        .filter_by(user_id=current_user.id)\
                        .first()

                    # add stats to user who donated
                    # coin
                    current_amount_donated_to_posts = changeuserxmrstats.total_donated_to_postcomments_xmr
                    newamount = (floating_decimals(
                        current_amount_donated_to_posts + final_amount_xmr,
                        12))
                    changeuserxmrstats.total_donated_to_postcomments_xmr = newamount
                    # usd
                    current_amount_donated_to_posts_usd = changeuserxmrstats.total_donated_to_postcomments_usd
                    newamount_usd = (floating_decimals(
                        current_amount_donated_to_posts_usd +
                        Decimal(usd_amount), 2))
                    changeuserxmrstats.total_donated_to_postcomments_usd = newamount_usd

                    if seeifpostpromotions is None:
                        addstatstopost = PostPromotions(
                            post_id=idofpost,
                            total_recieved_bch=0,
                            total_recieved_bch_usd=0,
                            total_recieved_btc=0,
                            total_recieved_btc_usd=0,
                            total_recieved_xmr=final_amount_xmr,
                            total_recieved_xmr_usd=usd_amount,
                        )
                        db.session.add(addstatstopost)
                    else:

                        # modify post to show it got xmr
                        current_post_xmr_amount = seeifpostpromotions.total_recieved_xmr
                        current_amount_xmr_usd_amount = seeifpostpromotions.total_recieved_xmr_usd
                        newamount_for_post = (floating_decimals(
                            current_post_xmr_amount + final_amount_xmr, 12))
                        newamount_for_post_usd = (floating_decimals(
                            current_amount_xmr_usd_amount +
                            Decimal(usd_amount), 2))
                        # set post to active and update post
                        seeifpostpromotions.total_recieved_xmr = newamount_for_post
                        seeifpostpromotions.total_recieved_xmr_usd = newamount_for_post_usd

                        db.session.add(seeifpostpromotions)

                    # create Wallet Transaction for both users
                    sendcointosite_post_promotion_xmr(
                        sender_id=current_user.id,
                        amount=final_amount_xmr,
                        postid=postid,
                        room=subname)
                    post.active = 1
                    post.last_active = now

                    db.session.add(post)
                    db.session.add(changeuserxmrstats)

                    # daily challnge
                    if current_user.is_authenticated:
                        daily_challenge(user_id=current_user.id, category=6)

                    # send notification you got a coin promotion
                    add_new_notification(
                        user_id=post.poster_user_id,
                        subid=post.subcommon_id,
                        subname=post.subcommon_name,
                        postid=post.id,
                        commentid=0,
                        msg=62,
                    )

                    db.session.commit()

                    flash(
                        "Successfully Promoted Post with Monero. In a few minutes the score will be updated.",
                        category="success")
                    return redirect(
                        url_for('subforum.viewpost',
                                subname=thesub.subcommon_name,
                                postid=post.id))
                else:
                    flash("Invalid Amount.", category="danger")
                    return redirect(
                        url_for('promote.promotepost',
                                subname=subname,
                                postid=postid))
            else:
                flash("Not enough coin in your wallet.", category="danger")
                return redirect(
                    url_for('promote.promotepost',
                            subname=subname,
                            postid=postid))
        else:
            flash("Invalid Amount.", category="danger")
            return redirect(
                url_for('promote.promotepost', subname=subname, postid=postid))
Example #13
0
def promotepost_coin(subname, postid, coinid):
    """
    Promotes a post
    """

    if request.method == 'POST':

        givecoinform = GiveCoin()

        # get the sub, post, comment
        thesub = db.session.query(SubForums).filter(
            SubForums.subcommon_name == subname).first()
        post = CommonsPost.query.get(postid)

        if post.shared_post != 0:
            idofpost = post.shared_post
        else:
            idofpost = post.id

        thecoins = PostCoins.query.filter(
            PostCoins.post_id == idofpost).first()

        if thesub is None:
            flash("Sub does not exist.", category="success")
            return redirect(url_for('index'))
        if post is None:
            flash("Post does not exist.", category="success")
            return redirect(
                url_for('subforum.sub', subname=thesub.subcommon_name))
        if post.hidden == 1:
            flash("Post has been removed.", category="success")
            return redirect(
                url_for('subforum.sub', subname=thesub.subcommon_name))
        # get user stats
        if givecoinform.validate_on_submit():
            usercoin = db.session.query(UserCoins).filter(
                UserCoins.coin_id == coinid,
                UserCoins.user_id == current_user.id).first()

            if usercoin is not None:
                # give coin to post
                if thecoins is None:
                    newcoinstable = PostCoins(
                        post_id=idofpost,
                        coin_1=0,
                        coin_2=0,
                        coin_3=0,
                        coin_4=0,
                        coin_5=0,
                        coin_6=0,
                        coin_7=0,
                        coin_8=0,
                        coin_9=0,
                        coin_10=0,
                    )
                    db.session.add(newcoinstable)
                    db.session.commit()

                thecoins = PostCoins.query.filter(
                    PostCoins.post_id == idofpost).first_or_404()

                if coinid == 1:
                    new_amount = thecoins.coin_1 + 1
                    thecoins.coin_1 = new_amount
                elif coinid == 2:
                    new_amount = thecoins.coin_2 + 1
                    thecoins.coin_2 = new_amount
                elif coinid == 3:
                    new_amount = thecoins.coin_3 + 1
                    thecoins.coin_3 = new_amount
                elif coinid == 4:
                    new_amount = thecoins.coin_4 + 1
                    thecoins.coin_4 = new_amount
                elif coinid == 5:
                    new_amount = thecoins.coin_5 + 1
                    thecoins.coin_5 = new_amount
                elif coinid == 6:
                    new_amount = thecoins.coin_6 + 1
                    thecoins.coin_6 = new_amount
                elif coinid == 7:
                    new_amount = thecoins.coin_7 + 1
                    thecoins.coin_7 = new_amount
                elif coinid == 8:
                    new_amount = thecoins.coin_8 + 1
                    thecoins.coin_8 = new_amount
                elif coinid == 9:
                    new_amount = thecoins.coin_9 + 1
                    thecoins.coin_9 = new_amount
                else:
                    flash("Coin Does not exist", category="success")
                    return redirect(
                        url_for('subforum.viewpost',
                                subname=thesub.subcommon_name,
                                postid=post.id))
                db.session.add(post)

                # subtract or delete users coin

                currentcoinamount = usercoin.quantity - 1

                if currentcoinamount == 0:

                    db.session.delete(usercoin)
                    db.session.commit()
                else:

                    usercoin.quantity = currentcoinamount
                    db.session.add(usercoin)
                    db.session.commit()
                # daily challnge
                if current_user.is_authenticated:
                    daily_challenge(user_id=current_user.id, category=5)

                # send notification you got a coin promotion
                add_new_notification(
                    user_id=post.poster_user_id,
                    subid=post.subcommon_id,
                    subname=post.subcommon_name,
                    postid=post.id,
                    commentid=0,
                    msg=60,
                )

                # commit
                db.session.commit()
                flash("You have promoted the post!", category="success")
                return redirect(
                    url_for('subforum.viewpost',
                            subname=thesub.subcommon_name,
                            postid=post.id))
            else:
                flash("You do not have this coin to give", category="success")
                return redirect(
                    url_for('subforum.viewpost',
                            subname=thesub.subcommon_name,
                            postid=post.id))
        else:
            flash("Invalid Form", category="success")
            return redirect(
                url_for('subforum.viewpost',
                        subname=thesub.subcommon_name,
                        postid=post.id))