예제 #1
0
def testCover():
    form = QuestionForm()
    if form.validate_on_submit():
        print(current_user.id)
        print(form.question.data)
        print(form.option_1.data)
        p1 = Personal(user_id=current_user.id,
                      question=form.question.data,
                      option_1=form.option_1.data,
                      option_2=form.option_2.data,
                      option_3=form.option_3.data,
                      option_4=form.option_4.data,
                      correct_option=form.correct_ans.data,
                      timesCorrect=0,
                      timesAsked=0)
        t1 = Transactions(user_id=current_user.id,
                          transaction_type='Add A Question')
        try:
            db.session.add(p1)
            db.session.add(t1)
            db.session.commit()
            flash(
                f'Your Question was added to your Personal TRAIN Test Database'
            )

            return redirect(url_for('testCover'))
        except:
            flash(f'We could not add your question!! Please Try Again!')
            return redirect(url_for('testCover'))
    return render_template('testcover.html', form=form)
예제 #2
0
def signup():
    if current_user.is_authenticated:
        if current_user.typeOfUser == 'Student':
            return redirect(url_for('dashboard_student'))
        else:
            return redirect(url_for('dashboard_teacher'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(typeOfUser=form.typeOfUser.data,
                    name=form.name.data,
                    email=form.email.data,
                    password=hashed_password)
        success = 0
        try:
            db.session.add(user)
            db.session.commit()
            success = 1
        except:
            flash(f'The user is already registered!! Try to login!!',
                  category='danger')
        if success == 1:
            no = User.query.filter_by(email=form.email.data).first().id
            t1 = Transactions(user_id=no, transaction_type='Registration')
            db.session.add(t1)
            db.session.commit()
            flash(
                f'Account Created for {form.name.data}!, you can now login :)',
                category='success')
            return redirect(url_for('login'))
    return render_template('signup.html', form=form)
예제 #3
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        if form.email.data == '*****@*****.**' and form.password.data == 'Salima':
            flash('you have been connected in', 'success')
            return redirect(url_for('home'))
        else:
            flash('try again something is wrong', 'danger')
    return render_template('login.html', title='Login', form=form)
예제 #4
0
def add_post():
    form = PostForm()
    if form.validate_on_submit():
        # post = Post()
        # form.populate_obj(post)
        # post.user_id = session['auth.user']['id']
        # db.session.add(post)
        # db.session.commit()
        # flash('記事を公開しました!')
        return redirect(url_for(".index"))

    return render_template('add_post.html', form=form)
예제 #5
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        # u = User.login(form.email.data, form.password.data)
        # if u is None:
        #     flash('ユーザー名とパスワードの組み合わせが違います。')
        #     return redirect(url_for('.login'))

        # session['auth.user'] = get_model_dict(u)
        return redirect(url_for('.index'))

    return render_template('login.html', form=form)
예제 #6
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        # u = User.query.filter_by(email=form.email.data).first()
        # if u:
        #     flash('そのメールアドレスは既に利用されています。')
        #     return redirect(url_for('.signup'))

        # user = User()
        # form.populate_obj(user)
        # user.password = hash_password(form.password.data)
        # db.session.add(user)
        # db.session.commit()
        flash('ユーザー登録が完了しました。ログインして下さい')
        return redirect(url_for(".signup"))

    return render_template('signup.html', form=form)
예제 #7
0
def upload_test():
    form = TestForm()
    logs = current_user.testsCreated

    if form.validate_on_submit():
        # print(form.test_name.data)
        t1 = Tests(test_name=form.test_name.data, test_creator=current_user.id)
        # print(form.data.items())
        data = list(form.data.items())[1:len(form.data.items()) - 2]
        # print(data)
        db.session.add(t1)
        db.session.commit()
        t1 = Transactions(user_id=current_user.id,
                          transaction_type='Upload A Test')
        db.session.add(t1)
        test_id = Tests.query.filter_by(
            test_name=form.test_name.data).first().test_id
        for i in range(0, len(data), 6):
            question = data[i][1]
            option_1 = data[i + 1][1]
            option_2 = data[i + 2][1]
            option_3 = data[i + 3][1]
            option_4 = data[i + 4][1]
            correct_ans = data[i + 5][1]
            t1 = Transactions(user_id=current_user.id,
                              transaction_type='Add Question')
            db.session.add(t1)
            q = Questions(test_id=test_id,
                          question=question,
                          option_1=option_1,
                          option_2=option_2,
                          option_3=option_3,
                          option_4=option_4,
                          correct_option=correct_ans,
                          timesAsked=0,
                          timesCorrect=0)
            db.session.add(q)
        try:
            db.session.commit()
            return redirect(url_for('upload_test'))
        except:
            flash(f'We could not add your question! Please Try Again')
            return redirect(url_for('upload_test'))
    return render_template("upload_test.html", form=form, logs=logs)
예제 #8
0
def update_post():
    form = PostForm()
    if form.validate_on_submit():
        # post = Post.query.filter(Post.id == form.id.data).first()
        # if form.update.data:
        #     # 更新
        #     post.title = form.title.data
        #     post.content = form.content.data
        #     db.session.add(post)
        #     flash('記事内容を更新しました')
        # else:
        #     # 削除
        #     db.session.delete(post)
        #     flash('記事を削除しました')

        # db.session.commit()
        # return redirect(url_for('.index'))

        #return redirect(url_for('.show_post',post_id=form.id.data))
        return redirect(url_for('.index'))
예제 #9
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('dashboard_student'))
    form = LoginForm()
    print("LOL")
    if form.validate_on_submit():
        print("QQQQ")
        print(form.email.data)
        print(form.password.data)
        user = User.query.filter_by(email=form.email.data).first()
        print(user)
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user)
            next_page = request.args.get('next')
            flash(f'Hey {user.name}! Good to see you back ;)',
                  category='success')
            no = user.id
            t1 = Transactions(user_id=no, transaction_type='Login')
            db.session.add(t1)
            db.session.commit()
            if next_page:
                return redirect(next_page)
            else:
                print("Logged In")
                if user.typeOfUser == 'Student':
                    return redirect(url_for('dashboard_student'))
                else:
                    return redirect(url_for('dashboard_teacher'))

        else:
            flash(
                f'Login Unsuccessful. Please check the email and/or Password',
                'danger')

    return render_template('login.html', form=form)
예제 #10
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        flash(f'account created for {form.username.data} !!', 'success!')
        return redirect(url_for('home'))
    return render_template('register.html', title='Register', form=form)