Compare commits

..

3 Commits

  1. 5
      app/forms.py
  2. 21
      app/routes.py
  3. 14
      app/templates/admin.html
  4. 9
      app/templates/base.html
  5. 15
      app/templates/index.html
  6. 9
      app/templates/login.html
  7. 5
      app/templates/result.html

@ -4,6 +4,11 @@ from wtforms.validators import ValidationError, DataRequired, Email, EqualTo
from app.models import User
class CheckForm(FlaskForm):
text = StringField('Text to be checked', validators=[DataRequired()])
submit = SubmitField('Check')
class LoginForm(FlaskForm):
username = StringField('Username', validators=[DataRequired()])
password = PasswordField('Password', validators=[DataRequired()])

@ -1,16 +1,25 @@
from app import app
from app import db
from app.forms import LoginForm, RegistrationForm
from app.forms import LoginForm, RegistrationForm, CheckForm
from app.models import User
from flask import render_template, flash, redirect, url_for
from flask import render_template, flash, redirect, url_for, request
from flask_login import current_user, login_user, logout_user
from flask_login import login_required
@app.route('/')
@app.route('/index')
@app.route('/index', methods=['GET', 'POST'])
def index():
return "Hello, World!"
form = CheckForm()
if request.method == 'POST':
text = request.form['text']
return render_template('result.html', title='Result', text=text)
else:
if form.validate_on_submit():
flash('Check requested for text {}'.format(
form.text.data))
return redirect(url_for('index'))
return render_template('index.html', title='Check', form=form)
@app.route('/register', methods=['GET', 'POST'])
@ -31,7 +40,7 @@ def register():
@app.route('/login', methods=['GET', 'POST'])
def login():
if current_user.is_authenticated:
return redirect(url_for('index'))
return redirect(url_for('admin'))
form = LoginForm()
if form.validate_on_submit():
user = User.query.filter_by(username=form.username.data).first()
@ -46,7 +55,7 @@ def login():
@app.route('/admin')
@login_required
def admin():
return "Hello, World!"
return render_template('admin.html')
@app.route('/logout')

@ -0,0 +1,14 @@
{% extends "base.html" %}
{% block content %}
<div>
Dildebaslar:
<a href="{{ url_for('index') }}">Home</a>
{% if current_user.is_anonymous %}
<a href="{{ url_for('login') }}">Login</a>
{% else %}
<a href="{{ url_for('logout') }}">Logout</a>
{% endif %}
</div>
<h1>Hi, {{ current_user.username }}!</h1>
{% endblock %}

@ -32,15 +32,6 @@
{% endif %}
{% endwith %}
{% block body %}{% endblock %}
<div>
Microblog:
<a href="{{ url_for('index') }}">Home</a>
{% if current_user.is_anonymous %}
<a href="{{ url_for('login') }}">Login</a>
{% else %}
<a href="{{ url_for('logout') }}">Logout</a>
{% endif %}
</div>
<div class="container" align="center">
<div class="jumbotron text-center" style="width: 50% ;">

@ -0,0 +1,15 @@
{% extends "base.html" %}
{% block content %}
<div class="container" align="center">
<div class="row">
<div class="col-md-6 mx-md-auto">
<form action="" method="post" novalidate >
<textarea class="form-control" rows="12" name="text" style="width: 100% ; height: 100%" ></textarea>
<input type="submit" value="Metni incele" class="btn btn-primary btn-block">
</form>
</div>
</div>
</div>
{% endblock %}

@ -1,6 +1,15 @@
{% extends "base.html" %}
{% block content %}
<div>
Dildebaslar:
<a href="{{ url_for('index') }}">Home</a>
{% if current_user.is_anonymous %}
<a href="{{ url_for('login') }}">Login</a>
{% else %}
<a href="{{ url_for('logout') }}">Logout</a>
{% endif %}
</div>
<h1>Hi, {{ current_user.username }}!</h1>
<h1>Sign In</h1>
<form action="" method="post" novalidate>

@ -0,0 +1,5 @@
{% extends "base.html" %}
{% block content %}
{{ text }}
{% endblock %}
Loading…
Cancel
Save