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")
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")
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('/')
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('/')
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
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")