def create_timepunch(punch_type, punch_time, reason): """ Creates a timepunch, adds it to the database, and sends an email to the appropriate user so that it may be approved or denied. :param punch_type: [String] type of requested punch (True for in, False for out) :param punch_time: [datetime] time of requested punch :param reason: [string] reason for timepunch submission :return: None """ current_app.logger.info("Start function create_timepunch()") punch_type = ( punch_type == "In" ) # Must manually cast string to bool because wtf doesn't support coerce bool event = Event( time=punch_time, type=punch_type, note=reason, user=current_user, timepunch=True, approved=False, pending=True, ) db.session.add(event) db.session.commit() send_email( current_user.supervisor.email, "Timeclock - TimePunch Request from {} {}".format( current_user.first_name, current_user.last_name), "/main/email/request_timepunch", user=current_user, punch_time=punch_time, type=punch_type, note=reason, )
def process_clock(note_data, ip=None): """ Creates an Event and writes it to the database when a user clocks in or out. :param note_data: The note associated with a ClockInForm or ClockOutForm [string] :param ip: The ip of the user that triggered the function :return: None """ current_app.logger.info('Start function process_clock({},{})'.format(note_data, ip)) current_app.logger.info('Creating new clock event for {}'.format(current_user.email)) last = get_last_clock() # Send email if employee has worked for over seven hours if last and last.type: # If the last clock is an IN # TODO: ADJUST EMAIL TO PROPER ADMIN EMAIL BEFORE DEPLOYING # CURRENT EMAIL IS BRIAN'S FOR QA TESTING if (datetime.now() - get_last_clock().time).seconds / float(3600) >= 8: send_email('*****@*****.**', 'Overtime - {}'.format(current_user.email), '/main/email/employee_overtime', email=current_user.email) # Create clock event typ = True if not last else not last.type event = Event(type=typ, time=datetime.now(), user_id=current_user.id, note=note_data, ip=ip) current_app.logger.info('Saving new event to database') db.session.add(event) db.session.commit() current_app.logger.info('Saved new event to database') current_app.logger.info('End function process_clock()')
def password_reset_request(): """ View function for requesting a password reset. :return: HTML page in which users can request a password reset. """ current_app.logger.info('Start function password_reset_request() [VIEW]') if not current_user.is_anonymous: # If the current user is signed in, redirect them to TimeClock home. current_app.logger.info( 'Current user ({}) is already signed in. Redirecting to index...'. format(current_user.email)) return redirect(url_for('main.index')) form = PasswordResetRequestForm() if form.validate_on_submit(): current_app.logger.info( 'Tried to submit a password reset request with account email {}'. format(form.email.data)) current_app.logger.info( 'Querying for user with given email: {}'.format(form.email.data)) user = User.query.filter_by(email=form.email.data.lower()).first() current_app.logger.info('Finished querying for user with given email') if user: # If the user exists, generate a reset token and send an email containing a link to reset the user's # password token = user.generate_reset_token() send_email(user.email, 'Reset Your Password', 'auth/email/reset_password', user=user, token=token, next=request.args.get('next')) current_app.logger.info( 'Sent password reset instructions to {}'.format( form.email.data)) flash( 'An email with instructions to reset your password has been sent to you.', category='success') else: # If the user doesn't exist in the database current_app.logger.info( 'Requested password reset for e-mail %s but no such account exists' % form.email.data) flash('An account with this email was not found in the system.', category='error') current_app.logger.info('Redirecting to /auth/login...') current_app.logger.info('End function password_reset_request() [VIEW]') return redirect(url_for('auth.login')) current_app.logger.info('End function password_reset_request() [VIEW]') return render_template('auth/request_reset_password.html', form=form)
def _send_new_user_email(user, temp_password): """ Sends a user an email instructing them on how to set up their new account. :param user: The user to send the email to :param temp_password: The initial temporary password the user is sent to sign up with :return: None """ send_email(user.email, 'DORIS TimeClock - New User Registration', 'auth/email/new_user', user=user, temp_password=temp_password) current_app.logger.info('Sent login instructions to {}'.format(user.email))
def process_health_screen_confirmation(name, email, division, date, questionnaire_confirmation, report_to_work): # Store Health Screen in DB health_screen = HealthScreenResults( name=name, email=email, division=division, date=date, questionnaire_confirmation=eval_request_bool( questionnaire_confirmation), report_to_work=eval_request_bool(report_to_work), ) db.session.add(health_screen) db.session.commit() buffer = BytesIO() c = canvas.Canvas(buffer, pagesize=letter) generate_health_screen_confirmation(c, health_screen) c.save() pdf = buffer.getvalue() buffer.close() filename = "{username}-health-check-report_to_work-{report_to_work}-{date}.pdf".format( username=email.split("@")[0], report_to_work=health_screen.report_to_work, date=datetime.strptime(date, "%m/%d/%Y").strftime("%Y-%m-%d"), ) attachment = { "filename": filename, "mimetype": "application/pdf", "file": pdf } send_email( to="*****@*****.**", subject= "(Report to Work: {report_to_work} - {date}) Health Screening Confirmation - {name}" .format(report_to_work=health_screen.report_to_work, date=date, name=name), template="health_screen/emails/results", attachment=attachment, bcc=[email], health_screen_results=health_screen, sender="*****@*****.**", )