def referral_users(): form = ReferralForm() if form.validate_on_submit(): html = 'asdlkfjasfd' subject = 'REFFERAL: ' admin = user_account.retrieve_user(1) email_parts = [ html, subject, admin.email_address, form.email.data, None ] send_email(email_parts) value = [ None, current_user.id, form.name.data, form.email.data, form.type.data, 'N' ] referral.add(value) flash('Referral has been sent!', 'success') return redirect(url_for('linkages.referral_users')) return render_template('/linkages/referral/index.html', form=form, active='referral')
def forgot_password(): form = ForgotPasswordForm() if form.validate_on_submit(): email = form.email.data value = user_account.query.by(email_address=email).first() if value: token = ''.join(random.choice(string.ascii_uppercase + string.digits)for _ in range(6)) value.password = bcrypt.generate_password_hash(token).decode('utf-8') db.session.commit() html = 'asdf' subject = 'RESET PASSWORD: '******'Password has been reset. Please check your email.', 'success') return redirect(url_for('unregistered.forgot_password')) else: flash('Email not existing.', 'error') return render_template('/unregistered/login/forgot_password.html', form=form)
def linkage_action(action, id): user = user_account.retrieve_user(id) linkage = user_information.linkage_info(user.info_id) if action=='disable': status = "D" flash(linkage.company_name.title() + " was disabled!","success") value = [None,current_user.id,user.id,'linkage', 4] audit_trail.add(value) elif action=='activate': status = "A" flash(linkage.company_name.title() + " was activated! ", "success") value = [None,current_user.id,user.id,'linkage', 3] audit_trail.add(value) elif action=='decline': status = "X" flash(linkage.company_name.title() + " was declined! ", "success") value = [None,current_user.id,user.id,'linkage', 3] audit_trail.add(value) else: if linkage.address == "San Sebastian College Recoletos de Cavite": status = "A" flash(linkage.company_name.title() + " was activated! ", "success") value = [None,current_user.id,user.id,'linkage', 2] audit_trail.add(value) else: token = generate(user.info_id) link = url_for('unregistered.confirm_linkage', token=token , _external = True) html = render_template('admin/email/moa.html', user = user.username, link = link) subject = "MEMORANDUM OF AGREEMENT" email_parts = [html, subject, current_user.email_address, user.email_address, None] send_email(email_parts) flash('MOA was sent to ' + linkage.company_name.title(), 'success') status = "P" value = [None,current_user.id,user.id,'linkage', 1] audit_trail.add(value) user_account.update_status(user.id, status) return redirect(url_for('admin.linkages', status='all', page='1', search=' '))
def event_action(id, action): event = event_information.retrieve_event(id) organizer = user_information.linkage_info(event.organizer_id) email = user_account.retrieve_user(organizer.id) if action=='approve': signatory = user_views.signatory_info(4) status = ['P','A'] recipient = signatory.email_address user = '******' + signatory.last_name + ', OAR' token = generate(event.id) approve = url_for('unregistered.event_signing', token=token , action='approve', _external = True) decline = url_for('unregistered.event_signing', token=token , action='decline', _external = True) html = render_template('admin/email/event.html', event=event , organizer=organizer.company_name, user=user, link = [approve, decline]) attachments = event_attachment.retrieve_files(id) subject = "NEW EVENT PROPOSAL: " + event.name email_parts = [html, subject, current_user.email_address, recipient, attachments] send_email(email_parts) event_information.update_status(event.id,status[0]) proposal_tracker.update_status(event.id,status[1]) proposal = proposal_tracker.query.filter(proposal_tracker.event_id==event.id).first() value = [None,current_user.id,event.id,'event', 5] audit_trail.add(value) flash(event.name + ' was approved!', 'success') elif action=='decline': status='X' proposal_tracker.update_status(event.id, status) event_information.update_status(event.id, status) value = [None,current_user.id,event.id,'event', 6] audit_trail.add(value) flash(event.name + ' was declined.', 'info') elif action=='cancel': status='C' proposal_tracker.update_status(event.id, status) event_information.update_status(event.id, status) value = [None,current_user.id,event.id,'event', 8] audit_trail.add(value) flash(event.name + ' was cancelled.', 'success') return redirect(url_for('admin.events', status='all', page='1', search=' '))
def events_create(): form = ProposalForm() linkages = linkage_views.target_linkages() photo = user_photo.photo(current_user.info_id) for item in linkages: if item.type==3: name = item.company_name else: name = item.address form.select_link.choices.extend([(item.id, name)]) if form.validate_on_submit(): det = user_information.linkage_info(current_user.info_id) if det.company_name=='San Sebastian College Recoletos de Cavite': event_type=1 else: event_type=2 value = [ None,current_user.info_id,form.title.data, form.description.data,form.objective.data,form.budget.data,form.location.data, form.event_date.data,form.participant_no.data, form.min_age.data, form.max_age.data, form.thrust.data,event_type,'P' ] event_information.add(value) event = event_information.last_added(current_user.id) if form.target_link.data: comm = form.target_link.data.split('|',-1) for participant in comm: if participant!='': value = [None, event.id, participant, 'Y'] event_participation.add(value) budget_plan = form.budget_plan.data old, extension = os.path.splitext(budget_plan.filename) filename = str(event.id)+extension file_path = 'static/attachment/budget_plan/' + filename value = [None,event.id,file_path,1] event_attachment.add(value) budget_plan.save(file_path) programme = form.programme.data old, extension = os.path.splitext(programme.filename) filename = str(event.id)+extension file_path = 'static/attachment/programme/' + filename value = [None,event.id,file_path,2] event_attachment.add(value) programme.save(file_path) signatory = user_views.signatory_info(3) recipient = signatory.email_address user = '******' + signatory.last_name + ', OAR' token = generate(event.id) organizer='Recoletos Community Outreach Program Office' approve = url_for('unregistered.event_signing', token=token , action='approve', _external = True) decline = url_for('unregistered.event_signing', token=token , action='decline', _external = True) html = render_template('admin/email/event.html', event=event , organizer=organizer, user=user, link = [approve, decline]) attachments = event_attachment.retrieve_files(event.id) subject = "NEW EVENT PROPOSAL: " + event.name email_parts = [html, subject, current_user.email_address, recipient, attachments] send_email(email_parts) value = [None, event.id, 'F'] proposal_tracker.add(value) proposal_tracker.update_status(event.id, 'F') flash('Event proposal submitted! Please wait for the approval.', 'success') return redirect(url_for('admin.events', status='all', page='1', search=' ')) return render_template('/admin/events/create.html', title="Create Event", form=form, photo=photo, active='events')
def event_signing(token, action): id = confirm(token) if id=='bad': flash('Link already expired. Please contact the ReCOP Administrator.', 'error') return redirect(url_for('unregistered.index')) event = event_views.show_info(id) organizer = user_information.linkage_info(event.organizer_id) success = user_account.retrieve_user(event.organizer_id) form = LoginForm() if form.validate_on_submit(): user = user_account.login([form.username.data, form.password.data]) if user and user.type==5: if action=='approve': if event.status=='A': if user.id==4: signatory = user_views.signatory_info(3) status='F' else: flash('Invalid credentials! Please try again.', 'error') return redirect(url_for('unregistered.event_signing', token=token, action=action)) elif event.status=='F': if user.id==3: signatory = user_views.signatory_info(2) status='P' else: flash('Invalid credentials! Please try again.', 'error') return redirect(url_for('unregistered.event_signing', token=token, action=action)) elif event.status=='P': if user.id==2: status='S' event_information.update_status(event.id, status) else: flash('Invalid credentials! Please try again.', 'error') return redirect(url_for('unregistered.event_signing', token=token, action=action)) proposal_tracker.update_status(event.id, status) value = [None,user.id,event.id,'event', 5] audit_trail.add(value) if status!='S': recipient = signatory.email_address name = 'Fr. ' + signatory.last_name + ', OAR' token = generate(event.id) approve = url_for('unregistered.event_signing', token=token , action='approve', _external = True) decline = url_for('unregistered.event_signing', token=token , action='decline', _external = True) html = render_template('admin/email/event.html', event=event , organizer=organizer.company_name, user=name, link = [approve, decline]) subject = "NEW EVENT: " + event.name attachments = event_attachment.retrieve_files(id) email_parts = [html, subject, user.email_address, recipient, attachments] send_email(email_parts) else: recipient = success.email_address html = 'Hey ' + success.username + '! Your event entitled ' + event.name.title() + ' was already approved!' subject = "NEW EVENT: " + event.name email_parts = [html, subject, user.email_address, recipient, None] send_email(email_parts) flash(event.name.title() + ' was approved!', 'success') return redirect('/') else: if event.status=='A': if user.id!=4: flash('Invalid credentials! Please try again.', 'error') return redirect(url_for('unregistered.event_signing', token=token, action=action)) elif event.status=='F': if user.id!=3: flash('Invalid credentials! Please try again.', 'error') return redirect(url_for('unregistered.event_signing', token=token, action=action)) elif event.status=='P': if user.id!=2: flash('Invalid credentials! Please try again.', 'error') return redirect(url_for('unregistered.event_signing', token=token, action=action)) status='X' proposal_tracker.update_status(event.id, status) event_information.update_status(event.id, status) value = [None,user.id,event.id,'event', 6] audit_trail.add(value) flash(event.name.title() + ' was declined!', 'success') return redirect('/') else: flash('Invalid credentials! Please try again.', 'error') return render_template('/unregistered/events/signing.html', form=form, action=action, event=event)