Exemplo n.º 1
0
def signup_berber_page():
    if request.method == 'GET':
        return render_template("signup_berber.html")
    else:
        person = People()
        person.username = request.form["username"]
        person.name_surname = request.form["name_surname"]
        person.mail = request.form["mail"]
        person.password_hash = hasher.hash(request.form["password"])
        person.gender = request.form["gender"]
        person.age = request.form["age"]
        person.role = "berber"
        people = Peoplemodel()

        if (people.control_exist(person)):
            return render_template("signup_berber.html", message="False")
        else:
            people.save(person)
            berbers = Berbermodel()
            berber = Berber()
            berber.people_id = berbers.get_id(person.username)[0]
            berber.gender_choice = request.form["gender_choice"]
            berber.experience_year = request.form["experience"]
            berber.start_time = request.form["start_time"][:2]
            berber.finish_time = request.form["finish_time"][:2]
            berbers.insert(berber)
            return render_template("signup_berber.html", message="True")

        return redirect(url_for("signup_berber_page"))
Exemplo n.º 2
0
def signup_owner_page():
    if request.method == 'GET':
        return render_template("signup_owner.html")
    else:
        person = People()
        person.username = request.form["username"]
        person.name_surname = request.form["name_surname"]
        person.mail = request.form["mail"]
        person.password_hash = hasher.hash(request.form["password"])
        person.gender = request.form["gender"]
        person.age = request.form["age"]
        person.role = "owner"
        people = Peoplemodel()
        if (people.control_exist(person)):
            return render_template("signup_owner.html", message="False")
        else:
            owners = Ownermodel()
            owner = Owner()
            owner.tc_number = request.form["tc_number"]
            owner.serial_number = request.form["serial_number"]
            owner.vol_number = request.form["vol_number"]
            owner.family_order_no = request.form["family_order_no"]
            owner.order_no = request.form["order_no"]
            if (owners.control_exist_tc(owner.tc_number)):
                return render_template(
                    "signup_owner.html",
                    message="The TC Number has been saved already ")
            elif (len(owner.tc_number) != 11):
                return render_template(
                    "signup_owner.html",
                    message="TC Number Length must be 11 digits")
            elif (len(owner.serial_number) != 3):
                return render_template(
                    "signup_owner.html",
                    message="Serial number must be 3 digits")
            elif (len(owner.vol_number) != 3):
                return render_template("signup_owner.html",
                                       message="Vol number must be 3 digits")
            elif (len(owner.family_order_no) != 3):
                return render_template(
                    "signup_owner.html",
                    message="Family order number must be 3 digits")
            elif (len(owner.order_no) != 3):
                return render_template("signup_owner.html",
                                       message="Order number must be 3 digits")
            else:
                people.save(person)
                owner.people_id = owners.get_id(person.username)[0]
                owners.insert(owner)
                #tc kimlik varlığını kontrolü
                return render_template("signup_owner.html", message="True")

        return redirect(url_for("signup_owner_page"))
Exemplo n.º 3
0
def signup_user_page():
    if request.method == 'GET':
        return render_template("signup_user.html", message="")
    else:
        person = People()
        person.username = request.form["username"]
        person.name_surname = request.form["name_surname"]
        person.mail = request.form["mail"]
        person.password_hash = hasher.hash(request.form["password"])
        person.gender = request.form["gender"]
        person.age = request.form["age"]
        person.role = "user"

        people = Peoplemodel()
        if (people.save(person)):
            return render_template("signup_user.html", message="True")
        else:
            return render_template("signup_user.html", message="False")

        return redirect(url_for("signup_user_page"))
