示例#1
0
def login():
    if current_user.is_authenticated:
        return redirect("/home")
    form = LoginForm()
    if form.validate_on_submit():
        email = form.email.data
        password = form.password.data
        std = Student(email, password)
        cursor.execute("select username from student where email = %s",
                       [email])
        username = cursor.fetchone()[0]
        std.username = username
        cursor.execute("select SID from student where email = %s", [email])
        sid = cursor.fetchone()[0]
        std.id = sid
        if std.login():
            logged_in_users.append(std)
            login_user(std, remember=form.remember.data)
            next_page = request.args.get('next')
            flash('you have been loggd in!', 'success')
            return redirect(next_page) if next_page else redirect("/home")
        else:
            flash('log in unsuccessful, invalid input', 'danger')
            return redirect("/login")
    return render_template('login.html', title='login', form=form)
示例#2
0
def language_class(class_id):
    cursor.execute('select file_path from class,takes where CID = %s',
                   [class_id])
    file_path = cursor.fetchone()[0]
    cursor.execute('select language, level from class where CID=%s',
                   [class_id])
    lang_lvl = cursor.fetchone()
    value = [file_path, lang_lvl[0], lang_lvl[1]]
    return render_template("language_class.html", title="Classes", value=value)
示例#3
0
def delete():
    if current_user.is_authenticated:
        username = current_user.username
        cursor.execute("select SID from student where username = %s ",
                       [username])
        sid = cursor.fetchone()[0]
        cursor.execute("DELETE from student where SID = %s ", [sid])
        database.commit()
        flash('your account has been deleted', 'success')
        logout_user()
        if len(logged_in_users) != 0:
            logged_in_users.pop(0)
    return render_template('home.html', posts=posts)
示例#4
0
def languages():
    form = SelectLanguageForm()
    if request.method == 'POST':
        lan = form.language.data
        lvl = form.level.data
        cursor.execute(
            "select CID from class where language = %s and level = %s",
            [lan, lvl])
        cid = cursor.fetchone()[0]
        print(current_user.username)
        cursor.execute(
            "insert into takes ( std_id , cls_id ) values ( %s, %s)",
            [current_user.id, cid])
        database.commit()
        flash('Class Added, click here to access it', 'success')
    return render_template("languages.html", form=form)
示例#5
0
文件: models.py 项目: SamNK/LangLearn
 def set_username(self):
     cursor.execute('select * from student where email = %s', [self.email])
     self.username = cursor.fetchone()[1]
     return self.username
示例#6
0
文件: models.py 项目: SamNK/LangLearn
 def set_id(self):
     cursor.execute('select * from student where email = %s', [self.email])
     self.id = cursor.fetchone()[0]
     return self.id