コード例 #1
0
ファイル: app.py プロジェクト: faiksohail/pms_project
def create_superuser():
	while True:
		email = click.prompt('Enter email')
		match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', email)

		if not match:
			click.echo('The email is not valid. Please enter a valid email.')
		elif User.query.filter_by(email=email).first():
			click.echo('Email already in use.')
		else:
			break

	while True:
		password = click.prompt('Enter Password')

		if len(password) < 8:
			click.echo("Make sure your password is at least 8 letters")
		elif re.search('[0-9]', password) is None:
			click.echo("Make sure your password has a number in it")
		elif re.search('[A-Z]', password) is None:
			click.echo("Make sure your password has a capital letter in it")
		else:
			break

	super_user = User(email, password)
	admin_role = Role.get_role('admin')

	super_user.add_role(admin_role)

	super_user.save()
	click.echo('Successfully added!')
コード例 #2
0
ファイル: app.py プロジェクト: faiksohail/pms_project
def register():
	form = AddForm()

	if form.validate_on_submit():
		email = form.email.data
		password = generate_random_password()

		name = form.name.data
		gender = form.gender.data
		address = form.address.data
		city = form.city.data
		dob = form.dob.data
		contact = form.contact.data

		user = User(email, password)

		patient_role = Role.get_role('patient')

		user.save()
		user.add_role(patient_role)

		user_id = user.id
		patient = Patient(name, gender, address, city, dob, contact, user_id)
		patient.save()

		body_html = render_template('mail/credentials.html', username=name, login_id=user_id, password=password)
		body_text = render_template('mail/credentials.txt', username=name, login_id=user_id, password=password)

		# send_email(email, 'Welcome to PMS', body_html, body_text)
		flash("Please check your email for user id and password.")

		return redirect(url_for('register'))

	return render_template('register.html', form=form)
コード例 #3
0
def add_doctor():
    form = AddDoctorForm()

    form.specializations.choices = Specialization.specialization_choices()
    form.degrees.choices = Degree.degree_choices()

    if form.validate_on_submit():
        email = form.email.data
        password = generate_random_password()

        name = form.name.data
        gender = form.gender.data
        address = form.address.data
        city = form.city.data

        specialization_ids = form.specializations.data
        degree_ids = form.degrees.data

        dob = form.dob.data
        contact = form.contact.data

        user = User(email, password)

        doctor_role = Role.get_role('doctor')

        user.save()
        user.add_role(doctor_role)

        user_id = user.id
        doctor = Doctor(name, gender, address, city, dob, contact, user_id)

        specializations = [
            Specialization.query.get(i) for i in specialization_ids
        ]
        degrees = [Degree.query.get(i) for i in degree_ids]

        doctor.add_specializations(specializations)
        doctor.add_degrees(degrees)

        doctor.save()

        body_html = render_template('mail/staff_credentials.html',
                                    email=email,
                                    password=password)
        body_text = render_template('mail/staff_credentials.txt',
                                    email=email,
                                    password=password)

        # send_email(email, 'Welcome to PMS', body_html, body_text)

        return redirect(url_for('receptionist.list_doctor'))

    return render_template('receptionist/add_doctor.html', form=form)
コード例 #4
0
def add_receptionist():
    form = AddForm()

    if form.validate_on_submit():
        email = form.email.data
        password = generate_random_password()

        name = form.name.data
        gender = form.gender.data
        address = form.address.data
        city = form.city.data
        dob = form.dob.data
        contact = form.contact.data

        user = User(email, password)
        receptionist_role = Role.get_role('receptionist')

        user.save()
        user.add_role(receptionist_role)

        user_id = user.id
        receptionist = Receptionist(name, gender, address, city, dob, contact,
                                    user_id)
        receptionist.save()

        body_html = render_template('mail/staff_credentials.html',
                                    email=email,
                                    password=password)
        body_text = render_template('mail/staff_credentials.txt',
                                    email=email,
                                    password=password)

        # send_email(email, 'Welcome to PMS', body_html, body_text)

        return redirect(url_for('admin.list_receptionist'))

    return render_template('admin/add_receptionist.html', form=form)