Beispiel #1
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index.home'))
    form = RegisterForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(f'Your Account has been Created!', 'primary')
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Register', form=form)
Beispiel #2
0
def SignUp():
    # Get data from the Registration Form
    if current_user.is_authenticated:
        next = request.args.get('next')
        return redirect(next or url_for('index'))
    form = RegistrationForm(request.form)
    if request.method == 'POST' and form.validate():
        hash_password = bcrypt.generate_password_hash(form.password.data)
        user = User(fname=form.fname.data, lname=form.lname.data,
                    email=form.email.data, password=hash_password)
        db.session.add(user)
        # Adds user permanently in the database
        db.session.commit()
        flash(
            f'Welcome {form.fname.data} {form.lname.data} Thanks for registering', 'success')
        return redirect(url_for('login'))
    return render_template('signup.html', form=form)
Beispiel #3
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('index.home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash(f'Invalid Token please try again', 'warning')
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            password=form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash(f'Your password was Successfully changed', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
Beispiel #4
0
def AddStudent():
    form = AddStudents()
    if form.validate_on_submit():
        student = Student(
            name=form.name.data,
            id=form.id.data,
            email=form.email.data,
            password=bcrypt.generate_password_hash(form.name.data +
                                                   str(form.id.data %
                                                       100)).decode('utf-8'))
        db.session.add(student)
        db.session.commit()
        flash('Student added!', category="success")
        form.id.data = None
        form.name.data = None
        #next_page = request.args.get('next')
        #return redirect(next_page) if next_page else redirect(url_for('home'))
    else:
        flash('Student couldnt be added', category='success')
    return render_template('adduser.html', form=form)
Beispiel #5
0
def AddFaculty():
    form = AddFaculties()
    if form.validate_on_submit():
        faculty = Faculty(id=form.id.data,
                          course=form.course.data,
                          name=form.name.data,
                          email=form.email.data,
                          password=bcrypt.generate_password_hash(
                              str(form.id.data)).decode('utf-8'))
        db.session.add(faculty)
        db.session.commit()
        flash('Faculty added!', category="success")
        form.id.data = None
        form.course.data = None
        form.name.data = None
        form.email.data = None
        #next_page = request.args.get('next')
        #return redirect(next_page) if next_page else redirect(url_for('home'))
    else:
        flash('Faculty couldnt be added', category='danger')
    return render_template('addfaculty.html', form=form)