Ejemplo n.º 1
0
def register(choice):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    idd = token_hex(16)
    if(choice=='doctor'):
        idd = 'D'+idd
        form = DoctorRegister()
        if form.validate_on_submit():
            user = Doctor(id = idd, full_name=form.name.data, email=form.email.data, city=form.city.data, phone=form.phone.data, address=form.address.data, qual=form.qual.data, fees=form.fees.data)
            user.set_password(form.password.data)
            db.session.add(user)
            db.session.commit()
            flash('Congratulations, you are now a registered user!')
            return redirect(url_for('login'))
    else:
        idd = 'P'+idd
        form = PatientRegister()
        if form.validate_on_submit():
            user = Patient(id=idd, full_name=form.name.data, email=form.email.data, city=form.city.data)
            user.set_password(form.password.data)
            db.session.add(user)
            db.session.commit()
            flash('Congratulations, you are now a registered user!')
            return redirect(url_for('login'))
    
    return render_template('register.html', choice=choice, form=form)
Ejemplo n.º 2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        try:
            doc = Doctor(name=form.name.data,
                         email=form.email.data,
                         registration_number=form.registration_number.data)
            db.session.add(doc)
            doc.set_password(form.password.data)
            db.session.commit()
            flash('Congratulations, you have succesfully registered.')
            return redirect(url_for('auth.login'))
        except Exception as e:
            flash('Error registering: ' + str(e))
            return redirect(url_for('auth.register'))
    return render_template('auth/register.html', title='Register', form=form)
Ejemplo n.º 3
0
 def test_password_hashing(self):
     d = Doctor(name = 'Dan')
     d.set_password('foo')
     self.assertFalse(d.check_password('bar'))
     self.assertTrue(d.check_password('foo'))