Exemple #1
0
def delete_pupil(pupil_id):
    if 'username' not in session:
        return redirect('/login')
    role = UsersModel(db.get_connection()).get(session['user_id'])[6]
    if role != 'teacher':
        return redirect('/index')
    nm = UsersModel(db.get_connection())
    nm.delete(pupil_id)
    return redirect("/index")
Exemple #2
0
def index_teacher():
    if 'username' not in session:
        return redirect('/login')
    role = UsersModel(db.get_connection()).get(session['user_id'])[6]
    if role != 'teacher':
        return redirect('/index')
    achievements = AchieveModel(db.get_connection()).get_all(
        session['user_id'])
    achievements.sort(key=lambda x: (x[4], x[1]))
    u_role = False
    name = UsersModel(db.get_connection()).get(session['user_id'])[1]
    user_name = UsersModel(db.get_connection()).get(session['user_id'])[3]
    password = UsersModel(db.get_connection()).get(session['user_id'])[4]
    role = UsersModel(db.get_connection()).get(session['user_id'])[6]
    all_user = UsersModel(db.get_connection()).get_all()
    users = []
    for user in all_user:
        if user[3] != UsersModel(db.get_connection()).get(
                session['user_id'])[3]:
            if user[5] == UsersModel(db.get_connection()).get(
                    session['user_id'])[1]:
                users.append((user[0], user[1]))
    return render_template(
        'index_teacher.html',
        users=users,
        name=name,
        link=url_for(
            'static',
            filename='img/' +
            UsersModel(db.get_connection()).get(session['user_id'])[7]))
Exemple #3
0
def index():
    if 'username' not in session:
        return redirect('/login')
    achievements = AchieveModel(db.get_connection()).get_all(
        session['user_id'])
    achievements.sort(key=lambda x: (x[4], x[1]))
    u_role = False
    name = UsersModel(db.get_connection()).get(session['user_id'])[1]
    group = UsersModel(db.get_connection()).get(session['user_id'])[2]
    user_name = UsersModel(db.get_connection()).get(session['user_id'])[3]
    password = UsersModel(db.get_connection()).get(session['user_id'])[4]
    teacher = UsersModel(db.get_connection()).get(session['user_id'])[5]
    role = UsersModel(db.get_connection()).get(session['user_id'])[6]
    if role == 'teacher':
        return redirect("/index_teacher")
    return render_template(
        'index.html',
        username=session['username'],
        achievements=achievements,
        name=name,
        group=group,
        teacher=teacher,
        link=url_for(
            'static',
            filename='img/' +
            UsersModel(db.get_connection()).get(session['user_id'])[7]))
Exemple #4
0
def users(user_id):
    if 'username' not in session:
        return redirect('/login')
    role = UsersModel(db.get_connection()).get(session['user_id'])[6]
    if role != 'teacher':
        return redirect('/index')
    user = UsersModel(db.get_connection()).get(user_id)
    achievements = AchieveModel(db.get_connection()).get_all(user[0])
    achievements.sort(key=lambda x: (x[4], x[1]))
    name = user[1]
    group = user[2]
    teacher = user[5]
    return render_template(
        'users.html',
        achievements=achievements,
        name=name,
        group=group,
        teacher=teacher,
        link=url_for('static',
                     filename='img/' +
                     UsersModel(db.get_connection()).get(user_id)[7]))
Exemple #5
0
def image_teacher(im):
    if 'username' not in session:
        return redirect('/login')
    role = UsersModel(db.get_connection()).get(session['user_id'])[6]
    if role != 'teacher':
        return redirect('/index')
    user_id = AchieveModel(db.get_connection()).get(im)[3]
    return render_template(
        'image_teacher.html',
        link=url_for('static',
                     filename='img/' +
                     AchieveModel(db.get_connection()).get(im)[5]),
        user_id=user_id)
Exemple #6
0
def login():
    form = LoginForm()
    already = False
    if 'username' in session:
        return redirect("/logout")
    if form.validate_on_submit():
        user_name = form.username.data
        password = form.password.data
        user_model = UsersModel(db.get_connection())
        exists = user_model.exists(user_name, password)
        already = False
        if (exists[0]):
            alredy = True
            session['username'] = user_name
            session['user_id'] = exists[1]
            if UsersModel(db.get_connection()).get(
                    session['user_id'])[6] == 'teacher':
                return redirect("/index_teacher")
            return redirect("/index")
    return render_template('login.html',
                           title='Авторизация',
                           form=form,
                           already=already)
Exemple #7
0
def reg():
    form = RegisterForm()
    already = False
    true_password = False
    teacher_exist = True
    file_ok = True
    if form.validate_on_submit():
        name = form.name.data
        group = form.group.data
        user_name = form.username.data
        password = form.password.data
        password_agree = form.password_agree.data
        if password != password_agree:
            true_password = True
        teacher = form.teacher.data
        teacher_exist = False
        all_user = UsersModel(db.get_connection()).get_all()
        for user in all_user:
            if user[1] == teacher and user[6] == 'teacher':
                teacher_exist = True
                break
        filename = secure_filename(form.file.data.filename)
        file_ok = False
        if '.' in filename and (filename.split('.')[1]
                                in ['jpg', 'JPG', 'bmp', 'png', 'PNG']):
            file_ok = True
        if file_ok:
            form.file.data.save('static/img/' + filename)
        user_model = UsersModel(db.get_connection())
        exists = user_model.exists(user_name, password)
        already = False
        if not (exists[0]) and not true_password and teacher_exist and file_ok:
            already = False
            user_model.insert(name, group, user_name, password, teacher,
                              'pupil', filename)
            exists = user_model.exists(user_name, password)
            session['username'] = user_name
            session['user_id'] = exists[1]
            return redirect("/index")
        elif not (exists[0]) and (true_password or not teacher_exist
                                  or not file_ok):
            already = False
        else:
            already = True
    return render_template('reg.html',
                           title='Регистрация',
                           form=form,
                           already=already,
                           true_password=true_password,
                           teacher_exist=teacher_exist,
                           file_ok=file_ok)
Exemple #8
0
from db import DB
from add_achieve import AddAchieveForm
from flask import Flask, redirect, render_template, session, url_for
from login_form import LoginForm
from user_model import UsersModel
from achieve_model import AchieveModel
from reg_form import RegisterForm
from change_model import ChangeForm
from regteacher_form import RegisterTeacherForm
from werkzeug import secure_filename

app = Flask(__name__)
app.config['SECRET_KEY'] = 'yandexlyceum_secret_key'
db = DB()
AchieveModel(db.get_connection()).init_table()
UsersModel(db.get_connection()).init_table()
admin_model = UsersModel(db.get_connection())
existss = admin_model.exists('Raisa', '1234')
if not (existss[0]):
    pass
    admin_model.insert('Метелёва Раиса Филипповна', '-', 'Raisa', '1234', '-',
                       'teacher', 'raisa.jpg')

existss = admin_model.exists('Grisha', '1234')
if not (existss[0]):
    pass
    admin_model.insert('Носов Григорий Леонидович', '-', 'Grisha', '1234', '-',
                       'teacher', 'grisha.jpg')


# http://127.0.0.1:8080/login