This commit is contained in:
yurecnt 2023-11-16 20:53:29 +05:00
parent 500cb439b8
commit 81d750aae9
15 changed files with 175 additions and 30 deletions

59
bd/1 Normal file
View File

@ -0,0 +1,59 @@
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "users" (
"id" INTEGER,
"email" TEXT NOT NULL,
"pwd" TEXT NOT NULL,
"dostup" TEXT NOT NULL DEFAULT 'u',
"activate" INTEGER NOT NULL DEFAULT 1,
"site" TEXT NOT NULL,
"json" ,
PRIMARY KEY("id" AUTOINCREMENT)
);
CREATE TABLE IF NOT EXISTS "pages" (
"id" INTEGER,
"title" TEXT NOT NULL,
"txt" TEXT NOT NULL,
"user_id" INTEGER,
"status" INTEGER NOT NULL DEFAULT 1,
"description" TEXT,
PRIMARY KEY("id" AUTOINCREMENT)
);
CREATE TABLE IF NOT EXISTS "content" (
"id" INTEGER,
"title" TEXT NOT NULL,
"txt" TEXT NOT NULL,
"short_txt" TEXT NOT NULL,
"user_id" INTEGER,
"status" INTEGER NOT NULL DEFAULT 1,
"content_category" INTEGER NOT NULL DEFAULT 0,
"keywords" TEXT,
"description" TEXT,
"site" TEXT,
"json" TEXT,
"type" ,
"alias" ,
PRIMARY KEY("id" AUTOINCREMENT)
);
CREATE TABLE IF NOT EXISTS "content_category" (
"id" INTEGER,
"category" INTEGER,
"title" TEXT NOT NULL,
"txt" TEXT NOT NULL,
"user_id" INTEGER,
"status" INTEGER NOT NULL DEFAULT 1,
"description" TEXT,
"keywords" TEXT,
"site" TEXT,
"json" TEXT,
PRIMARY KEY("id" AUTOINCREMENT)
);
CREATE TABLE IF NOT EXISTS "settings" (
"id" INTEGER,
"json" TEXT NOT NULL,
"site" TEXT NOT NULL,
"mod" TEXT NOT NULL,
PRIMARY KEY("id" AUTOINCREMENT)
);
INSERT INTO "users" VALUES (1,'yurec@yurecnt.ru','123','u',1,'localhost','iuhiuhi');
INSERT INTO "content" VALUES (1,'Первая страница Flask','text страницы','Краткое описание',1,1,0,NULL,NULL,'localhost',NULL,'page',NULL);
COMMIT;

3
bd/dump.sql Normal file
View File

