Example #1
0
    def send_notice_email(self):
        """
        为当前邮箱状态为0的用户发送提醒邮件
        :return:
        """
        db = TinyDB("data.json")
        People = Query()
        target_users = db.search(People.status == 0)
        email_config = get_email_config()
        org_config = get_org_config()
        for user in target_users[:30]:  # 这里最多需要150 * 30s来发送完毕
            token = str(uuid.uuid1())
            content = '感谢您的辛苦付出,请点击链接 <a href="%s?token=' % org_config["frontend_url"]
            content += token + '">%s?token=' % org_config["frontend_url"]
            content += token + '</a>领取您的《志愿者证书》\n'
            content += org_config["name"]
            content += '\n网址:<a href="{0}">{0}</a>'.format(org_config["website"])

            is_successful = send_email(
                to_email=user['email'],
                subject='快来领取您的《 %s 志愿者证书》' % org_config["name"],
                content=content,
            )
            if is_successful:
                update_status_and_token(email=user['email'], status=1, token=token)
            slope = email_config["max_second"] - email_config["min_second"]
            time.sleep(email_config["min_second"] + random.random() * slope)

        db.close()
Example #2
0
def send_notice_email():
    """
    为当前邮箱状态为0的用户发送提醒邮件
    :return:
    """
    db = TinyDB("data.json")
    People = Query()
    target_users = db.search(People.status == 0)
    email_config = get_email_config()
    for user in target_users[:30]:  # 这里最多需要150 * 30s来发送完毕
        token = str(uuid.uuid1())
        is_successful = send_email(
            to_email=user['email'],
            subject='快来领取您的《wuhan2020开源社区志愿者证书》',
            content=
            '感谢您的辛苦付出,请点击链接 <a href="https://community.wuhan2020.org.cn/zh-cn/certification/index.html?token='
            + token +
            '">https://community.wuhan2020.org.cn/zh-cn/certification/index.html?token='
            + token +
            '</a>领取您的《志愿者证书》\nwuhan2020 开源社区\n社区网址:<a href="https://community.wuhan2020.org.cn/">https://community.wuhan2020.org.cn/</a>',
        )
        if is_successful:
            update_status_and_token(email=user['email'], status=1, token=token)
        slope = email_config["max_second"] - email_config["min_second"]
        time.sleep(email_config["min_second"] + random.random() * slope)

    db.close()
 def test_updateOrgConfig(self):
     client = app.test_client()
     json_data = {"token": "1234",
                  "website":"https://community.wuhan2020.org.cn/",
                  "username": "******",
                  "password": "******"}
     response = client.post('/api/updateOrgConfig',
                             json=json_data,
                             headers={'Referer': 'http://example.org/admin.html'})
     res_json = json.loads(response.data.decode('ascii'))
     self.assertEqual(res_json['code'], 0)
     email_config = get_email_config()
     self.assertEqual(email_config["server_address"], "smtp.example.org")
     org_config = get_org_config()
     self.assertEqual(org_config["frontend_url"], 'http://example.org/index.html')
Example #4
0
def update_config():
    if request.method == 'POST':
        message = json.loads(request.get_data(as_text=True))
        token = message["token"]
        result = confirm_admin_token(token)  # 没有每个人唯一的Key
    response = Response()
    response.headers['Content-Type'] = 'application/json'
    response.headers['Access-Control-Allow-Origin'] = '*'
    response.headers['Access-Control-Allow-Headers'] = '*'
    if request.method == 'OPTIONS':
        return response
    return_json = {'code': 1, 'message': '网络异常', 'data': None}
    response.data = return_msg(return_json)
    if result == False:
        return response
    try:
        referer = request.headers.get('Referer', None)
        if referer is not None:
            referer = referer.replace('admin', 'index')
            message['frontend_url'] = referer
        if message.get('username'):  # email admin address
            message['server_address'] = get_smtp_url(
                message.get('username'))  # email smtp address
        orgconfig = utils.get_org_config()
        emailconfig = utils.get_email_config()
        for domain in message:
            if domain == "token" or len(str(message[domain])) == 0:
                continue
            if domain in orgconfig:
                orgconfig[domain] = message[domain]
            elif domain in emailconfig:
                emailconfig[domain] = message[domain]
        utils.update_org_config(orgconfig)
        utils.update_email_config(emailconfig)
    except Exception as e:
        logger.error(e)
    return_json = {
        'code': 0,
        'message': 'update config successfully',
        'data': None
    }
    response.data = return_msg(return_json)
    return response