Exemplo n.º 1
0
def new():
    if not UserMaster.is_auntethicated():
        return flask.redirect("/login")
    elif flask.request.method == 'GET':
        headers = {
            "main":
            "New Discussion",
            "brand":
            SvgMaster.getFullLogo(),
            "menu":
            JsonMaster.htmlifyFile("./templates/json-templates/menu.json",
                                   {"activated": ["forum"]}),
            "user":
            UserMaster.get_userBar()
        }
        return flask.render_template("general-templates/new-discussion.html",
                                     title=headers['main'],
                                     headers=headers)
    elif flask.request.method == 'POST':
        data = flask.request.json
        disc = Discussion()
        disc.author_id = UserMaster.get_user().id
        disc.header = data['header']

        session = Session.create_session()
        session.add(disc)
        disc = session.query(Discussion).filter(
            Discussion.header == data['header'],
            Discussion.author_id == UserMaster.get_user().id).all()[-1]
        disc.init_file()
        disc.set_file(data)
        session.query(Discussion).filter(Discussion.id == disc.id).update(
            disc.to_dict())
        session.commit()
    return "end"
Exemplo n.º 2
0
 def get_tags(self):
     from app.alchemy import session as Session
     from app.alchemy.models.tags import Tag
     from json import loads
     session = Session.create_session()
     data = {}
     tags = []
     with open(f"./static/databases/frm_api-files{self.personal_file}", "r") as file:
         data = loads(file.read())
     q = session.query(Tag)
     for i in data['tag_ids']:
         tags.append(q.filter(Tag.id==i).first())
     print(tags)
     return tags
Exemplo n.º 3
0
def register():
    if flogin.current_user.is_authenticated:
        return flask.redirect('/')
    
    elif flask.request.method == 'GET':
        headers = {
                "main": "Test Page",
                "brand": SvgMaster.getFullLogo(),
                "menu": JsonMaster.htmlifyFile(
                    "./templates/json-templates/menu.json",
                    {
                        "activated": []
                    } 
                )        
        }
        return flask.render_template(
            "general-templates/register.html",
            title="login to oxygen",
            headers=headers
        )
    
    elif flask.request.method == 'POST':
        data = flask.request.form   
        flask.flash("POST :: ", data)
        
        user = User()
        user.login = data['login']
        user.email = data['email']
        lst =[
            "./static/images/avatars/av/avatar_00.png",
            "./static/images/avatars/av/avatar_01.png",
            "./static/images/avatars/av/avatar_02.png"
        ]
        from random import choice
        user.avatar = choice(lst)
        
        if(data['password'] == data['password-rep']):
            user.set_password(data['password'])
        else:
            del user
            return "SHIT"
        
        session = Session.create_session()
        session.add(user)
        session.commit()

        return flask.redirect("/login")
Exemplo n.º 4
0
def new(*args, **kwargs):
    if not UserMaster.is_auntethicated():
        return "/login"

    req = flask.request.json

    tag = Tag()
    tag.header = req['header']
    tag.color = req['color']
    tag.bg_color = req['bg_color']
    tag.author_id = UserMaster.get_user().id

    session = Session.create_session()
    session.add(tag)
    session.commit()

    return "/tags"
Exemplo n.º 5
0
def add_answer(id: int):
    if not UserMaster.is_auntethicated():
        return "NO"

    data = flask.request.json
    print(data)
    session = Session.create_session()
    discussion = session.query(Discussion).filter(Discussion.id == id).first()

    ans = Answer()
    ans.text = data['markdown']
    ans.discussion_id = discussion.id
    ans.author_id = UserMaster.get_user().id

    session.add(ans)
    session.commit()

    return "OK"
Exemplo n.º 6
0
def new_avatar():
    if not UserMaster.is_auntethicated():
        return flask.redirect('/me')
    file = flask.request.files['avatar']
    print(file.__dict__)

    
    file.save("static/images/avatars/" + UserMaster.get_user().login + file.filename.split('.')[-1])

    session = Session.create_session()
    session.query(User).filter(User.id==UserMaster.get_user().id).update(
        {
            "avatar": "static/images/avatars/" + UserMaster.get_user().login + file.filename.split('.')[-1]
        }
    )
    
    session.commit()
    return flask.redirect('/me')
Exemplo n.º 7
0
import app.services.users.usr_api as UserMaster
import app.services.forums.mrk_api as MarkMaster
from app.services.forums.tgs_api import getListTags
from app.alchemy import session as Session
from app.alchemy.models.discussions import Discussion
from app.alchemy.models.answers import Answer
""" Service Forum """

folder = "templates"

blueprint: flask.Blueprint = flask.Blueprint('forum_api',
                                             __name__,
                                             template_folder=folder)
# courier: Courier = Courier()
# Session.global_init(Database_Config.FORUM)
session = Session.create_session()


def init_blueprint(folder: str = Config.TEMPLATES_FOLDER):
    global blueprint
    blueprint = flask.Blueprint('user_api', __name__, template_folder=folder)


def setTemplateFolder(self, folder="templates"):
    global blueprint
    blueprint = flask.Blueprint('user_api', __name__, template_folder=folder)


def getBlueprint() -> flask.Blueprint:
    return blueprint