@ -0,0 +1,3 @@
SQLite version 3.37.2 2022-01-06 13:25:41
Enter ".help" for usage hints.
[?2004hsqlite> ^C[?2004l [?2004h^C[?2004l [?2004h^C[?2004l

View File

@ -6,32 +6,9 @@ from urllib.parse import urlparse
app = Flask(__name__)
@app.route('/')
def main_mod(module='main'):
o = urlparse(request.base_url)
myhost=o.hostname
myhost=o.hostname
module2="mod."+module + ".index"
mod = __import__(module2)
a=getattr(mod, module)
b=getattr(a, 'index')
if request.method=='POST':
do=b.do(id)
else:
go=b.mod(id, myhost)
# help(b)
result=b.mod.result
print(result)
return render_template(myhost + "/" + module+'.html', massiv=result, myhost=myhost)
@app.route('/<module>')
def short_mod(module='main'):
module="mod."+module
__import__(module)
return str(module)
@app.route('/<module>/')
@app.route('/<module>/<id>', methods=['GET', 'POST'])
def mod(id, module='page'):
def mod(id=1, module='page'):
o = urlparse(request.base_url)
myhost=o.hostname
module2="mod."+module + ".index"
@ -45,7 +22,7 @@ def mod(id, module='page'):
# help(b)
result=b.mod.result
print(result)
return render_template(myhost + "/" + module+'.html', massiv=result, myhost=myhost)
return render_template(module+'.html', massiv=result, myhost=myhost, module=module)
#return str(module)

Binary file not shown.

9
mod/login/index.py Normal file
View File

@ -0,0 +1,9 @@
class mod:
result=""
def __init__(self, id, myhost):
import mod.sqlite.index
self.getPage(id, myhost)
def getPage(self, id, myhost):
pass
#return result

View File

@ -36,7 +36,7 @@ class mod:
self.getPage(id, myhost)
def getPage(self, id, myhost):
self.sql.cur.execute("SELECT * FROM content WHERE id=" + id + " AND type='page' AND site='" + myhost + "' LIMIT 1")
self.sql.cur.execute("SELECT * FROM content WHERE id=" + str(id) + " AND type='page' AND site='" + myhost + "' LIMIT 1")
result = self.sql.cur.fetchone()
mod.result=result
return result

File diff suppressed because one or more lines are too long

49
static/js/login.js Normal file
View File

@ -0,0 +1,49 @@
/*
0 - нет ошибки
1 - не совпадает капча
2 - не совпадают пароли
3 - юзер уже зарегистрирован
4 - не введен адрес почты
5 - скрыть ошибку
*/
function showErr_v2(data) {
$("#regResult").addClass("hidden");
$("#regResult").removeClass("alert-danger");
$("#regResult").removeClass("alert-success");
switch (data) {
case '0':
$("#regResult").text("Вы успешно зарегистрированы!");
$("#alert-success").addClass("alert-success");
$("#regResult").removeClass("hidden");
break;
case '1':
$("#regResult").text("Не подошел проверочный код!");
$("#regResult").addClass("alert-danger");
$("#regResult").removeClass("hidden");
break;
case '2':
$("#regResult").text("Пароли не совпадают!");
$("#regResult").addClass("alert-danger");
$("#regResult").removeClass("hidden");
break;
case '3':
$("#regResult").text("Пользователь с такой почтой уже зарегистрирован");
$("#regResult").addClass("alert-danger");
$("#regResult").removeClass("hidden");
break;
case '4':
$("#regResult").text("Вы не указали электронную почту");
$("#regResult").addClass("alert-danger");
$("#regResult").removeClass("hidden");
break;
case '5'://Скрываем ошибки
$("#regResult").addClass("hidden");
break;
}
}
/* проверка валидности пароля */
$('#pwd, #pwd2').keyup(function (event) {
showErr_v2(($("#pwd").val() != $("#pwd2").val()) ? "2" : "5");
})

42
templates/login.html Normal file
View File

@ -0,0 +1,42 @@
{% extends "template.html" %}
{% block body %}
<section class="container">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/">Главная</a></li>
<li class="breadcrumb-item active" aria-current="page">Авторизация</li>
</ol>
</nav>
<div class="row">
<div class="col-md-6" style="border-right: 1px solid lightgray;">
<h2>Авторизация</h2>
<input class="form-control mt-3" name="email" type="email" placeholder="Электронная почта">
<input class="form-control mt-3" name="pwd" type="password" placeholder="Пароль">
<input class="btn btn-outline-dark mt-3" name="ok" type="submit" value="Войти">
</div>
<div class="col-md-6">
<h2>Регистрация</h2>
<input class="form-control mt-3" name="email" type="email" placeholder="Электронная почта">
<input class="form-control mt-3" name="pwd" type="password" placeholder="Пароль" id="pwd">
<input class="form-control mt-3" name="pwd2" type="password" placeholder="Повторите пароль" id="pwd2">
<input class="btn btn-outline-dark mt-3" name="ok" type="submit" value="Зарегистрироваться">
<div class="alert hidden" role="alert" id="regResult">
</div>
</div>
</div>
</section>
{% endblock %}

View File

@ -1,4 +1,4 @@
{% extends "localhost/template.html" %}
{% extends "template.html" %}
{% block body %}
<section class="container">
<div class="row">

View File

@ -1,6 +1,6 @@
{% extends "localhost/template.html" %}
{% extends "template.html" %}
{% block body %}
<article class="container">
{{massiv.2}}

View File

@ -69,11 +69,15 @@
<script src="/static/js/jquery-3.7.1.min.js.js"></script>
<script src="https://new.yurecnt.ru/api/jquery/plugins/lazyload/jquery.lazyload.min1.9.5.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.bundle.min.js"
integrity="sha384-HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBNS5n7C8IVInixGAoxmnlMuBnhbgrkm"
crossorigin="anonymous"></script>
<script src="/static/js/global.js"></script>
<script src="/static/js/{{module}}.js"></script>
</body>