Пример #1
0
def before_request():
    ignore_urls  = app.config['IGNORE_URLS_HOME']
    ignore_check_login_urls  = app.config['IGNORE_CHECK_LOGIN_URLS']
    path = request.path
    #如果是静态文件就不要查询用户信息了
    pattern = re.compile('%s' % "|".join( ignore_check_login_urls ) )
    if pattern.match( path ) or "/home" not in path:
        return

    # 多查询一次数据也没有什么问题
    user_info = check_login()
    g.current_user = None
    if user_info:
        g.current_user = user_info

    #将忽略数组换成字符串
    pattern = re.compile('%s' % "|".join( ignore_urls ) )
    if pattern.match( path ):
        return

    if not user_info :
        response = make_response( redirect(GlobalUrlService.buildHomeUrl("/user/logout")))
        return response

    #判断RBAC的权限
    if not RBACService.checkPrivilege( path ):
        if UtilHelper.isAjax():
            return UtilHelper.renderErrJSON("无权限,请联系管理员" )
        response = make_response(redirect( GlobalUrlService.buildHomeUrl("/error/ban",{ "msg" : path }) ))
        return response

    g.menus = MenuService.getMenu()
    AppLogService.addAccessLog( user_info )
    return
 def daterangepicker():
     res = [
         GlobalUrlService.buildStaticResUrl("/plugins/daterangepicker/daterangepicker.min.css"),
         GlobalUrlService.buildStaticResUrl("/plugins/daterangepicker/moment.min.js"),
         GlobalUrlService.buildStaticResUrl("/plugins/daterangepicker/jquery.daterangepicker.min.js")
     ]
     return StaticPluginsHelper.groupEcho( res )
 def select2():
     res = [
         GlobalUrlService.buildStaticResUrl("/plugins/select2/select2.min.css"),
         GlobalUrlService.buildStaticResUrl("/plugins/select2/select2.pinyin.js"),
         GlobalUrlService.buildStaticResUrl("/plugins/select2/zh-CN.js"),
         GlobalUrlService.buildStaticResUrl("/plugins/select2/pinyin.core.js"),
     ]
     return StaticPluginsHelper.groupEcho(res)
Пример #4
0
def Login():
    if request.method == "GET":
        if g.current_user:
            return redirect(GlobalUrlService.buildHomeUrl("/"))
        return UtilHelper.renderView("home/user/login_2.html")

    resp = {'code': 200, 'msg': '操作成功~~', 'data': {}}
    req = request.values
    email = req['email'] if 'email' in req else ''
    pwd = req['pwd'] if 'pwd' in req else ''

    if email is None or len(email) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入正确的邮箱~~"
        return jsonify(resp)

    if pwd is None or len(pwd) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入正确的邮箱密码~~"
        return jsonify(resp)

    user_info = User.query.filter_by(
        email=email, status=CommonConstant.default_status_true).first()
    if not user_info:
        resp['code'] = -1
        resp['msg'] = "你好,未注册的邮箱,请找系统管理员先注册用户~~"
        return jsonify(resp)

    try:
        at_idx = email.index("@")
        smtp_obj = smtplib.SMTP_SSL("smtp." + email[(at_idx + 1):], 465)
        smtp_obj.set_debuglevel(1)
        smtp_obj.login(email, pwd)
        smtp_obj.close()
    except Exception:
        resp['code'] = -1
        resp['msg'] = "登录失败,请核对邮箱和密码是否对应~~"
        return jsonify(resp)
    next_url = GlobalUrlService.buildHomeUrl("/")

    response = make_response(
        json.dumps({
            'code': 200,
            'msg': '登录成功~~',
            'data': {
                "next_url": next_url
            }
        }))
    response.set_cookie(
        CommonConstant.AUTH_COOKIE_NAME,
        '%s#%s' % (CurrentUserService.userAuthToken(user_info), user_info.id),
        60 * 60 * 24 * 120)  # 保存120天
    return response
Пример #5
0
def job_info():
    req = request.values
    id = int(req['id']) if ('id' in req and req['id']) else 0
    info = JobList.query.filter_by(id=id).first()
    if not info:
        return redirect(GlobalUrlService.buildHomeUrl("/job/index/index"))

    info = ModelHelper.model2Dict(info)

    server_info = JobServer.query.filter_by(id=info['server_id']).first()
    cate_info = JobCategory.query.filter_by(id=info['cate_id']).first()
    server_env_map = CommonConstant.server_env_map
    run_status_map = CommonConstant.run_status_map

    info['next_run_time'] = DateHelper.getDateOnTimestamps(
        info['next_run_time'], '%Y-%m-%d %H:%M')
    info['env_name'] = server_env_map.get(info['env_id'])
    info['run_status_desc'] = run_status_map.get(info['run_status'])
    info['job_status_desc'] = job_status_map.get(info['status'])
    info['server_name'] = server_info.name
    info['cate_name'] = cate_info.name if cate_info else ''
    info['run_interval_desc'] = DateHelper.formatBeautyTime(
        info['run_interval'] * 60)

    user_map = ModelHelper.getDictFilterField(
        User,
        select_field=User.id,
        id_list=[info['owner_uid'], info['relate_uid']])

    ##获取最近5天运行记录
    log_list = JobRunLog.query.filter_by(job_id=id).order_by(
        JobRunLog.id.desc())[0:5]
    log_data = []
    if log_list:
        for item in log_list:
            tmp_data = ModelHelper.model2Dict(item)
            tmp_data['status_desc'] = CommonConstant.job_log_status_map[
                tmp_data['status']]
            tmp_data['duration'] = ""
            if DateHelper.getCurrentTime(date=tmp_data['end_time']
                                         ) == CommonConstant.DEFAULT_DATETIME:
                tmp_data['end_time'] = "未知"
                tmp_data['duration'] = time.time() - time.mktime(
                    tmp_data['start_time'].timetuple())
            else:
                tmp_data['duration'] = tmp_data['end_time'].timestamp(
                ) - tmp_data['start_time'].timestamp()
            tmp_data['duration'] = DateHelper.formatBeautyTime(
                tmp_data['duration'])
            log_data.append(tmp_data)

    return UtilHelper.renderView(
        "home/job/index/info.html", {
            "info": info,
            "log_list": log_data,
            "user_map": user_map,
            "job_level_map": CommonConstant.job_level_map,
        })
Пример #6
0
def LogOut():
    response = make_response(
        redirect(GlobalUrlService.buildHomeUrl("/user/login")))
    response.delete_cookie(CommonConstant.AUTH_COOKIE_NAME)
    return response