def user_loader(username): if username not in myusers.find(): return user = User() user.id = username return user
def request_loader(request): username = request.form.get('username') password = request.form.get('password', '') access = request.form.get('access') if username not in myusers.find(): return user = User() user.id = username user.is_authenticated = compare_digest(password, myusers[username]['password']) return user
def login_cookies(): user = User.get_user(request.cookies.get("username")) password = request.cookies.get("password") # If the user exist and if it equals to the password, return if user and user.password == password: return render_template("index.html", config=Config.config, user=user), user
def login_or_register(): # If the request method is 'Get' it means that we're just requesting the page and not sending any form if request.method == "POST": username = request.values.get("inputtext1") password = request.values.get("inputtext2") user = User.get_user(username) # If user is None, it means it doesn't exist and we have to create it. if not user: User.new_user(username, password, False) user = User.get_user(username) if user.password == password: # Converting the template into a response resp = make_response( render_template("index.html", config=Config.config, user=user)) # Setting the cookies resp.set_cookie("username", username) resp.set_cookie("password", password) return resp, user
def database_initialization_sequence(): from blog import User print('db init...') test_rec = User( username='******', email='*****@*****.**', #'demo.jpg', password='******', ) db.session.add(test_rec) db.session.rollback() print('db test complete. ') db.session.commit()
if __name__ == "__main__": import pymysql pymysql.install_as_MySQLdb() from blog import db from blog import User db.create_all() user1 = User(username='******', email='*****@*****.**', password='******') db.session.add(user1) db.session.commit() print(User.query.all())
def create_user(user, password): """Creates the admin user.""" from blog import User u = User(user, password) db.session.add(u) db.session.commit()