def get_certificate(user_id):
     user = userservice.check_hackers(user_id)
     if user is None:
         return 'Sorry but you have not participated devsummit'
     mail_template = EmailHackaton("devsummit-hackathon-certificate.html")
     mail_template = mail_template.build(user.first_name + ' ' + user.last_name)
     return render_pdf(HTML(string=mail_template))
 def resend_certificate(self, payloads):
     response = ResponseBuilder()
     emailservice = EmailService()
     mail_template = EmailHackaton("devsummit-hackathon-certificate.html")
     checked_in = db.session.query(UserTicket.user_id).join(CheckIn).all()
     checkins = [i[0] for i in checked_in]
     print(checkins)
     user = db.session.query(User).filter(
         or_(User.id == payloads['user_id'],
             User.email == payloads['user_id'])).first()
     if user is None:
         return response.set_data(None).set_message(
             'user not found.').set_error(True).build()
     if user.id not in checkins:
         return response.set_data(None).set_message(
             'user found but did not check in.').set_error(True).build()
     extra = "<br/><br/><br/>Link to your downloadable certificate: <a href='https://api.devsummit.io/certificate-%s.pdf'>here</a>" % user.id
     template = mail_template.build(user.first_name + ' ' + user.last_name,
                                    extra)
     email = emailservice.set_recipient(user.email).set_subject(
         'Indonesia Developer Summit 2017').set_sender(
             '*****@*****.**').set_html(template).build()
     mail.send(email)
     return response.set_data(None).set_message('email has been sent to: ' +
                                                user.email).build()
 def email_certificate(self, payload):
     response = ResponseBuilder()
     emailservice = EmailService()
     mail_template = EmailHackaton("devsummit-hackathon-certificate.html")
     emailservice = EmailService()
     extra = "<br/>Link to your downloadable certificate: <a href='https://api.devsummit.io/certificate-email-%s.pdf'>here</a>" % payload[
         'name']
     template = mail_template.build(payload['name'], extra)
     email = emailservice.set_recipient(payload['email']).set_subject(
         'Indonesia Developer Summit 2017 Hackathon').set_sender(
             '*****@*****.**').set_html(template).build()
     mail.send(email)
     return response.set_data(None).set_message('Email sent').build()
 def resend_email(self, payloads):
     response = ResponseBuilder()
     emailservice = EmailService()
     hackaton_proposal = db.session.query(HackatonProposal).filter(
         HackatonProposal.order_id == payloads['order_id']).first()
     if hackaton_proposal is None:
         return response.set_error(True).set_data(None).set_message(
             'proposal not found').build()
     mail_template = EmailHackaton("devsummit-hackathon.html")
     user = hackaton_proposal.order.user
     template = mail_template.build(user.first_name + ' ' + user.last_name)
     email = emailservice.set_recipient(user.email).set_subject(
         'Indonesia Developer Summit 2017 Hackathon').set_sender(
             '*****@*****.**').set_html(template).build()
     mail.send(email)
     return response.set_data(None).set_message('email has been sent to: ' +
                                                user.email).build()
    def send_certificate(self):
        response = ResponseBuilder()
        emailservice = EmailService()
        mail_template = EmailHackaton("devsummit-hackathon-certificate.html")
        checked_in = db.session.query(UserTicket.user_id).join(CheckIn).all()
        hackers = db.session.query(User).filter(
            or_(User.role_id == ROLE['hackaton'],
                User.role_id == ROLE['user']), User.id.in_(checked_in)).all()
        if hackers is None:
            return response.set_data(None).set_message(
                'user not found').set_error(True).build()
        for user in hackers:
            emailservice = EmailService()
            extra = "<br/>Link to your downloadable certificate: <a href='https://api.devsummit.io/certificate-%s.pdf'>here</a>" % user.id
            template = mail_template.build(
                user.first_name + ' ' + user.last_name, extra)
            email = emailservice.set_recipient(user.email).set_subject(
                'Indonesia Developer Summit 2017 Hackathon').set_sender(
                    '*****@*****.**').set_html(template).build()
            mail.send(email)

        return response.set_data(None).set_message(
            'email has been sent').build()
 def create(self, payloads):
     response = ResponseBuilder()
     emailservice = EmailService()
     hackaton_proposal = HackatonProposal()
     hackaton_proposal.github_link = payloads['github_link']
     hackaton_proposal.order_id = payloads['order_id']
     hackaton_proposal.status = 'pending'
     db.session.add(hackaton_proposal)
     try:
         db.session.commit()
         mail_template = EmailHackaton("devsummit-hackathon.html")
         user = hackaton_proposal.order.user
         template = mail_template.build(user.first_name + ' ' +
                                        user.last_name)
         email = emailservice.set_recipient(
             hackaton_proposal.order.user.email).set_subject(
                 'Indonesia Developer Summit 2017 Hackathon').set_sender(
                     '*****@*****.**').set_html(template).build()
         mail.send(email)
         return response.set_data(hackaton_proposal.as_dict()).set_message(
             'proposal succesfully created').build()
     except SQLAlchemyError as e:
         data = e.orig.args
         return response.set_data(data).set_error(True).build()
 def email_certificate(name):
     mail_template = EmailHackaton("devsummit-hackathon-certificate.html")
     mail_template = mail_template.build(name)
     return render_pdf(HTML(string=mail_template))