Esempio n. 1
0
def auth_create():
    form = NewUserForm(request.form)

    if not form.validate():
        return render_template("auth/new.html", form=form)

    if form.new_password.data != form.repeat_password.data:
        form.repeat_password.errors.append('Passwords do not match')
        return render_template("auth/new.html", form=form)
    pw_hash = bcrypt.generate_password_hash(
        form.new_password.data).decode('utf-8')

    u = User(name=form.name.data, username=form.username.data,
             password=pw_hash, email=form.email.data)

    db.session.add(u)

    try:
        default_category = db.session.query(Category).get(1)
        u.categories.append(default_category)
        db.session.commit()
    except IntegrityError:
        db.session.rollback()
        return render_template("auth/new.html", form=form, username_taken=True)

    return redirect(url_for("auth_index"))
Esempio n. 2
0
def auth_new():
    if request.method == "GET":
        return render_template("auth/newuserform.html", form = NewUserForm(), add_user=True)
    form = NewUserForm(request.form)

    if request.method == 'POST' and form.validate():

        first_name = form.first_name.data
        last_name = form.last_name.data
        phone = form.phone_number.data
        email = form.email.data
        username = form.username.data
        pword = form.password.data
        admin = form.admin.data
        
        print(admin)

        if not email:
            user = Kayttaja(first_name.title(), last_name.title(), username, phone, pword, admin)
        else:
            user = Kayttaja(first_name.title(), last_name.title(), username, phone, pword, admin, email)


        db.session().add(user)
        db.session.flush()
        if admin == 1:
           adminrole = roles.insert().values(role_id = 1, kayttaja_id = user.id)
           db.session.execute(adminrole)
        
        user_role = roles.insert().values(role_id = 2, kayttaja_id = user.id)
        db.session.execute(user_role)
        db.session().commit()

        return redirect(url_for("index"))
    return render_template("auth/newuserform.html", form = form, add_user=True)
Esempio n. 3
0
def users_create():
    form = NewUserForm(request.form)

    if not form.validate():
        return render_template("auth/new.html", form=form)

    username = form.username.data
    if User.query.filter_by(username=username).first() is None:
        user = User(username, form.password.data)
    else:
        return render_template("auth/new.html",
                               form=NewUserForm(),
                               message="This username is already taken")

    users_in_database = User.query.order_by(User.username).all()

    if users_in_database:
        user.role = "DEFAULT"
    else:
        user.role = "ADMIN"

    db.session().add(user)
    db.session().commit()

    return redirect(url_for("auth_login"))
Esempio n. 4
0
def user_create_as_admin():
    form = NewUserForm(request.form)

    if not form.validate():
        return render_template("auth/new.html", form = form)

    user = User.query.filter_by(username=form.username.data).first()
    if user is not None:
        return render_template("auth/new.html", form = form,
                               error = "Käyttäjänimi on jo varattu")

    u = User(form.name.data, form.username.data, form.password.data, form.email.data, form.phone.data)

    db.session().add(u)
    db.session().commit()

    role = Role.query.filter_by(name="user").first()
    user = User.query.filter_by(username=u.username).first()

    if role is None:
        db.session.add(Role("user"))
        db.session.commit()
        role = Role.query.filter_by(name="user").first()

    if form.admin.data == True:
         role = Role.query.filter_by(name="admin").first()

    user_role = UserRole(user.id, role.id)
    db.session.add(user_role)
    db.session.commit()

    return redirect(url_for("list_users"))
Esempio n. 5
0
def users_create():
    form = NewUserForm(request.form)
    if not form.validate():
        return render_template("auth/new.html", form=form)

    user = User(form.name.data, form.username.data, form.password.data,
                form.is_teacher.data)

    db.session().add(user)
    db.session().commit()

    return redirect(url_for("index"))
Esempio n. 6
0
def create_new_user():
    form = NewUserForm(request.form)
    if not form.validate():
        return render_template("auth/newuserform.html", form=form)
    username = request.form.get("username")
    password = request.form.get("password")

    u = User(username, username, password)
    db.session().add(u)
    db.session().commit()

    return redirect(url_for("account_created"))
Esempio n. 7
0
def user_create():
    form = NewUserForm(request.form)

    if form.validate() and request.method == 'POST':
        a = User(form.name.data, form.username.data, form.password.data)

        db.session().add(a)
        db.session().commit()

        return redirect(url_for("auth_login"))

    return render_template("auth/newuser.html", form=form)
Esempio n. 8
0
def create_new_user():
    form = NewUserForm(request.form)
    possibleUser = User.query.filter_by(username=form.username.data).first()
    if possibleUser:
        return render_template("auth/newuser.html", form = form, error = "Username already taken")

    if not form.validate():
        return render_template("auth/newuser.html", form = form, error = "All fields are required. Minimum password length is 6 characters")
    role = "S"
    pw_hash = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
    t = User(form.name.data, form.username.data, pw_hash, role)
    db.session().add(t)
    db.session().commit()
    return redirect(url_for("courses_index"))
