Example #1
0
def register():
    if request.method == "POST" and session['user'] == None:
        if baza.dobi_uporabnika(username=request.form["username"]) is None:
            baza.vstavi_novega_uporabnika(username=request.form["username"],
                                          password=request.form["password"])
            session['user'] = baza.dobi_uporabnika(
                username=request.form["username"],
                password=request.form["password"])
            session['registriran'] = 1
        else:
            session['registriran'] = None
    return render_template("register.html")
Example #2
0
def druga():
    if request.method == 'POST':
        session['user'] = baza.dobi_uporabnika(
            username=request.form['username'],
            password=request.form['password'])

    return render_template("druga_stran.html")
Example #3
0
def register():
    if session.get('user') is not None:
        return redirect('/')
    if request.method == 'GET':
        return render_template("register.html")
    elif request.method == 'POST':
        if len(request.form['username']) < 3:
            return render_template("register.html", error="Prekratko ime")
        if baza.dobi_uporabnika(username=request.form['username']):
            return render_template("register.html",
                                   error="Uporabnik že obstaja")
        if len(request.form['password']) < 3:
            return render_template("register.html", error="Prekratko geslo")
        if request.form['password'] != request.form['password2']:
            return render_template("register.html",
                                   error="Gesli se ne ujemata")
        user_id = baza.vstavi_novega_uporabnika(
            username=request.form['username'],
            password=request.form['password'])
        session['user'] = baza.dobi_uporabnika(user_id)
        return redirect('/')
Example #4
0
def login():
    if session.get('user') is not None:
        return redirect('/')
    if request.method == 'GET':
        return render_template("login.html")
    elif request.method == 'POST':
        session['user'] = baza.dobi_uporabnika(
            username=request.form['username'],
            password=request.form['password'])
        if session['user'] is None:
            return render_template("login.html", error="Napačni podatki")
        else:
            return redirect('/')
Example #5
0
    def test_register(self):
        response = self.app.get('/register')
        assert response.status_code == 200
        assert b"Registriraj se!" in response.data

        response = self.app.post('/register',
                                 data={
                                     "username": "******",
                                     "password": "******",
                                     "password2": "netest"
                                 })
        assert response.status_code == 200
        assert b"Gesli se ne ujemata" in response.data

        response = self.app.post('/register',
                                 data={
                                     "username": "******",
                                     "password": "******",
                                     "password2": "test"
                                 })
        assert response.status_code == 302

        response = self.app.get('/')
        assert response.status_code == 200
        assert b"testUsername" in response.data
        assert b"Odjava" in response.data

        user = baza.dobi_uporabnika(username="******")
        assert user[1] == "testUsername"

        response = self.app.get('/logout')
        assert response.status_code == 302

        response = self.app.get('/')
        assert response.status_code == 200
        assert b"Prijava" in response.data

        response = self.app.post('/login',
                                 data={
                                     "username": "******",
                                     "password": "******"
                                 })
        assert response.status_code == 302

        response = self.app.get('/')
        assert response.status_code == 200
        assert b"testUsername" in response.data
        assert b"Odjava" in response.data
Example #6
0
def login():
    if request.method == "POST":
        session['user'] = baza.dobi_uporabnika(
            username=request.form["username"],
            password=request.form["password"])
    return render_template("druga_stran.html")