def clearall():
    for notice in Notice.select():
        notice.delete_instance()
    for user in User.select():
        user.delete_instance()
    for message in Message.select():
        message.delete_instance()
    return redirect(url_for('register'))
Exemple #2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if request.method == 'POST' and form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        User.create(fullname=form.fullname.data,
                    telephone=form.telephone.data,
                    course=form.course.data,
                    admission_no=form.admission_no.data,
                    year=form.year.data,
                    level=form.level.data,
                    password=hashed_password,
                    image='default.jpg')
        flash(f'Account created for {form.fullname.data}.', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', form=form)
Exemple #3
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm()
    if request.method == 'POST' and form.validate_on_submit():
        user = User.get_or_none(User.admission_no == form.admission_no.data)
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            flash(f'You have been logged in as { current_user.fullname }',
                  category='success')
            next_page = request.args.get('next')
            if not is_safe_url(next_page):
                return abort(400)
            return redirect(next_page or url_for('index'))
        else:
            flash(
                'Login unsuccessful. Please check admission number and password',
                category=('danger'))
    return render_template('login.html', form=form)
def validate_admision_no_is_new(form, field):
    user = User.get_or_none(User.admission_no == field.data)
    if user:
        raise ValidationError(
            'This admission number is already taken, contact the admin for guidance.')
def validate_admision_no_exists(form, field):
    user = User.get_or_none(User.admission_no == field.data)
    if not user:
        raise ValidationError(
            'No account created by this admission number, register to join.')