def approval_request(): request_data = request.get_json() user_id = request_data['user_id'] resource_id = request_data['resource_id'] resource = ThrivResource.query.filter_by(id=resource_id).first_or_404() # Get admins for the user's institution user = User.query.filter_by(id=user_id).first_or_404() admins = User.query.filter_by(role="Admin", institution_id=user.institution_id).all() # Send approval request email to each admin for the institution for admin in admins: tracking_code = email_service.approval_request_email( user, admin, resource) log = EmailLog(user_id=admin.id, type="approval_request", tracking_code=tracking_code) db.session.add(log) db.session.commit() # Send confirmation email to user confirm_tracking_code = email_service.approval_request_confirm_email( user, resource) confirm_log = EmailLog(user_id=user.id, type="approval_request_confirm", tracking_code=confirm_tracking_code) db.session.add(confirm_log) db.session.commit() return ''
def send_confirm_email(self, user): tracking_code = email_service.confirm_email(user) log = EmailLog(user_id=user.id, type="confirm_email", tracking_code=tracking_code) db.session.add(log) db.session.commit()
def consult_request(): request_data = request.get_json() user_id = request_data['user_id'] user = User.query.filter_by(id=user_id).first_or_404() tracking_code = email_service.consult_email(user, request_data) log = EmailLog(user_id=user.id, type="consult_request", tracking_code=tracking_code) db.session.add(log) db.session.commit() return ''
def forgot_password(): request_data = request.get_json() email = request_data['email'] user = User.query.filter_by(email=email).first_or_404() tracking_code = email_service.reset_email(user) log = EmailLog(user_id=user.id, type="reset_email", tracking_code=tracking_code) db.session.add(log) db.session.commit() return ''
def send_confirm_email(user): current_studies = db.session.query(Study).filter_by( status='currently_enrolling').all() for study in current_studies: study.link = app.config['SITE_URL'] + '/#/study/' + str(study.id) + \ EmailService.generate_google_analytics_link_content('reset_password_study' + str(study.id), '0days') tracking_code = email_service.confirm_email(user, current_studies) log = EmailLog(user_id=user.id, type="confirm_email", tracking_code=tracking_code) db.session.add(log) db.session.commit()
def create_email_log_records(self, num_records, days_removed, log_type, user=None): if user is None: user = self.construct_user() for _ in range(num_records): log = EmailLog(last_updated=datetime.datetime.now() - datetime.timedelta(days=days_removed), user_id=user.id, type=log_type) db.session.add(log) db.session.commit() days_removed += 2
def forgot_password(): request_data = request.get_json() email = request_data['email'] user = User.query.filter(func.lower(User.email) == email.lower()).first() if user: tracking_code = email_service.reset_email(user) log = EmailLog(user_id=user.id, type="reset_email", tracking_code=tracking_code) db.session.add(log) db.session.commit() return '' else: raise RestException(RestException.EMAIL_NOT_REGISTERED)
def construct_everything(self): self.construct_all_questionnaires() cat = self.construct_category() org = self.construct_organization() self.construct_resource() study = self.construct_study() location = self.construct_location() event = self.construct_event() self.construct_location_category(location.id, cat.name) self.construct_study_category(study.id, cat.name) self.construct_zip_code() investigator = Investigator(name="Sam I am", organization_id=org.id) db.session.add(StudyInvestigator(study = study, investigator = investigator)) db.session.add(StudyUser(study=study, user=self.construct_user())) db.session.add(AdminNote(user_id=self.construct_user().id, resource_id=self.construct_resource().id, note='')) db.session.add(investigator) db.session.add(EmailLog()) db.session.add(StepLog()) db.session.commit()
def forgot_password(): request_data = request.get_json() email = request_data['email'] user = User.query.filter(func.lower(User.email) == email.lower()).first() if user: tracking_code = email_service.reset_email(user) log = EmailLog(user_id=user.id, type="reset_email", tracking_code=tracking_code) db.session.add(log) db.session.commit() if (app.config.get('TESTING') or app.config.get('DEVELOPMENT')) and user.token_url: return jsonify(user.token_url) else: return '' else: raise RestException(RestException.EMAIL_NOT_REGISTERED)
def post(self): request_data = request.get_json() user_id = request_data['user_id'] study_id = request_data['study_id'] user = db.session.query(User).filter_by(id=user_id).first() study = db.session.query(Study).filter_by(id=study_id).first() if user and study: tracking_code = email_service.study_inquiry_email(study=study, user=user) log = EmailLog(user_id=user.id, type="study_inquiry_email", tracking_code=tracking_code) su = StudyUser(study_id=study.id, user_id=user.id, status=StudyUserStatus.inquiry_sent) db.session.add(log) db.session.add(su) db.session.commit() return '' else: raise RestException(RestException.STUDY_INQUIRY_ERROR)