예제 #1
0
def home(request):
    text = """<h1>Page d'accueil !</h1>"""

    user = User()
    user._username = "******"
    text += user._username
    return HttpResponse(text)
예제 #2
0
def home(request):
    """
    request:
    URL: get/token/username
    POST: name_or_mail, pass

    return:
    {
        "statusOk", 0 ou 1
        "statusId", # Status (voire README)
        "statusName", # nom (description) du status
    }

    """
    nameormail = request.POST['name_or_mail']
    print(request.POST['name_or_mail'])
    print(request.POST['passHash'])
    passHash = hashlib.sha512(request.POST['passHash'].encode('utf8')).hexdigest()

    statusOk = 0
    statusId = 200
    statusName = "OK"

    user = User()
    response = HttpResponse()
    if user.userExistByUsername(nameormail):
        """ """
        token = user.newTokenByUsername(nameormail, passHash)
        if token == 1500:
            statusOk = 0
            statusId = 403
            statusName = "Mauvaise combinaison de username et mot de passe"
        else:
            print("*************Le user '" + nameormail + "' est à présent connecté.")
            response.set_cookie("token", token)
            response.set_cookie("nameormail", nameormail)
            print(token)
    elif user.userExistByEmail(nameormail):
        """ """
        token = user.newTokenByEmail(nameormail, passHash)
        if token == 1500:
            statusOk = 0
            statusId = 403
            statusName = "Mauvaise combinaison de e-mail et mot de passe"
        else:
            response.set_cookie("token", token)
            print(token)
    else:
        statusOk = 0
        statusId = 503
        statusName = "Mauvais e-mail ou username"

    text = {
        "statusOk": statusOk,
        "statusId": statusId,
        "statusName": statusName,
        }
    response.write(json.dumps(text)) # On converti le JSON en String pour le renvoyer
    return response