Compare commits
8 Commits
7f8900d36c
...
bf105f7048
Author | SHA1 | Date |
---|---|---|
Neslihan | bf105f7048 | 4 years ago |
Neslihan | ffb8fe1f4f | 4 years ago |
Neslihan | ea6ad54f79 | 4 years ago |
Neslihan | 7556c8168c | 4 years ago |
Neslihan | c9c5d3f418 | 4 years ago |
Neslihan | 722c2777d5 | 4 years ago |
Neslihan | 74f779e0f8 | 4 years ago |
Neslihan | 8dd0e52081 | 4 years ago |
@ -0,0 +1,142 @@ |
||||
# Byte-compiled / optimized / DLL files |
||||
__pycache__/ |
||||
*.py[cod] |
||||
*$py.class |
||||
|
||||
# C extensions |
||||
*.so |
||||
|
||||
# Distribution / packaging |
||||
.Python |
||||
build/ |
||||
develop-eggs/ |
||||
dist/ |
||||
downloads/ |
||||
eggs/ |
||||
.eggs/ |
||||
lib/ |
||||
lib64/ |
||||
parts/ |
||||
sdist/ |
||||
var/ |
||||
wheels/ |
||||
share/python-wheels/ |
||||
*.egg-info/ |
||||
.installed.cfg |
||||
*.egg |
||||
MANIFEST |
||||
|
||||
# PyInstaller |
||||
# Usually these files are written by a python script from a template |
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it. |
||||
*.manifest |
||||
*.spec |
||||
|
||||
# Installer logs |
||||
pip-log.txt |
||||
pip-delete-this-directory.txt |
||||
|
||||
# Unit test / coverage reports |
||||
htmlcov/ |
||||
.tox/ |
||||
.nox/ |
||||
.coverage |
||||
.coverage.* |
||||
.cache |
||||
nosetests.xml |
||||
coverage.xml |
||||
*.cover |
||||
*.py,cover |
||||
.hypothesis/ |
||||
.pytest_cache/ |
||||
cover/ |
||||
|
||||
# Translations |
||||
*.mo |
||||
*.pot |
||||
|
||||
# Django stuff: |
||||
*.log |
||||
local_settings.py |
||||
db.sqlite3 |
||||
db.sqlite3-journal |
||||
|
||||
# Flask stuff: |
||||
instance/ |
||||
.webassets-cache |
||||
|
||||
# Scrapy stuff: |
||||
.scrapy |
||||
|
||||
# Sphinx documentation |
||||
docs/_build/ |
||||
|
||||
# PyBuilder |
||||
.pybuilder/ |
||||
target/ |
||||
|
||||
# Jupyter Notebook |
||||
.ipynb_checkpoints |
||||
|
||||
# IPython |
||||
profile_default/ |
||||
ipython_config.py |
||||
|
||||
# pyenv |
||||
# For a library or package, you might want to ignore these files since the code is |
||||
# intended to run in multiple environments; otherwise, check them in: |
||||
# .python-version |
||||
|
||||
# pipenv |
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. |
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies |
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not |
||||
# install all needed dependencies. |
||||
#Pipfile.lock |
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow |
||||
__pypackages__/ |
||||
|
||||
# Celery stuff |
||||
celerybeat-schedule |
||||
celerybeat.pid |
||||
|
||||
# SageMath parsed files |
||||
*.sage.py |
||||
|
||||
# Environments |
||||
.env |
||||
.venv |
||||
env/ |
||||
venv/ |
||||
ENV/ |
||||
env.bak/ |
||||
venv.bak/ |
||||
|
||||
# Spyder project settings |
||||
.spyderproject |
||||
.spyproject |
||||
|
||||
# Rope project settings |
||||
.ropeproject |
||||
|
||||
# mkdocs documentation |
||||
/site |
||||
|
||||
# mypy |
||||
.mypy_cache/ |
||||
.dmypy.json |
||||
dmypy.json |
||||
|
||||
# Pyre type checker |
||||
.pyre/ |
||||
|
||||
# pytype static type analyzer |
||||
.pytype/ |
||||
|
||||
# Cython debug symbols |
||||
cython_debug/ |
||||
app.db |
||||
.idea |
||||
.flaskenv |
||||
migrations |
@ -0,0 +1,15 @@ |
||||
from flask import Flask |
||||
from config import Config |
||||
from flask_sqlalchemy import SQLAlchemy |
||||
from flask_migrate import Migrate |
||||
from flask_login import LoginManager |
||||
|
||||
app = Flask(__name__) |
||||
app.config.from_object(Config) |
||||
login = LoginManager(app) |
||||
db = SQLAlchemy(app) |
||||
migrate = Migrate(app, db) |
||||
login = LoginManager(app) |
||||
login.login_view = 'login' |
||||
|
||||
from app import routes |
@ -0,0 +1,30 @@ |
||||
from flask_wtf import FlaskForm |
||||
from wtforms import StringField, PasswordField, BooleanField, SubmitField |
||||
from wtforms.validators import ValidationError, DataRequired, Email, EqualTo |
||||
from app.models import User |
||||
|
||||
|
||||
class LoginForm(FlaskForm): |
||||
username = StringField('Username', validators=[DataRequired()]) |
||||
password = PasswordField('Password', validators=[DataRequired()]) |
||||
remember_me = BooleanField('Remember Me') |
||||
submit = SubmitField('Sign In') |
||||
|
||||
|
||||
class RegistrationForm(FlaskForm): |
||||
username = StringField('Username', validators=[DataRequired()]) |
||||
email = StringField('Email', validators=[DataRequired(), Email()]) |
||||
password = PasswordField('Password', validators=[DataRequired()]) |
||||
password2 = PasswordField( |
||||
'Repeat Password', validators=[DataRequired(), EqualTo('password')]) |
||||
submit = SubmitField('Register') |
||||
|
||||
def validate_username(self, username): |
||||
user = User.query.filter_by(username=username.data).first() |
||||
if user is not None: |
||||
raise ValidationError('Please use a different username.') |
||||
|
||||
def validate_email(self, email): |
||||
user = User.query.filter_by(email=email.data).first() |
||||
if user is not None: |
||||
raise ValidationError('Please use a different email address.') |
@ -0,0 +1,27 @@ |
||||
from datetime import datetime |
||||
from app import db |
||||
from werkzeug.security import generate_password_hash, check_password_hash |
||||
from flask_login import UserMixin |
||||
from app import login |
||||
|
||||
|
||||
class User(UserMixin, db.Model): |
||||
id = db.Column(db.Integer, primary_key=True) |
||||
username = db.Column(db.String(64), index=True, unique=True) |
||||
email = db.Column(db.String(120), index=True, unique=True) |
||||
password_hash = db.Column(db.String(128)) |
||||
# posts = db.relationship('Post', backref='author', lazy='dynamic') |
||||
|
||||
def __repr__(self): |
||||
return '<User {}>'.format(self.username) |
||||
|
||||
def set_password(self, password): |
||||
self.password_hash = generate_password_hash(password) |
||||
|
||||
def check_password(self, password): |
||||
return check_password_hash(self.password_hash, password) |
||||
|
||||
|
||||
@login.user_loader |
||||
def load_user(id): |
||||
return User.query.get(int(id)) |
@ -0,0 +1,55 @@ |
||||
from app import app |
||||
from app import db |
||||
from app.forms import LoginForm, RegistrationForm |
||||
from app.models import User |
||||
from flask import render_template, flash, redirect, url_for |
||||
from flask_login import current_user, login_user, logout_user |
||||
from flask_login import login_required |
||||
|
||||
|
||||
@app.route('/') |
||||
@app.route('/index') |
||||
def index(): |
||||
return "Hello, World!" |
||||
|
||||
|
||||
@app.route('/register', methods=['GET', 'POST']) |
||||
def register(): |
||||
if current_user.is_authenticated: |
||||
return redirect(url_for('index')) |
||||
form = RegistrationForm() |
||||
if form.validate_on_submit(): |
||||
user = User(username=form.username.data, email=form.email.data) |
||||
user.set_password(form.password.data) |
||||
db.session.add(user) |
||||
db.session.commit() |
||||
flash('Congratulations, you are now a registered user!') |
||||
return redirect(url_for('login')) |
||||
return render_template('register.html', title='Register', form=form) |
||||
|
||||
|
||||
@app.route('/login', methods=['GET', 'POST']) |
||||
def login(): |
||||
if current_user.is_authenticated: |
||||
return redirect(url_for('index')) |
||||
form = LoginForm() |
||||
if form.validate_on_submit(): |
||||
user = User.query.filter_by(username=form.username.data).first() |
||||
if user is None or not user.check_password(form.password.data): |
||||
flash('Invalid username or password') |
||||
return redirect(url_for('login')) |
||||
login_user(user, remember=form.remember_me.data) |
||||
return redirect(url_for('admin')) |
||||
return render_template('login.html', title='Sign In', form=form) |
||||
|
||||
|
||||
@app.route('/admin') |
||||
@login_required |
||||
def admin(): |
||||
return "Hello, World!" |
||||
|
||||
|
||||
@app.route('/logout') |
||||
def logout(): |
||||
logout_user() |
||||
return redirect(url_for('index')) |
@ -0,0 +1,54 @@ |
||||
<!DOCTYPE html> |
||||
<html lang="tr"> |
||||
|
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<meta http-equiv="X-UA-Compatible" content="IE=EDGE"> |
||||
<meta name="viewport" content="width=device-width, initial-scale=1"> |
||||
<meta name="description" content="Dilde Başlar"> |
||||
<meta name="author" content="Özgür Yazılım Derneği"> |
||||
|
||||
<title>dildeBaslar</title> |
||||
|
||||
<!-- Bootstrap CSS --> |
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous"> |
||||
|
||||
<!-- Font Awesome --> |
||||
<!-- This link is restricted. You will need your own Font Awesome link if deploying to anywhere other than localhost --> |
||||
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.15.1/css/all.css" integrity="sha384-9ZfPnbegQSumzaE7mks2IYgHoayLtuto3AS6ieArECeaR8nCfliJVuLh/GaQ1gyM" crossorigin="anonymous"> |
||||
|
||||
<!-- Custom CSS --> |
||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='/css/custom.css')}}"> |
||||
|
||||
</head> |
||||
<body> |
||||
{% with messages = get_flashed_messages() %} |
||||
{% if messages %} |
||||
<ul class=flashes> |
||||
{% for message in messages %} |
||||
<li>{{ message }}</li> |
||||
{% endfor %} |
||||
</ul> |
||||
{% 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% ;"> |
||||
<h1>dildeBaşlar</h1> |
||||
<p>dildeBaşlar, metinlerdeki hak ihlallerini tespit edip olması gereken kullanımları ve açıklamalarını gösteren hak temelli bir redaktördür.</p> |
||||
</div> |
||||
</div> |
||||
|
||||
{% block content %}{% endblock %} |
||||
</body> |
||||
</html> |
@ -0,0 +1,26 @@ |
||||
{% extends "base.html" %} |
||||
|
||||
{% block content %} |
||||
<h1>Hi, {{ current_user.username }}!</h1> |
||||
<h1>Sign In</h1> |
||||
<form action="" method="post" novalidate> |
||||
{{ form.hidden_tag() }} |
||||
<p> |
||||
{{ form.username.label }}<br> |
||||
{{ form.username(size=32) }}<br> |
||||
{% for error in form.username.errors %} |
||||
<span style="color: red;">[{{ error }}]</span> |
||||
{% endfor %} |
||||
</p> |
||||
<p> |
||||
{{ form.password.label }}<br> |
||||
{{ form.password(size=32) }}<br> |
||||
{% for error in form.password.errors %} |
||||
<span style="color: red;">[{{ error }}]</span> |
||||
{% endfor %} |
||||
</p> |
||||
<p>{{ form.remember_me() }} {{ form.remember_me.label }}</p> |
||||
<p>{{ form.submit() }}</p> |
||||
<p>New User? <a href="{{ url_for('register') }}">Click to Register!</a></p> |
||||
</form> |
||||
{% endblock %} |
@ -0,0 +1,38 @@ |
||||
{% extends "base.html" %} |
||||
|
||||
{% block content %} |
||||
<h1>Hi, {{ current_user.username }}!</h1> |
||||
<h1>Register</h1> |
||||
<form action="" method="post"> |
||||
{{ form.hidden_tag() }} |
||||
<p> |
||||
{{ form.username.label }}<br> |
||||
{{ form.username(size=32) }}<br> |
||||
{% for error in form.username.errors %} |
||||
<span style="color: red;">[{{ error }}]</span> |
||||
{% endfor %} |
||||
</p> |
||||
<p> |
||||
{{ form.email.label }}<br> |
||||
{{ form.email(size=64) }}<br> |
||||
{% for error in form.email.errors %} |
||||
<span style="color: red;">[{{ error }}]</span> |
||||
{% endfor %} |
||||
</p> |
||||
<p> |
||||
{{ form.password.label }}<br> |
||||
{{ form.password(size=32) }}<br> |
||||
{% for error in form.password.errors %} |
||||
<span style="color: red;">[{{ error }}]</span> |
||||
{% endfor %} |
||||
</p> |
||||
<p> |
||||
{{ form.password2.label }}<br> |
||||
{{ form.password2(size=32) }}<br> |
||||
{% for error in form.password2.errors %} |
||||
<span style="color: red;">[{{ error }}]</span> |
||||
{% endfor %} |
||||
</p> |
||||
<p>{{ form.submit() }}</p> |
||||
</form> |
||||
{% endblock %} |
@ -0,0 +1,9 @@ |
||||
import os |
||||
basedir = os.path.abspath(os.path.dirname(__file__)) |
||||
|
||||
|
||||
class Config(object): |
||||
SECRET_KEY = os.environ.get('SECRET_KEY') or 'xxx' |
||||
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \ |
||||
'sqlite:///' + os.path.join(basedir, 'app.db') |
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False |
@ -0,0 +1 @@ |
||||
from app import app |
Loading…
Reference in new issue