示例#1
0
def user_loader(username):
    if username not in myusers.find():
        return

    user = User()
    user.id = username
    return user
示例#2
0
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
示例#3
0
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
示例#4
0
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
示例#5
0
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()
示例#6
0
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())
示例#7
0
def create_user(user, password):
    """Creates the admin user."""
    from blog import User
    u = User(user, password)
    db.session.add(u)
    db.session.commit()