Example #1
0
def register():
    form = RegForm()
    if form.validate_on_submit():
        user_name = form.username.data
        password = form.password.data
        repassword = form.repassword.data
        content = form.content.data
        filename = secure_filename(content.filename)
        user_model = UsersModel(db.get_connection())
        print(user_name)
        exists = user_model.login_used(user_name)
        if exists:
            return render_template('register.html',
                                   title='Регистрация',
                                   form=form)
        else:
            if password == repassword:
                if os.path.isfile(os.path.join('static', 'img', filename)):
                    while os.path.isfile(
                            os.path.join('static', 'img', filename)):
                        filename = filename.split('.')
                        filename = '.'.join([filename[0] + 'A', filename[-1]])
                content.save(os.path.join('static', 'img', filename))
                user_model.insert(user_name, password, filename)
                exists = user_model.exists(user_name, password)
                session['username'] = user_name
                session['user_id'] = exists[1][0]
                session['content'] = exists[1][-1]
            else:
                return render_template('register.html',
                                       title='Регистрация',
                                       form=form)
        return redirect("/index")
    return render_template('register.html', title='Регистрация', form=form)
Example #2
0
def add_user():
    form = AddNewUser()
    if form.validate_on_submit():
        user_name = form.username.data
        pass_word = form.password.data
        um = UsersModel(db.get_connection())
        um.insert(user_name, pass_word)  #проверить, что его нет
    return render_template('add_user.html',
                           title='Добавление пользователя',
                           form=form)
Example #3
0
def signup():
    form = SignUpForm()
    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)
        user_model.insert(user_name, password)
        return redirect("/login")
    return render_template("signup.html", title="Регистрация", form=form)
Example #4
0
def registration(er=None):
    form = RegistrationForm()
    if form.validate_on_submit():
        users = UsersModel(db.get_connection())
        users.insert(
            form.username.data,
            str(md5(bytes(form.password.data,
                          encoding='utf-8')).hexdigest()))  #add new user
        return redirect('/login')
    return render_template('registration.html', form=form, error=er)
Example #5
0
def sign_up():
    if request.method == 'GET':
        return render_template(
            'sign_up.html',
            title='Please fill in this form to create an account:')
    elif request.method == 'POST':
        um = UsersModel(db.get_connection())
        um.init_table()
        um.insert(request.form['email'], request.form['uname'],
                  request.form['pswd'])
        session['username'] = request.form['uname']
        print(um.get_all())
        return redirect('/main')
Example #6
0
def register():
    if 'username' in session:
        return redirect('/')
    form = RegisterModel()
    if form.validate_on_submit():
        user_name = form.user_name.data
        password = form.password.data
        user = UsersModel(db.get_connection())
        flag = user.is_username_busy(user_name)
        if flag and user_name not in admins:
            user.insert(user_name, password)
            session['username'] = user_name
            exists = user.exists(user_name, password)
            session['user_id'] = exists[1]
            return redirect("/")
        else:
            return render_template('register.html', form=form, error=1)
    return render_template('register.html', form=form)
Example #7
0
def registration(er=None):
    form = RegistrationForm()
    if form.validate_on_submit():  # if password, login, and photo is not empty
        users = UsersModel(db.get_connection())
        if users.exists_only_by_name(form.username.data):
            return redirect(
                '/registration/exists'
            )  # if user is already in db you should do reregistration
        else:
            users.insert(
                form.username.data,
                str(
                    md5(bytes(form.password.data, encoding='utf-8')).hexdigest(
                    )))  # add to db hash of the password for better encryption
            form.fileName.data.save(
                os.path.join(os.path.join('static', 'avas'),
                             str(users.get_table_size()) + ".jpg"))
            return redirect('/login')
    return render_template('registration.html', form=form, error=er)
Example #8
0
File: main.py Project: Kaisa1906/--
def registration(er=None):
    form = RegistrationForm()
    if form.validate_on_submit():
        users = UsersModel(db.get_connection())
        udm = UserDataModel(db.get_connection())
        find = users.find(form.username.data)
        if find[0]:
            return redirect('/registration/exists')
        else:
            if form.username.data == 'admin':
                users.insert(form.username.data, form.password.data, 'admin')
            else:
                users.insert(form.username.data, form.password.data,
                             'user')  # add new user
            udm.insert(form.username.data, 'Фамилия', 'Имя', 'Отчество',
                       'Адрес', 'Номер счетчика')
            return redirect('/login')
    return render_template('registration.html',
                           form=form,
                           error=er,
                           text="Авторизоваться")
Example #9
0
from add_news import AddNewsForm
from db import DB
from loginform import LoginForm
from news_model import NewsModel
from users_model import UsersModel


#инициализируем таблицу
db = DB('db.db')
UsersModel(db.get_connection()).init_table()
user_ = UsersModel(db.get_connection())
#добавляем пользователя (по одному!!!!!)
user_.insert('Admin','pass')