check if user log in flask
from flask_login import current_user
@app.route(...)
def your_route():
return current_user.is_authenticated
check if user log in flask
from flask_login import current_user
@app.route(...)
def your_route():
return current_user.is_authenticated
flask authentication user without database
class User(UserMixin):
def __init__(self, username, hash):
self.name = username
self.hash = hash
@property
def id(self):
return self.name
@self.server.route('/api/login', methods=['GET', 'POST'])
def login():
user = load_user(request.values.get('username'))
if user and user.hash == request.values.get('hash'):
login_user(user)
return jsonify(status='ok', username=user.username)
else:
return jsonify(status='error', message='wrong username or hash')
flask authentication
from flask import Flask
from flask_httpauth import HTTPBasicAuth
from werkzeug.security import generate_password_hash, check_password_hash
app = Flask(__name__)
auth = HTTPBasicAuth()
users = {
"john": generate_password_hash("hello"),
"susan": generate_password_hash("bye")
}
@auth.verify_password
def verify_password(username, password):
if username in users and
check_password_hash(users.get(username), password):
return username
@app.route('/')
@auth.login_required
def index():
return "Hello, {}!".format(auth.current_user())
if __name__ == '__main__':
app.run()
flask user create account at
<p><i class="fa fa-fw fa-calendar"></i>Create account at {{ user.create_account.strftime('%Y-%m-%d') }}</p>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us