Exemplo n.º 1
0
def register():
    if current_user.is_authenticated:
        return redirect("/home")
    form = RegisterationForm()
    if form.validate_on_submit():
        password = form.password.data
        username = form.username.data
        email = form.email.data
        registering_std = Student(email, password)
        cursor.execute("select * from student")
        all_users = cursor.fetchall()
        check = True
        for user in all_users:
            if user[2] == email:
                check = False
            elif user[1] == username:
                check = False
        if check == True:
            registering_std.register(username)
            registering_std.set_id()
            registering_std.set_username()
            flash(f'Account created for {form.username.data}!', 'Success')
            return redirect("/login")
        else:
            return redirect("/register")
    return render_template('register.html', title='Register', form=form)
Exemplo n.º 2
0
 def login(self):
     cursor.execute(
         "select * from student where email = %s and password = %s",
         [self.email, self.password])
     user = cursor.fetchall()
     if len(user) == 1:
         return True
     else:
         return False
Exemplo n.º 3
0
def classes():
    form = DeleteLanguageForm()
    if request.method == 'POST':
        # I was working on this ( not finished )
        cursor.execute(
            'select distinct language from class,takes where std_id = %s',
            [current_user.id])
        langs = cursor.fetchall()
        choices = []
        for lang in langs:
            choices.append((lang[0], lang[0]))
            cursor.execute(
                'select level from class,takes where language = %s and std_id=%s',
                [lang[0], current_user.id])
            lvls = cursor.fetchall()
            print(lvls)
            choices_lvl = []
            for lvl in lvls:
                choices_lvl.append((lvl[0], lvl[0]))

        form.language.choices = choices
        form.level.choices = choices_lvl

        # level
        cursor.execute(
            'select distinct level from class,takes where std_id = %s',
            [current_user.id])
        lvls = cursor.fetchall()
        choices = []
        for lvl in lvls:
            choices.append((lvl[0], lvl[0]))

    # loading classes
    sid = current_user.id
    cursor.execute(
        'select language,level,CID from class,takes where CID = cls_id and std_id = %s;',
        [sid])
    taken_classes = cursor.fetchall()

    return render_template("classes.html",
                           title="Classes",
                           posts=taken_classes,
                           form=form)
Exemplo n.º 4
0
class DeleteLanguageForm(FlaskForm):
    cursor.execute('select distinct language from class')
    langs = cursor.fetchall()
    choices = []
    for lang in langs: 
        choices.append((lang[0], lang[0]))
    language = SelectField('language', choices=choices)
    level = SelectField('level', choices=[('A1','A1'),
                                          ('A2','A2'),
                                          ('B1','B1'),
                                          ('B2','B2'),
                                          ('C1','C1'),
                                          ('C2','C2')])
    submit = SubmitField('delete')