def application(): if current_user.is_authenticated: return redirect(url_for('home')) form = ApplicationForm() if form.validate_on_submit(): application = Application(firstname=form.firstname.data, lastname=form.lastname.data, college_id=form.college_id.data, phone=form.phone.data, department=form.department.data, course=form.course.data, address=form.address.data, city=form.city.data, income=form.income.data, email=form.email.data) db.session.add(application) db.session.commit() msg = Message("Send Mail Tutorial!", sender="*****@*****.**", recipients=["*****@*****.**"]) msg.body = "Yo!\nHave you heard the good word of Python???" mail.send(msg) print("Mail sent") flash( 'You have applied to the Hostel. Please keep checking your email inbox for further updates.', 'success') return redirect(url_for('index')) return render_template('account/apply.html', title='Application', form=form)
def guard_create(): form = CreateMessStaffForm() if form.validate_on_submit(): password = ''.join( random.choices(string.ascii_uppercase + string.digits, k=8)) hashed_password = bcrypt.generate_password_hash(password).decode( 'utf-8') user = User(firstname=form.firstname.data, lastname=form.lastname.data, college_id=form.college_id.data, phone=form.phone.data, address=form.address.data, email=form.email.data, password=password, user_type=2) db.session.add(user) db.session.commit() msg = Message("Password for HosteLite", sender="*****@*****.**", recipients=["*****@*****.**"]) msg.body = "The password for your hostelite account is: " + password + "\nPlease reset your password as soon as you login." mail.send(msg) flash('Account created successfully.', 'success') return redirect(url_for('guard_list')) return render_template('admin/guard_create.html', form=form)
def individual_applications(id): if request.method == 'POST': room = Room.query.filter(Room.capacity > 0).order_by( Room.capacity).first() if room: application = Application.query.get_or_404(id) password = ''.join( random.choices(string.ascii_uppercase + string.digits, k=8)) hashed_password = bcrypt.generate_password_hash(password).decode( 'utf-8') user = User(college_id=application.college_id, firstname=application.firstname, lastname=application.lastname, email=application.email, password=hashed_password, phone=application.phone, address=application.address, course=application.course, department=application.department) room.capacity -= 1 application.status = 1 user.room_no = room.room_no db.session.add(user) db.session.commit() user = User.query.filter_by( college_id=application.college_id).first() if not room.student1_id: room.student1_id = user.id elif not room.student2_id: room.student2_id = user.id else: room.student3_id = user.id db.session.commit() msg = Message("Password for HosteLite", sender="*****@*****.**", recipients=["*****@*****.**"]) msg.body = "The password for your hostelite account is: " + password + "\nPlease reset your password as soon as you login." mail.send(msg) return redirect(url_for('display_applications')) application = Application.query.get_or_404(id) return render_template('admin/individual_application.html', application=application)