diff --git a/yadc/__init__.py b/yadc/__init__.py index 5a076fb..998ed50 100644 --- a/yadc/__init__.py +++ b/yadc/__init__.py @@ -28,7 +28,7 @@ def create_app(): POST_LIST_THUMB_HEIGHT=200, POST_UPLOADS=os.path.join(app.instance_path, 'post'), INSTANCE_NAME='YaDc', - POSTS_PER_PAGE=4, + POSTS_PER_PAGE=8, SQLALCHEMY_ECHO=True, ) @@ -51,10 +51,11 @@ def create_app(): admin.add_view(ModelView(models.Tag, db.session, endpoint='admin_tag')) admin.add_view(ModelView(models.Comment, db.session, endpoint='admin_comment')) - from yadc.bp import main, post, auth + from yadc.bp import main, post, auth, user app.register_blueprint(main.bp) app.register_blueprint(post.bp, url_prefix='/post') - app.register_blueprint(auth.bp, url_prefix='/user') + app.register_blueprint(auth.bp, url_prefix='/auth') + app.register_blueprint(user.bp, url_prefix='/user') login.login_view = 'auth.login' from yadc import utils diff --git a/yadc/bp/auth.py b/yadc/bp/auth.py index 90be874..bc0ce35 100644 --- a/yadc/bp/auth.py +++ b/yadc/bp/auth.py @@ -35,7 +35,7 @@ def login(): return redirect(nextpage()) - return render_template('login.html', form=form) + return render_template('auth/login.html', form=form) @bp.route('/logout/') def logout(): @@ -60,7 +60,7 @@ def reset_password(): flash('Password successfully reset. Check your email.') return redirect(url_for('.login')) - return render_template('reset_password.html', form=form) + return render_template('auth/reset_password.html', form=form) @bp.route('/register/', methods=['GET', 'POST']) @@ -79,4 +79,4 @@ def register(): flash('Your account has been successfully registered. You can now login.') return redirect(url_for('.login')) - return render_template('register.html', form=form) + return render_template('auth/register.html', form=form) diff --git a/yadc/bp/main.py b/yadc/bp/main.py index d1aa061..c750a7e 100644 --- a/yadc/bp/main.py +++ b/yadc/bp/main.py @@ -32,7 +32,7 @@ def uploaded_thumb(*args, **kwargs): # @bp.route('/threads') # def threads(): -# return render_template('index.html') +# return render_template('post/index.html') # @bp.route('/user/show/') # def user_profile(username): diff --git a/yadc/bp/post.py b/yadc/bp/post.py index 9b4f8e0..47eeafa 100644 --- a/yadc/bp/post.py +++ b/yadc/bp/post.py @@ -63,7 +63,7 @@ def posts(page): # flash(posts.items) # flash(tags) - return render_template('index.html', posts=posts.items, tags=tags, pagination=posts) + return render_template('post/index.html', posts=posts.items, tags=tags, pagination=posts) @bp.route('/show/') def post_show(id): @@ -80,7 +80,7 @@ def post_show(id): form = CommentForm() form.post_id.data = post.id - return render_template('post.html', post=post, tags=post.tags, comments=post.comments, comment_form=form) + return render_template('post/post.html', post=post, tags=post.tags, comments=post.comments, comment_form=form) @bp.route('/upload', methods=['GET', 'POST']) @login_required @@ -115,9 +115,10 @@ def upload(): flash('Successfully submitted {}'.format(str(post))) - return redirect(url_for('.upload')) + #return redirect(url_for('.upload')) + return redirect(url_for('.posts')) - return render_template('upload.html', form=form) + return render_template('post/upload.html', form=form) @bp.route('comment', methods=['POST']) @login_required diff --git a/yadc/bp/user.py b/yadc/bp/user.py new file mode 100644 index 0000000..35495d5 --- /dev/null +++ b/yadc/bp/user.py @@ -0,0 +1,29 @@ +from flask import (Blueprint, abort, current_app, flash, redirect, + render_template, request, send_from_directory, url_for) +from flask_login import current_user, login_required +from yadc.forms import ChangePassForm + +bp = Blueprint('user', __name__) + +@bp.route('/') +def profile(username): + return "OH HELLO, HERETIC!" + +@bp.route('/settings') +@login_required +def settings(): + form = ChangePassForm(request.form) + if request.method == 'POST' and form.validate(): + user = current_user + + if not user.check_password(form.password_current.data): + flash('Incorrect password') + return redirect(url_for('.settings')) + + user.create_password(form.password.data) + db.session.commit() + + flash('Password changed successfully.') + return redirect(url_for('.settings')) + + return render_template('manage/user.html', form=form) \ No newline at end of file diff --git a/yadc/forms.py b/yadc/forms.py index f608547..8fde217 100644 --- a/yadc/forms.py +++ b/yadc/forms.py @@ -83,4 +83,10 @@ class UploadForm(CSRFForm): class CommentForm(CSRFForm): post_id = HiddenField(validators=[DataRequired()]) content = TextAreaField('Comment', validators=[DataRequired()]) - submit = SubmitField('Send') \ No newline at end of file + submit = SubmitField('Send') + +class ChangePassForm(CSRFForm): + password_current = PasswordField('Current password', validators=[DataRequired()]) + password = PasswordField('Password', validators=[DataRequired()]) + password_again = PasswordField('Repeat password', validators=[DataRequired(), EqualTo('password')]) + submit = SubmitField('Change password') \ No newline at end of file diff --git a/yadc/static/default.scss b/yadc/static/default.scss index 583e87e..f46e514 100644 --- a/yadc/static/default.scss +++ b/yadc/static/default.scss @@ -14,18 +14,8 @@ $header-bg-color: #222; $nav-bg-color: #111d;//#20141fd0; $nav-bg-color_hover: #333;//#20141fa0; -// $desktop-width: 560px; - -// @mixin mobile { -// @media only screen and (max-width: #{$desktop-width - 1px}) { -// @content; -// } -// } -// @mixin desktop { -// @media only screen and (min-width: #{$desktop-width}) { -// @content; -// } -// } +//$notif-bg-color: #542772d0; +$notif-bg-color: #000c; body { @@ -204,14 +194,56 @@ header { } } +.flash_msgs { + display: flex; + flex-flow: column-reverse nowrap; + position: absolute; + z-index: 20; + // top: 0; + //left: 0; + bottom: 0; + right: 0; + + margin: 0; + // margin-top: 20px; + padding: 10px; + //max-width: 1300; + + font-size: .9em; + pointer-events: none; + + > li { + //width: 300px; + //margin: 0 auto; + width: 250px; + padding: 10px; + + &:not(:first-child) { + margin-bottom: 10px; + } + + background-color: $notif-bg-color; + + overflow: hidden; + + @keyframes fade { + 0%,100% { opacity: 0 } + 20%,80% { opacity: 1 } + } + + opacity: 0; + animation: fade 7s normal; + + } +} .main_wrap { $bp-desktop: ">=desktop"; $bp-tablet: "Edit edit? +{% endmacro %} + +{% macro render_sidenav(sidenav_links) %} +
+ {% for class, (name, link) in sidenav_links.items() %} + {{ name }} + {% endfor %} +
{% endmacro %} \ No newline at end of file diff --git a/yadc/templates/login.html b/yadc/templates/auth/login.html similarity index 91% rename from yadc/templates/login.html rename to yadc/templates/auth/login.html index 7d461da..f9c7eff 100644 --- a/yadc/templates/login.html +++ b/yadc/templates/auth/login.html @@ -1,4 +1,4 @@ -{% extends 'base.html' %} +{% extends 'layout/base.html' %} {% from "_formhelpers.html" import errors %} {% block content %} diff --git a/yadc/templates/register.html b/yadc/templates/auth/register.html similarity index 92% rename from yadc/templates/register.html rename to yadc/templates/auth/register.html index 48cd69c..3cbf922 100644 --- a/yadc/templates/register.html +++ b/yadc/templates/auth/register.html @@ -1,4 +1,4 @@ -{% extends 'base.html' %} +{% extends 'layout/base.html' %} {% from "_formhelpers.html" import errors %} {% block content %} diff --git a/yadc/templates/reset_password.html b/yadc/templates/auth/reset_password.html similarity index 88% rename from yadc/templates/reset_password.html rename to yadc/templates/auth/reset_password.html index 316af1d..d54e86b 100644 --- a/yadc/templates/reset_password.html +++ b/yadc/templates/auth/reset_password.html @@ -1,4 +1,4 @@ -{% extends 'base.html' %} +{% extends 'layout/base.html' %} {% from "_formhelpers.html" import errors %} {% block content %} diff --git a/yadc/templates/base.html b/yadc/templates/layout/base.html similarity index 98% rename from yadc/templates/base.html rename to yadc/templates/layout/base.html index c475b0b..2d870aa 100644 --- a/yadc/templates/base.html +++ b/yadc/templates/layout/base.html @@ -46,7 +46,7 @@ {% with msgs = get_flashed_messages() %} {% if msgs %} -
    +
      {% for msg in msgs %}
    • {{ msg }}
    • {% endfor %} diff --git a/yadc/templates/layout/settings.html b/yadc/templates/layout/settings.html new file mode 100644 index 0000000..958662f --- /dev/null +++ b/yadc/templates/layout/settings.html @@ -0,0 +1,13 @@ +{% extends 'layout/base.html' %} +{% from '_includes.html' import render_sidenav with context %} + +{% block content %} +
      +
      + {{ render_sidenav({"speedtest": ("Speedtest", "http://speedtest.cesnet.cz")}) }} +
      +
      + {% block setting_content %}{% endblock %} +
      +
      +{% endblock content %} \ No newline at end of file diff --git a/yadc/templates/manage/user.html b/yadc/templates/manage/user.html new file mode 100644 index 0000000..78319ba --- /dev/null +++ b/yadc/templates/manage/user.html @@ -0,0 +1,24 @@ +{% extends 'layout/settings.html' %} +{% from "_formhelpers.html" import errors %} + +{% block setting_content %} +
      +

      Change password

      + {{ form.csrf_token }} +
      + {{ form.password_current(placeholder="Current password") }} + {{ errors(form.password_current) }} +
      +
      + {{ form.password(placeholder="Password") }} + {{ errors(form.password) }} +
      +
      + {{ form.password_again(placeholder="Repeat password") }} + {{ errors(form.password_again) }} +
      +
      + {{ form.submit() }} +
      +
      +{% endblock %} \ No newline at end of file diff --git a/yadc/templates/index.html b/yadc/templates/post/index.html similarity index 95% rename from yadc/templates/index.html rename to yadc/templates/post/index.html index 629b3ce..532c03f 100644 --- a/yadc/templates/index.html +++ b/yadc/templates/post/index.html @@ -1,4 +1,4 @@ -{% extends 'base.html' %} +{% extends 'layout/base.html' %} {% from '_includes.html' import render_tags, render_pagination with context %} {% block content %} diff --git a/yadc/templates/post.html b/yadc/templates/post/post.html similarity index 97% rename from yadc/templates/post.html rename to yadc/templates/post/post.html index ed9831f..7d4ea91 100644 --- a/yadc/templates/post.html +++ b/yadc/templates/post/post.html @@ -1,4 +1,4 @@ -{% extends 'base.html' %} +{% extends 'layout/base.html' %} {% from '_includes.html' import render_tags, render_comments, render_post_edit with context %} {% from "_formhelpers.html" import errors %} diff --git a/yadc/templates/upload.html b/yadc/templates/post/upload.html similarity index 92% rename from yadc/templates/upload.html rename to yadc/templates/post/upload.html index e7d368a..3a7ea01 100644 --- a/yadc/templates/upload.html +++ b/yadc/templates/post/upload.html @@ -1,4 +1,4 @@ -{% extends 'base.html' %} +{% extends 'layout/base.html' %} {% from "_formhelpers.html" import errors %} {% block content %}