コード例 #1
0
def send_verify_mail():
    user_id = login_user.get('user_id')
    record = User().find_by_id(user_id)
    if not record:
        return jsonify({
            'message': 'invalid user',
            'code': 104033
        }), 403

    email = record.get('email')
    token = md5(str(current_request_id))
    url = config.dommain + '/users/email/verify?token=' + token
    message = '[Eclogue]Please click url to verify your email:<a href="{}">{}</a>'.format(url, url)
    smtp = SMTP()
    smtp.send(message, email, subtype='html')
    data = {
        'user_id': user_id,
        'token': token,
        'created_at': time.time(),
        'email': email,
        'content': message,
    }

    db.collection('mail_verify').insert_one(data)

    return jsonify({
        'message': 'ok',
        'code': 0
    })
コード例 #2
0
def reset_pwd():
    payload = request.get_json()
    if not payload:
        return jsonify({
            'message': 'illegal params',
            'code': 104000,
        }), 400

    old_password = payload.get('old_pwd')
    new_password = payload.get('new_pwd')
    confirm = payload.get('confirm')
    if not old_password or not new_password or not confirm:
        return jsonify({
            'message': 'miss required params',
            'code': 104001
        }), 400

    if new_password != confirm:
        return jsonify({
            'message': 'inconsistent confirm password',
            'code': 104002
        }), 400

    user = User().find_by_id(login_user.get('user_id'))
    checked = check_password_hash(user.get('password'), old_password)
    if not checked:
        return jsonify({
            'message': 'password incorrect',
            'code': 104003,
        }), 400

    pwd = generate_password_hash(new_password)
    update = {
        '$set': {
            'password': pwd,
        }
    }
    User().collection.update_one({'_id': user['_id']}, update=update)

    return jsonify({
        'message': 'ok',
        'code': 0,
    })
コード例 #3
0
ファイル: notify.py プロジェクト: eclogue/eclogue
    def dispatch(self, user_id, msg_type, content, channel=None):
        user = User().find_by_id(user_id)
        if not user:
            return False

        alerts = user.get('alerts')
        if not alerts or not alerts.get(msg_type):
            return False

        items = alerts.get(msg_type)
        if not items:
            return False

        if channel and isinstance(channel, Iterable):
            items = [i for i in channel if i in items]

        if not items:
            self.web(user_id, msg_type, content)

            return True

        if 'slack' in items:
            self.slack(content)

        if 'wechat' in items:
            self.wechat(content)

        if 'smtp' in items:
            self.smtp(user, content)

        if 'sms' in items:
            self.sms(user, content)

        if 'web' in items:
            self.web(user_id, msg_type, content)

        return True