Exemplo n.º 1
0
def login(request: HttpRequest):
    if request.method == 'POST':
        login = request.POST.get('login', "")
        password = request.POST.get('pass', "")
        try:
            user = User.objects.get(login=login)
            print(password)
            print(utils.hash_password(password))
            print(user.password)
            if not utils.check_password(user.password, password):
                map = get(request)
                msg = messages.Message("Błąd logowania", "Złe hasło", [])
                map['msg'] = msg
                return render_to_response('main.html', map)
            request.session['user'] = user.id
            map = get(request)
            msg = messages.Message("Zalogowano", "Logowanie przebiegło pomyślnie", [])
            map['msg'] = msg
            return render_to_response('main.html', map)
        except User.DoesNotExist:
            map = get(request)
            msg = messages.Message("Błąd logowania", "Użytkownik nie istnieje", [])
            map['msg'] = msg
            return render_to_response('main.html', map)
    map = get(request)
    return render_to_response('main.html', map)
Exemplo n.º 2
0
def register(request: HttpRequest):
    if request.method == 'POST':
        login = request.POST.get('login', "")
        password1 = request.POST.get('pass1', -1)
        password2 = request.POST.get('pass2', -1)
        realname = request.POST.get('realname', "")
        email = request.POST.get('email', "")
        map = get(request)
        map['login'] = login
        map['email'] = email
        map['realname'] = realname
        if password1 != password2:
            msg = messages.Message("Hasła nie zgadzają się!", [])
            map['msg'] = msg
        elif len(password1) < 4:
            msg = messages.Message("Twoje hasło jest za krótkie!", [])
            map['msg'] = msg
        elif not re.match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$", email):
            msg = messages.Message("Wprowadź poprawnie adres email", [])
            map['msg'] = msg
        else:
            msg = messages.Message("Błąd!", "Rejestracja nie powiodła się, sprawdź wprowadzone dane.", [])
            map = get(request)
            map['msg'] = msg
            map['login'] = login
            map['email'] = email
            map['realname'] = realname
            user = User()
            user.login = login
            user.email = email
            user.real_name = realname
            print(password1)
            user.password = utils.hash_password(password1)
            print(user.password)
            user.privilages = AccountPrivilages.objects.get(id=1)
            user.credits = 100
            user.save()
            map = get(request)
            return render_to_response('main.html', map)
    else:
        map = get(request)
    return render_to_response('register.html', map)