Beispiel #1
0
def register():
    form = RegisterForm()
    form.university.choices = getAllUniversitiesForm()
    universities = getAllUniversities()
    return render_template("consumerViews/register.html",
                           universities=universities,
                           form=form)
Beispiel #2
0
class RegisterForm(FlaskForm):
    choices = [('0', 'Student'), ('1', 'Owner')]
    role = SelectField("Role", choices=choices, validate_choice=False
                       )
    username = StringField("username", validators=[
        DataRequired(),
        Length(min=1, max=64, message="The length of the name must be shorter than 65 characters.")
    ])
    email = EmailField("email", validators=[
        DataRequired(),
        Length(min=1, max=64, message="The length of the email must be shorter than 65 characters.")
    ])
    password = PasswordField("password", validators=[
        DataRequired(),
        Length(min=1, max=256, message="The length of the password must be shorter than 257 characters.")
    ])
    phone = StringField("phone", validators=[
        Optional(),
        Length(min=1, max=16, message="The length of the phone number must be shorter than 17 characters.")
    ])
    uni_choice = university.getAllUniversitiesForm()
    university = SelectField("university", validate_choice=False, choices=uni_choice
                             )
    agree = BooleanField("agree", validators=[
        DataRequired()
    ])
Beispiel #3
0
def userSettings():
    if session['role'] == 'student':
        userId = session['id']
        user = getStudentDetail(userId)
        form = SettingsForm()
        form.university.choices = getAllUniversitiesForm()
        return render_template("consumerViews/settings.html", user=user, form=form)
    else:
        return render_template("errorViews/403.html")
Beispiel #4
0
def addClient():
    form = RegisterForm()
    if form.validate_on_submit():
        role = request.form['role']
        username = request.form['username']
        password = request.form['password']
        email = request.form['email']
        if request.form['role'] == "0":
            university = request.form['university']
            return addNewStudent(username, password, email, university)
        elif request.form['role'] == "1":
            phone = request.form['phone']
            return addNewRestaurant(username, password, email, phone)
        else:
            form.university.choices = getAllUniversitiesForm()
            return render_template("consumerViews/register.html", form=form)
    else:
        form.university.choices = getAllUniversitiesForm()
        return render_template("consumerViews/register.html", form=form)
Beispiel #5
0
def addNewRestaurant(name, password, email, phone):
    form = RegisterForm()
    restaurant = []
    restaurant.append(name)
    restaurant.append(hasher.hash(password))
    restaurant.append(email)
    restaurant.append(phone)
    try:
        add = addRestaurant(restaurant)
        if add != True:
            form.university.choices = getAllUniversitiesForm()
            return render_template("consumerViews/register.html",
                                   form=form,
                                   messages=["Error: " + add])
    except:
        form.university.choices = getAllUniversitiesForm()
        return render_template("consumerViews/register.html",
                               form=form,
                               messages=["Check your information."])
    return redirect(url_for("login", success='true'))
Beispiel #6
0
def addNewStudent(username, password, email, university):
    form = RegisterForm()
    user = []
    user.append(username)
    user.append(hasher.hash(password))
    user.append(email)
    user.append(university)
    try:
        add = addStudent(user)
        if add != True:
            form.university.choices = getAllUniversitiesForm()
            return render_template("consumerViews/register.html",
                                   form=form,
                                   messages=["Error: " + add])
    except:
        form.university.choices = getAllUniversitiesForm()
        return render_template("consumerViews/register.html",
                               form=form,
                               messages=["Check your information."])
    return redirect(url_for("login", success='true'))
Beispiel #7
0
def updateUser():
    if session['role'] == 'student':
        userId = session['id']
        form = SettingsForm()
        if form.validate_on_submit():
            username = request.form['username']
            password = request.form['password']
            university = request.form['university']
            if (hasActiveOrder(session['id'])):
                user = getStudentDetail(userId)
                form = SettingsForm()
                form.university.choices = getAllUniversitiesForm()
                return render_template("consumerViews/settings.html", user=user, form=form,
                                       messages=["You have active order, you cannot change your information."])
            email = request.form['email']
            if form['passwordchange'].data == True:
                userUpdate = updateUserWithPassword(userId, username,email, hasher.hash(password), university)
                if userUpdate != True:
                    user = getStudentDetail(userId)
                    form = SettingsForm()
                    form.university.choices = getAllUniversitiesForm()
                    return render_template("consumerViews/settings.html", user=user, form=form, messages=[userUpdate])
                else:
                    user = getStudentDetail(userId)
                    form = SettingsForm()
                    form.university.choices = getAllUniversitiesForm()
                    return render_template("consumerViews/settings.html", user=user, form=form, success='true')
            else:
                userUpdate = updateUserWithoutPassword(userId, username, email, university)
                if userUpdate != True:
                    user = getStudentDetail(userId)
                    form = SettingsForm()
                    form.university.choices = getAllUniversitiesForm()
                    return render_template("consumerViews/settings.html", user=user, form=form, messages=[userUpdate])
                else:
                    user = getStudentDetail(userId)
                    form = SettingsForm()
                    form.university.choices = getAllUniversitiesForm()
                    return render_template("consumerViews/settings.html", user=user, form=form, success='true')
        else:
            userId = session['id']
            user = getStudentDetail(userId)
            form.university.choices = getAllUniversitiesForm()
            return render_template("consumerViews/settings.html", user=user, form=form)
    else:
        return render_template("errorViews/403.html")
Beispiel #8
0
class SettingsForm(FlaskForm):
    username = StringField(
        "username",
        validators=[
            DataRequired(),
            Length(
                min=1,
                max=64,
                message=
                "The length of the name must be shorter than 65 characters.")
        ])
    email = EmailField(
        "email",
        validators=[
            DataRequired(),
            Length(
                min=1,
                max=64,
                message=
                "The length of the email must be shorter than 65 characters.")
        ])
    password = PasswordField(
        "password",
        validators=[
            Length(
                min=1,
                max=256,
                message=
                "The length of the password must be shorter than 257 characters."
            ),
            Optional()
        ])
    uni_choice = university.getAllUniversitiesForm()
    university = SelectField("university",
                             validate_choice=False,
                             choices=uni_choice)
    passwordchange = BooleanField("passwordchange", validators=[Optional()])