<commit_before>from flask import Blueprint, abort, request, redirect, session, url_for
from flask.ext.login import current_user, login_user, logout_user
from truecraft.database import db
from truecraft.objects import *
from truecraft.common import *
from truecraft.config import _cfg

import os
import hashlib
import datetime

legacy = Blueprint('api', __name__, template_folder='../../templates')

@legacy.route("/api/login", methods=["POST"])
@with_session
def login():
    username = request.form.get('user')
    password = request.form.get('password')
    version = request.form.get('version')
    if not username or not password or not version:
        return "Missing username or password or launcher version parameters"
    if version != "12":
        return "Old Version"
    user = User.query.filter(User.username.ilike(username)).first()
    if bcrypt.checkpw(password, user.password):
        salt = os.urandom(40)
        user.sessionId = hashlib.sha256(salt).hexdigest()
        user.sessionExpiry = datetime.datetime.utcnow() + datetime.timedelta(minutes = 10)
        # first number doesn't really matter
        return "1281688214000:deprecated:{}:{}".format(user.username, user.sessionId)
    else:
        return "Invalid username or password"

@legacy.route("/session")
@with_session
def keep_alive():
    username = request.args.get('name')
    sessionId = request.args.get('session')
    if not username or not sessionId:
        return "Missing username or session parameters"
    user = User.query.filter(User.username.ilike(username)).first()
    if datetime.datetime.utcnow() > user.sessionExpiry:
        return "Session expired."
    if sessionId != user.sessionId:
        return "Invalid session key"
    return "Session renewed."<commit_msg>Fix NoneType exception for bad usernames<commit_after>from flask import Blueprint, abort, request, redirect, session, url_for
from flask.ext.login import current_user, login_user, logout_user
from truecraft.database import db
from truecraft.objects import *
from truecraft.common import *
from truecraft.config import _cfg

import os
import hashlib
import datetime

legacy = Blueprint('api', __name__, template_folder='../../templates')

@legacy.route("/api/login", methods=["POST"])
@with_session
def login():
    username = request.form.get('user')
    password = request.form.get('password')
    version = request.form.get('version')
    if not username or not password or not version:
        return "Missing username or password or launcher version parameters"
    if version != "12":
        return "Old Version"
    user = User.query.filter(User.username.ilike(username)).first()
    if not user:
        return "Invalid username or password"
    if bcrypt.checkpw(password, user.password):
        salt = os.urandom(40)
        user.sessionId = hashlib.sha256(salt).hexdigest()
        user.sessionExpiry = datetime.datetime.utcnow() + datetime.timedelta(minutes = 10)
        # first number doesn't really matter
        return "1281688214000:deprecated:{}:{}".format(user.username, user.sessionId)
    else:
        return "Invalid username or password"

@legacy.route("/session")
@with_session
def keep_alive():
    username = request.args.get('name')
    sessionId = request.args.get('session')
    if not username or not sessionId:
        return "Missing username or session parameters"
    user = User.query.filter(User.username.ilike(username)).first()
    if datetime.datetime.utcnow() > user.sessionExpiry:
        return "Session expired."
    if sessionId != user.sessionId:
        return "Invalid session key"
    return "Session renewed."
{'fraction_non_alphanumeric': 0.11261013215859031, 'fraction_numerical': 0.012114537444933921, 'mean_word_length': 3.8055555555555554, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4799308', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1013, 'n_words': 290}