Beispiel #1
0
def sign_up():
    form = RegistrationForm()
    if form.validate_on_submit():
        username = form.username.data
        password1 = form.password1.data
        password2 = form.password2.data
        users_model = UsersModel(db.get_connection())
        for user in users_model.get_all():
            if user[1] == username:
                return render_template('registration.html',
                                       title='Регистрация',
                                       form=form,
                                       error_text='Этот логин уже занят')
        if len(password1) < 5:
            return render_template('registration.html',
                                   title='Регистрация',
                                   form=form,
                                   error_text='Пароль слишком короткий')
        elif password1 != password2:
            return render_template('registration.html',
                                   title='Регистрация',
                                   form=form,
                                   error_text='Пароли различаются')
        else:
            users_model.insert(username, generate_password_hash(password1))
            return redirect('/login')
    return render_template('registration.html', title='Регистрация', form=form)
Beispiel #2
0
def registration():
    global recent
    recent = 'registration'
    form = RegistrationForm()
    user_model = UsersModel(db.get_connection())
    if form.back.data:
        return redirect('/login')
    elif form.validate_on_submit():
        user_name = form.username.data
        password = form.password.data
        email = form.email.data
        about = form.about.data
        user_model.insert(user_name, password, email, about)
        # Проверка, точно ли все в базе
        exists = user_model.exists(user_name, password)
        if exists[0]:
            session['username'] = user_name
            session['user_id'] = exists[1]
        # Переход к новостям
        return redirect('/index')
    return render_template('registration.html',
                           title='Регистрация',
                           form=form,
                           err='',
                           about_page='Расскажите нам немного о себе!',
                           session=session)
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        users = UsersModel(db.get_connection())
        users.insert(form.username.data, form.password.data)
        speak('registration successful!')
        flash('You have successfully registered', 'success')
        return redirect('/login')
    return render_template('register.html', title='Registration', form=form)
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        users = UsersModel(db.get_connection())
        if not users.get_by_name(form.username.data):
            hashed_password = generate_password_hash(form.password.data)
            users.insert(form.username.data, hashed_password)
            flash('Спасибо за регистрацию', 'success')
            return redirect('/login')
        else:
            form.username.errors.append(
                'Пользователь с таким именем уже существует')
    return render_template('project_register.html',
                           title='Instagram',
                           form=form,
                           user_info={'userid': 0})
Beispiel #5
0
def registration():
    try:
        session.pop('username', 0)
        session.pop('user_id', 0)
    except Exception:
        pass
    form = RegistrationForm()
    if form.validate_on_submit():
        user_name = form.username.data
        password = form.password.data
        age = form.age.data
        user_model = UsersModel(db.get_connection())
        exists = user_model.exists(user_name, password)
        if not (exists[0]):
            um = UsersModel(db.get_connection())
            um.insert(user_name, password, age)
            return redirect("/login")
    return render_template('registration.html',
                           title='Tattle Crime',
                           form=form)
Beispiel #6
0
                           title='Избранное',
                           username=session['username'],
                           favourites=res)


@app.route('/favourites/<int:perf_id>/delete')
def delete_from_favourites(perf_id):
    if 'username' not in session:
        return redirect('/login')
    user_id = session['user_id']
    users_model = UsersModel(db.get_connection())
    favourites = users_model.get_favourites(user_id).split(',')
    if str(perf_id) not in favourites:
        return redirect('/performances')
    del favourites[favourites.index(str(perf_id))]
    users_model.edit_favourites(user_id, ','.join(favourites))
    return redirect('/performances')


if __name__ == '__main__':
    db = DataBase()
    ActorsModel(db.get_connection()).init_table()
    PerformancesModel(db.get_connection()).init_table()
    um = UsersModel(db.get_connection())
    um.init_table()

    if not um.exists(ADMIN_NAME)[0]:
        um.insert(ADMIN_NAME, ADMIN_PASSWORD_HASH)

    app.run(port=8080, host='127.0.0.1')