Пример #1
0
def sign_up():
    #print(request.cookies.get('user', 'нету'))
    form = LoginForm(request.form)
    user = get_user_from_session_and_cookies()
    if user:
        return redirect(url_for('index'))


    if request.method == 'POST' and form.validate():

        try:
            user_md5 = md5()
            user_md5.update(bytearray(form.password.data, 'utf8'))
            user_password = user_md5.hexdigest()
            user = User(form.login.data, user_password, None)
            session_db.add(user)
            session_db.commit()
            flash('Login requested by login="******", remember me=' + str(form.remember_me.data))
            session['user'] = {'login':user.login, 'e_mail':user.e_mail, 'role':user.role}
            response = make_response(redirect(url_for('get_user', username=user.login)))
            if form.remember_me.data:
                response.set_cookie('user', user.login, max_age=157680000)
                response.set_cookie('password', user.password, max_age=157680000)

            return response
        except:
            session_db.rollback()
            flash('The user is already exists, ' + str(session_db.query(User).filter(User.role == 1).all()))
            return redirect(url_for('sign_up'))

    return render_template('login.html',
                           method=request.method,
                           title='Sign Up',
                           form=form,
                           page = '/signup')
Пример #2
0
def subscribe():
    # print(request.form['user_login'])
    if 'user' not in session:
        return redirect(url_for('user', username=request.form['user_login']))

    sub = Subscription(session['user']['login'], request.form['user_login'])
    session_db.add(sub)
    session_db.commit()

    return redirect(url_for('get_user', username=request.form['user_login']))
Пример #3
0
def make_post():
    if 'user' not in session:
        return redirect(url_for('index'))
    post = request.form.get('text_post')
    if post and len(post) < 250:
        post = Post(post, datetime.now(), session['user']['login'])
        session_db.add(post)
        session_db.commit()
        return redirect(url_for('get_user', username=session['user']['login']))
    flash('Post must be not empty and > 250 characters')
    return redirect(url_for('get_user', username=session['user']['login']))