예제 #1
0
def password_reset():
    form = passwordReset()
    if form.validate_on_submit():
        username = form.data['username']
        print(username)
        guide = Guide.query.filter_by(username=username)
        if guide:
            hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            guide[0].password = hashed_password
            db.session.commit()
            template = email_header + f"""
            Respected <b>{guide[0].name}</b>,
            <br/><br/>You have successfully reset your password.<br/><br/>
            <b>Not you? </b>If it was not you, please <b>immediately report us</b> by replying the issue on this email.<br/><br/>
            """ + email_footer
            msg = Message(
                subject=
                '[ALERT!] Password Reset Done | Department of CSE | MGM\'s College of Engineering',
                sender='*****@*****.**',
                recipients=[guide[0].email],
                html=template)
            mail.send(msg)
            flash('Password Reset Successful!', 'success')
        else:
            flash(
                'The entered username doesnot exist. Please register as a Guide.',
                'danger')
        return redirect(url_for('guideLogin'))
    return render_template('password-reset.html',
                           title="Reset Password",
                           form=form)
예제 #2
0
def GuideRegistration():
    form = guideRegister()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        guide = Guide(name=form.guideName.data,
                      username=form.username.data,
                      password=hashed_password,
                      email=form.guideEmail.data,
                      interest=form.guideInterest.data)
        db.session.add(guide)
        db.session.commit()
        flash('Your account has been created. You can now login as a guide.',
              'success')
        template = f"Hi {guide.name}! You have been successfully registerd as a Guide. Your Interests: {guide.interest}. You will be informed via mail, when students will be are assigned to you."
        msg = Message(
            subject=
            'Guide Registration Successful | Department of CSE | MGM College of Engineering | Nanded',
            sender='*****@*****.**',
            recipients=[guide.email],
            body=template)
        mail.send(msg)
        return redirect(url_for('guide'))
    return render_template('GuideRegistration.html',
                           title='Guide Registration',
                           form=form)
예제 #3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    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('Your account has been created! You are now able to log in', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
예제 #4
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(name=form.name.data,
                    surname=form.surname.data,
                    email=form.email.data,
                    password=hashed_password,
                    phoneNumber=form.phoneNumber.data)
        db.session.add(user)
        db.session.commit()
        flash('Twoje konto zostało utworzone pomyślnie!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title="Rejestracja", form=form)
예제 #5
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('That is an invalid or experied token', 'warning')
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash(f'Your has been updated! You are now able to log in', 'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)