コード例 #1
0
def user():
    if current_user.is_authenticated:
        username = current_user.username
        user = UserService.get_by_username(username)
    if user:
        posts = [
            {'author': user, 'body': 'Test post #1'},
            {'author': user, 'body': 'Test post #2'}
        ]
        return render_template('user.html', user=user, posts=posts)
    return 'Not found user'
コード例 #2
0
def index():
    # print(app.config['SECRET_KEY'])
    if not current_user:
        flash("Please login!!")
        return redirect(url_for("login"))
    user = UserService.get_by_username(current_user.username)
    posts = [
        {
            'author': {'username': '******'},
            'body': 'Beautiful day in Portland!'
        },
        {
            'author': {'username': '******'},
            'body': 'The Avengers movie was so cool!'
        }
    ]
    return render_template('index.html', title="Home", posts=posts, user = user)
コード例 #3
0
def authen():
    # if current_user.is_authenticated:
    if session.get('username'):
        username = session.get('username')
        # username = current_user.username
        user = UserService.get_by_username(username)
        session['base32_key'] = user.base32_key
        if request.method == "POST":
            totp = pyotp.TOTP(session.get('base32_key'))
            otp = request.json['otp']
            if totp.verify(otp):
                login_user(user)
                return {'status': 'Ok',
                        'next_page': session.get('next_page')
                }
            return {'status': 'Wrong code'}
        return render_template('2authentication.html', user=user)
    return "Not found user"
コード例 #4
0
 def validate_username(self, username):
     user = UserService.get_by_username(username.data)
     if user is not None:
         raise ValidationError('Please use a different username.')
コード例 #5
0
def qrcode():
    if not current_user.is_authenticated:
        return redirect(url_for('login'))
    user = UserService.get_by_username(current_user.username)

    return render_template('qrcode.html', user = user)