Exemplo n.º 4
0
def admin_panel():
    peoples = []
    people = Peoplemodel()
    berbers = Berbermodel()
    owners = Ownermodel()
    peoples = people.get_all_list()
    berber_list = []
    berber_list = berbers.get_all_list()
    owner_list = []
    owner_list = owners.get_all_list()

    if request.method == 'GET':
        if (current_user.role == "admin"):
            return render_template("admin_panel.html",
                                   people=peoples,
                                   berbers=berber_list,
                                   owners=owner_list)
        else:
            return render_template("signin.html", message="admin_error")
    else:
        if request.form["edit"] == "delete":
            form_movie_keys = request.form.getlist("people_keys")
            for i in form_movie_keys:
                for j in peoples:
                    if j.id == int(i) and j.role == "user":
                        people.delete_id(j.id)
                    elif j.id == int(i) and j.role == "berber":
                        berbers.delete_with_people_id(j.id)
                        people.delete_id(j.id)
                    elif j.id == int(i) and j.role == "owner":
                        owners.delete_with_people_id(j.id)
                        people.delete_id(j.id)

        elif "update" in request.form["edit"]:
            for i in peoples:
                x = request.form["edit"].split("_")[0]
                if int(x) == i.id:
                    person = People()
                    person.username = request.form["username"]
                    person.name_surname = request.form["name_surname"]
                    person.mail = request.form["mail"]
                    person.password_hash = hasher.hash(
                        request.form["password"])
                    person.gender = request.form["gender"]
                    person.age = request.form["age"]
                    person.role = "user"
                    person.id = i.id

                    #Validation
                    if len(person.name_surname) > 50 or len(
                            person.username) > 50 or len(person.mail) > 300:
                        return render_template(
                            "update.html",
                            person=i,
                            message="You should check input validations.")

                    if i.role == "user" or i.role == "admin":

                        if (people.update(person)):
                            return render_template("admin_panel.html",
                                                   people=peoples,
                                                   berbers=berber_list,
                                                   owners=owner_list,
                                                   message="True")
                        else:
                            return render_template("admin_panel.html",
                                                   people=peoples,
                                                   berbers=berber_list,
                                                   owners=owner_list,
                                                   message="False")
                    elif i.role == "berber":
                        berbers = Berbermodel()
                        berber = Berber()
                        berber.people_id = i.id
                        berber.gender_choice = request.form["gender_choice"]
                        berber.experience_year = request.form["experience"]
                        berber.start_time = request.form["start_time"][:2]
                        berber.finish_time = request.form["finish_time"][:2]
                        berbers = Berbermodel()
                        people.update(person)
                        berbers.update_berber(berber)
                        return render_template("admin_panel.html",
                                               people=peoples,
                                               berbers=berber_list,
                                               owners=owner_list,
                                               message="True")
                    elif i.role == "owner":
                        owner = Owner()
                        owner.people_id = owners.get_id(person.username)[0]
                        owner.tc_number = request.form["tc_number"]
                        owner.serial_number = request.form["serial_number"]
                        owner.vol_number = request.form["vol_number"]
                        owner.family_order_no = request.form["family_order_no"]
                        owner.order_no = request.form["order_no"]
                        if (owners.control_exist_tc(owner.tc_number)):
                            return render_template("admin_panel.html",
                                                   people=peoples,
                                                   berbers=berber_list,
                                                   owners=owner_list,
                                                   message="False")
                        people.update(person)
                        owners.update_owner(owner)
                        return render_template("admin_panel.html",
                                               people=peoples,
                                               berbers=berber_list,
                                               owners=owner_list,
                                               message="True")

        elif "order_id" in request.form["edit"]:
            peoples = sorted(peoples,
                             key=lambda people: people.id)  # sort by age
            return render_template("admin_panel.html",
                                   people=peoples,
                                   berbers=berber_list,
                                   owners=owner_list)

        elif "order_username" in request.form["edit"]:
            peoples = sorted(peoples,
                             key=lambda people: people.username)  # sort by age
            return render_template("admin_panel.html",
                                   people=peoples,
                                   berbers=berber_list,
                                   owners=owner_list)

        elif "order_role" in request.form["edit"]:
            peoples = sorted(peoples,
                             key=lambda people: people.role)  # sort by age
            return render_template("admin_panel.html",
                                   people=peoples,
                                   berbers=berber_list,
                                   owners=owner_list)

        else:
            for i in peoples:
                if int(request.form["edit"]) == i.id:
                    return render_template("update.html", person=i)

        return redirect(url_for("admin_panel"))