Esempio n. 9
0
def auth_create():
    if request.method == "GET":
        return render_template("auth/signup.html", form=NewUserForm())

    form = NewUserForm(request.form)
    if not form.validate():
        return render_template("auth/signup.html", form=form)

    pw = form.password.data
    pw_hash = bcrypt.generate_password_hash(pw).decode('utf-8')
    u = User(form.name.data, form.username.data, pw_hash)

    db.session().add(u)
    db.session().commit()

    return redirect(url_for("auth_login"))
Esempio n. 10
0
def users_create():
    form = NewUserForm(request.form)

    if not form.validate():
        return render_template("auth/new.html", form=form)

    username = form.username.data
    if User.query.filter_by(username=username).first() is None:
        user = User(username, form.password.data)
    else:
        return render_template("auth/new.html", form=NewUserForm())

    db.session().add(user)
    db.session().commit()

    return redirect(url_for("auth_login"))
Esempio n. 11
0
def auth_new():
    form = NewUserForm(request.form)
    if request.method == "GET":
        return render_template("auth/newuserform.html", form=form)
    if not form.validate():
        return render_template("auth/newuserform.html",
                               form=form,
                               errors=form.errors.items())

    user = User(username=str(form.username.data),
                password=bcrypt.generate_password_hash(str(
                    form.password.data)).decode("utf-8"))
    db.session().add(user)
    db.session().commit()
    return render_template(
        "auth/loginform.html",
        form=LoginForm(request.form),
        success="Account created successfully, you can now log in")
Esempio n. 12
0
def auth_register():
    if request.method == "GET":
        return render_template("auth/registerform.html", form=NewUserForm())

    form = NewUserForm(request.form)
    if not form.validate():
        return render_template("auth/registerform.html", form=form)

    user = User(form.name.data, form.username.data, form.password.data,
                form.email.data)

    db.session().add(user)
    db.session().commit()

    user.set_default_role()

    login_user(user)
    return redirect(url_for("index"))
Esempio n. 13
0
def auth_newuser():
    if request.method == "GET":
        return render_template("auth/newuserform.html", form = NewUserForm())

    form = NewUserForm(request.form)

    user = User.query.filter_by(username=form.username.data, password=form.password.data).first()
    if user:
        return render_template("auth/newuserform.html", form = form,
                                error = "Käyttäjätunnus on jo käytössä, valitse jokin toinen käyttäjätunnus!")
    else:
        u = User(form.name.data, form.username.data, form.password.data)

        db.session().add(u)
        db.session().commit()

        login_user(u)
        return redirect(url_for("index"))
Esempio n. 14
0
def auth_new():
    if request.method == "GET":
        return render_template("auth/registrationform.html",
                               form=NewUserForm())

    form = NewUserForm(request.form)
    if not form.validate():
        return render_template("auth/registrationform.html", form=form)

    name = form.name.data
    username = form.username.data
    password = form.password.data
    role_id = int(form.role.data)

    new_user = User(name, username, password)
    new_user.role_id = role_id

    db.session().add(new_user)
    db.session().commit()
    return redirect(url_for("index"))
Esempio n. 15
0
def edit_user(user_id):


    kayttaja = Kayttaja.query.get_or_404(user_id)
    form = NewUserForm(obj=kayttaja)
    bookings = kayttaja.get_booking_infos()
    

    if request.method == "POST" and form.validate():
        kayttaja.first_name = form.first_name.data
        kayttaja.last_name = form.last_name.data
        kayttaja.phone_number = form.phone_number.data
        kayttaja.email = form.email.data
        kayttaja.username = form.username.data
        kayttaja.password = form.password.data
        kayttaja.admin = form.admin.data

        db.session().commit()

        return redirect(url_for("user_info", user_id=user_id))

    return render_template("auth/newuserform.html", form=form, kayttaja=kayttaja, user_id=user_id,
                           varaukset=bookings, add_user=False)
Esempio n. 16
0
def newUser_admin():
    return render_template("admin/auth/new.html", form = NewUserForm())
Esempio n. 17
0
def user_registration():
    return render_template("auth/newuserform.html", form=NewUserForm())
Esempio n. 18
0
def new_user_form():
    return render_template("auth/newuser.html", form = NewUserForm())
Esempio n. 19
0
def auth_form():
    return render_template("auth/new.html", form=NewUserForm())
Esempio n. 20
0
def new_user_form():
    return render_template("auth/new.html", form=NewUserForm(), message="")