Example #1
0
def delete(id: int):
    get_exists_data('p.id, title, body, created, author_id, username',
                    'post p JOIN user u ON p.author_id = u.id', 'p.id', (id, ))

    get_delete_query('post', (id, ))

    return redirect(url_for('public.index'))
Example #2
0
    def load_logget_user():
        user_id = session.get('user_id')

        if user_id is None:
            g.user = None
        else:
            g.user = get_exists_data('*','user','id',(user_id,))
Example #3
0
def update(id: int):
    post = get_exists_data('p.id, title, body, created, author_id, username',
                           'post p JOIN user u ON p.author_id = u.id', 'p.id',
                           (id, ))

    if post is None:
        abort(404, "Post id {0} no existe..".format(id))
    if post['author_id'] != g.user['id']:
        abort(
            403, "Post no es de este usuario : {0} acceso denegado".format(
                g.user['username']))

    if request.method == 'POST':
        title = request.form['title']
        body = request.form['TextUpdateContentEditor']
        error = None
        time = datetime.datetime.now()

        if not title:
            error = 'Titulo Requerido'

        if error is not None:
            flash(error)
        else:
            get_edit_query('post', 'title = ?, body = ?, created = ?', 'id',
                           (title, body, time, id))
            return redirect(url_for('public.index', update="Si"))

    return render_template('public/creator.html',
                           directory="UpdatePost",
                           post=post)
Example #4
0
def articles(id: int):
    comments = get_query('c.id, comment, user_id, username',
                         'comments c JOIN user u ON c.user_id = u.id', 'c.id')
    post = get_exists_data('p.id, title, body, created, author_id, username',
                           'post p JOIN user u ON p.author_id = u.id', 'p.id',
                           (id, ))
    return render_template('public/article.html',
                           article=post,
                           commentaries=comments)
Example #5
0
def register():
    if request.method == 'POST':
        if 'file' not in request.files:
            error = 'No ha guardado ninguna imagen de avatar'
        avatar = request.files['avatar']
        username = request.form['username']
        email = request.form['email']
        password = request.form['password']
        error = None

        if not avatar.filename:
            error = 'No has seleccionado una imagen del avatar se asignara por defecto'
            category = 'material-blue'
        elif not username:
            error = 'Nombre de usuario requerido'
            category = 'material-yellow'
        elif not email:
            error = 'Correo Electronico requerido'
            category = 'material-yellow'
        elif not password:
            error = 'Contraseña requerida'
            category = 'material-red'
        elif get_exists_data('id', 'user', 'username',
                             (username, )) is not None:
            error = 'El Usuario {} ya esta registrado.'.format(username)
            category = 'material-yellow'

        if error is None:
            save_image(avatar)
            get_new_query('user (username, email, password)', '(?, ?, ?)',
                          (username, email, generate_password_hash(password)))

            user = get_exists_data('*', 'user', 'username', (username, ))

            get_new_query('avatar (user_id, image)', '(?,?)',
                          (user['id'], avatar.filename))
            flash('Usuario Registrado con exito')
            return redirect(url_for('auth.login'))

        flash(error, category)

    return redirect(url_for('public.index'))
Example #6
0
def update_username():
    if request.method == 'POST':
        username = request.form['username']
        error = None

        if not username:
            error = 'El nombre de usuario esta vacio'
            category = 'material-yellow'
        elif get_exists_data('id', 'user', 'username',
                             (username, )) is not None:
            error = 'El nombre de usuario ya existe escoje uno diferente'
            category = 'material-red'

        if error is None:
            get_edit_query('user', 'username = ?', 'id', (username, g.user.id))
        flash(error, category)
    return redirect(url_for('public.profile'))
Example #7
0
def login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        error = None
        user = get_exists_data('*', 'user', 'username', (username, ))

        if user is None:
            error = 'Usuario incorrecto.'
            category = 'material-red'
        elif not check_password_hash(user['password'], password):
            error = 'Contraseña incorrecta.'
            category = 'material-yellow'

        if error is None:
            session.clear()
            session['user_id'] = user['id']
            return redirect(url_for('public.index'))

        flash(error, category)

    return redirect(url_for('public.index'))
Example #8
0
def social_feed():
    if request.method == 'POST':
        social = request.form['socialname']
        url = request.form['socialurl']
        error = None

        if not social:
            error = 'El campo no puede estar vacio especifica un nombre'
            category = 'material-yellow'
        elif not url:
            error = 'El campo no puede estar vacio especifica un nombre'
            category = 'material-red'

        if error is None:
            if get_exists_data('id', 'socialfeed', 'feed',
                               (social, )) is not None:
                flash('Ya existe Actualizando', 'material-teal')
                get_edit_query('socialfeed', 'url = ?', 'feed', (url, social))
            else:
                flash('Añadiendo la red a tu estatus', 'material-blue')
                get_new_query('socialfeed (feed, url, user_id)', '(?, ?, ?)',
                              (social, url, g.user['id']))
        flash(error, category)
    return redirect(url_for('public.profile'))