def test_new_user(self): cnx = db.connect() cursor = cnx.cursor(dictionary=True) cursor.execute("DELETE FROM users WHERE name='Bruno'") newUser = dict(name="Bruno", email="*****@*****.**", password="******", birthday="1990-01-01") users.new_user(newUser, cursor) cursor.execute("SELECT * FROM users WHERE name='Bruno'") insertedEntry = cursor.fetchall()[0] self.assertEqual(insertedEntry["name"], "Bruno") self.assertEqual(insertedEntry["email"], "*****@*****.**") self.assertEqual(insertedEntry["password"], "1234") self.assertEqual(insertedEntry["birthday"], datetime.datetime(1990, 1, 1)) self.assertEqual(insertedEntry["mod_level"], 0) # Checks errors for already registered name and email. self.assertEqual( users.new_user(dict(name="Bruno", email="*****@*****.**"), cursor), "name") self.assertEqual( users.new_user(dict(name="no-Bruno", email="*****@*****.**"), cursor), "email") cursor.close() cnx.close()
def register(): form = RegistrationForm(request.form) if request.method == "GET": return render_template("register.html", form=form) if request.method == "POST" and form.validate(): if users.new_user(form.username.data, form.password.data, form.first_name.data, form.last_name.data): if (form.player.data == True): jersey = form.jersey.data if jersey < 0: jersey = 0 height = form.height.data if height < 0: height = 0 weight = form.weight.data if weight < 0: weight = 0 if players.new_player(form.username.data, jersey, height, weight, form.position.data): return redirect("/") else: render_template("error.html",message="Rekisteröinti ei onnistunut") else: return redirect("/") else: return render_template("error.html",message="Rekisteröinti ei onnistunut. Nimimerkki saattaa olla varattu.") else: return render_template("error.html",message="Rekisteröinti ei onnistunut")
def new_user(newUser): cnx = db.connect() cursor = cnx.cursor(dictionary=True) answer = users.new_user(json.loads(newUser), cursor) cursor.close() cnx.commit() cnx.close() return answer
def admin_new_user(): """admin function to add new users""" usr = verify_user() if not usr or not users.is_admin(usr["email"]): raise EXCEPTION_UNAUTHORIZED name = get_req("name") email = get_req("email") return users.new_user({"email": email, "name": name})
def signup_data(): username = request.form["username"] password = request.form["password"] if username == "" or password == "": return render_template("signup.html", error="tunnus tai salasana ei voi olla tyhjä") if len(username) > 10: return render_template("signup.html", error="käyttäjänimi on liian pitkä") if users.username_exists(username): return render_template("signup.html", error="tunnus on jo käytössä") id = users.new_user(username, password) return render_template("login.html", message="Uusi tunnus luotu")
def users_route(user_id=None): if request.method == 'POST': first_name = utils.get_field(request, 'first_name', required=True) last_name = utils.get_field(request, 'last_name', required=True) email = utils.get_field(request, 'email', required=True) password = utils.get_field(request, 'password') fb_id = utils.get_field(request, 'fb_id') return users.new_user(first_name, last_name, email, password, fb_id) if user_id is None: return users.get_all_users() return users.get_user(user_id)