Example #1
0
 def emit(self, record):
     from opencampus.common.sendmail import send_email
     send_email(self.subject, self.format(record), self.toaddrs)
Example #2
0
def lecture_auth_admin_method(year, term, code):
    lecture = Lecture.get_lecture(year, term, code)

    # TODO : Remove
    lecture.email = '*****@*****.**'
    lecture.phone = '+821051277004'

    if not session.get_account():
        return '<p>로그인 후 사용해주세요</p>'

    from opencampus.module.lecture.authmodels import LectureAuthRequestInfo

    if request.form.get('type') == 'email':
        if not lecture.email:
            return '강의정보에 이메일이 등록되어 있지 않습니다'

        at_index = lecture.email.find('@')

        email_view = '*' * (at_index-3) + lecture.email[at_index-3:]
        if at_index < 3:
            email_view = '*' * at_index + lecture.email[at_index:]

        try:
            from opencampus.common.sendmail import send_email
            send_email('[오픈캠퍼스] 관리자 인증 메일 - %s년 %s학기 %s(%s)' % (lecture.year, lecture.get_term_text(),
                                                                lecture.code, lecture.subject_name),
                       render_template('module/lecture/detail/sendemail.html', lecture=lecture,
                                       auth_code=LectureAuthRequestInfo.create_request(lecture.id, 'email', session.get_account().id)),
                       [lecture.email])
        except Exception as e:
            print(e)
            return '<p>메일 발송 도중 에러가 발생하였습니다</p>'

        return '<p>%s으로 이메일이 발송되었습니다.</p><p>이메일에 기재되어 있는 방법을 이용하여 인증을 진행하여 주십시오.</p>' % email_view

    if request.form.get('type') == 'ars':
        if not lecture.phone:
            return '강의정보에 전화번호가 등록되어 있지 않습니다'

        phone_view = lecture.phone[:7] + '*' * (len(lecture.phone) - 7)
        body = '<p>%s으로 ARS가 발송되었습니다.</p><p>전화를 받으신 후 아래의 인증코드를 입력하신후 # 버튼을 눌러주세요.</p>' % phone_view
        body += '<div class="well well-sm"><h2>3333</h2></div>'
        return body
    if request.form.get('type') == 'sms':
        if not lecture.phone:
            return '강의정보에 전화번호가 등록되어 있지 않거나 휴대폰 번호가 아닙니다'

        phone_view = lecture.phone[:7] + '*' * (len(lecture.phone) - 7)

        auth_code = LectureAuthRequestInfo.create_request(lecture.id, 'sms', session.get_account().id)

        from twilio.rest import TwilioRestClient
        account_sid = app.config.get('TWILIO_ACCOUNT_SID')
        auth_token = app.config.get('TWILIO_AUTH_TOKEN')
        client = TwilioRestClient(account_sid, auth_token)
        message = client.messages.create(body="[오픈캠퍼스 인증] 인증번호 %s" % auth_code,
                                         to=lecture.phone,
                                         from_="+18559731333")

        body = '<p>%s으로 SMS가 발송되었습니다.</p><p>수신된 인증코드를 입력하여 주시기 바랍니다.</p>' % phone_view
        body += '<form action="%s" method="GET">' % url_for('campus.lecture_auth_admin_method_cb', year=year, term=term, code=code)
        body += '<input type="number" name="auth_code" class="form-control input-lg" placeholder="인증번호">'
        body += '<button type="submit" class="btn btn-danger btn-lg">인증</button>'
        body += '</form>'
        return body
    if request.form.get('type') == 'manual':
        body = '<p>해당 강의 정보와 관리자임을 증빙 할 수 있는 서류 등을 첨부하여</p>'
        body += '<p><a href="mailto:[email protected]">[email protected]</a>로 보내주시기 바랍니다.</p>'
        return body

    return '비정상 접근'