Exemple #1
0
def add_system_mail(request, info):
    """保存系统邮件"""
    logging.info(u"保存系统邮件")
    user = user_roles.get_userinfo(request)
    if user:
        username = user.username
    else:
        username = ""
        
    info["created_user"] = username
    info["status"] = 0
    info["approve_time"] = datetime.now()
    if not info["date"]:
        info["date"] = datetime.now()
        
    if info.get("lodo_ids"):
        lodo_id_set = set()
        lodo_id_list = info["lodo_ids"].split(",")
        for lodo_id in lodo_id_list:
            lodo_id_set.add(str(lodo_id.strip()))
        info["lodo_ids"] = ",".join(lodo_id_set)

    server_ids = info["server_ids"]
    server_id_list = server_ids.split(",")
    for server_id in server_id_list:
        server = server_business.get_server(server_id)
        if server.is_test == 0:#没有正式服权限
            if not user_roles.had_privilege(request, PageConstant.page_send_mail_id, 11):
                return -1

    return mail_business.add_system_mail(info)
Exemple #2
0
def login(request):
    if not request.POST:
        user = user_roles.get_userinfo(request)
        username = user and user.username or None
        data = {'username': username,
                'post_path': request.get_full_path()}
        return render_to_response(request, 'admin/login.html', data)
    
    # login post back
    username = request.POST.get('username', None)
    password = request.POST.get('password', None)

    if not username or not password:
        error_message = "用户名或者密码不能都不填写,请重新登录。";
        data = {'error_message': error_message,
                'post_path': request.get_full_path()}
        return render_to_response(request, 'admin/login.html', data) 
    
    r, session_id_or_msg = user_roles.login(username, password)
    if r == 0:
        redirect_to = request.GET.get("to", "/")
        response = HttpResponseRedirect(redirect_to)
        response.set_cookie(user_roles.SESSION_KEY, session_id_or_msg)
        return response
    else:
        data = {'username': username,
                'post_path': request.get_full_path(),
                "error_message": session_id_or_msg}
        return render_to_response(request, 'admin/login.html', data)
Exemple #3
0
def set_server_list(request):

    server_id = request.REQUEST.get('server_id', None)
    if server_id:
        request.COOKIES['sid'] = server_id

    server_id = request.COOKIES.get('sid', server_id)

    server_list = server_business.get_all_server_list()
    partner_list = partner_business.get_all_partner_list()
    user = user_roles.get_userinfo(request)

    server_list_map = {}
    for server in server_list:
        server_zone = server.server_zone
        server_zone_server_list = server_list_map.get(server_zone, [])
        server_zone_server_list.append(server)
        server_list_map[server_zone] = server_zone_server_list

    for k, values in server_list_map.iteritems():
        values = sorted(
            values,
            cmp=lambda x, y: cmp(int(x.server_id[1:]), int(y.server_id[1:])))
        server_list_map[k] = values

    return {
        'server_list': server_list,
        'server_id': server_id,
        'partner_list': partner_list,
        "user": user,
        "server_list_map": server_list_map,
        "server_zone_map": server_zone_map
    }
Exemple #4
0
def add_notice(request, info):
    user = user_roles.get_userinfo(request)
    if user:
        username = user.username
    else:
        username = ""

    nid = info["id"]
    nid = int(nid)
    if not nid:
        info["created_user"] = username

    return notice_business.add_notice(info)
Exemple #5
0
def system_exchange_list(request):
    page = int(request.REQUEST.get('page', 1))
    show_all = int(request.REQUEST.get('all', 0))
    pagesize = int(request.REQUEST.get('pagesize', 20))
    username = None
    if show_all == 0:
        user = user_roles.get_userinfo(request)
        if user:
            username = user.username

    infos, total = activity_business.get_system_tool_exchange_list(
        page, pagesize, username=username)
    return render_to_response(request, "manager/system_exchange_list.html",
                              locals())
Exemple #6
0
 def replace_function(*args, **kwargs):
     request = args[0]
     user = user_roles.get_userinfo(request)
     if user:
         request.user = user
         try:
             return input_function(*args, **kwargs)
         except:
             full_path = request.get_full_path()
             exception_mgr.on_except('request url: %r' % full_path, 1)
             log_execption('request url: %r' % full_path, 1)
             raise
     else:
         response = HttpResponseRedirect("/login/")
         return response
Exemple #7
0
 def replace_function(*args, **kwargs):
     request = args[0]
     user = user_roles.get_userinfo(request)
     if user or True:
         request.user = user
         try:
             return input_function(*args, **kwargs)
         except:                
             full_path = request.get_full_path()
             exception_mgr.on_except('request url: %r' % full_path, 1)
             log_execption('request url: %r' % full_path, 1)
             raise
     else:
         response = HttpResponseRedirect('/login/')
         return response
Exemple #8
0
def system_mail_approve(request, system_mail_id, approve):
    user = user_roles.get_userinfo(request)
    if user:
        username = user.username
    else:
        username = ""
        
    system_mail = mail_business.get_system_mail(system_mail_id)
    server_id_list = system_mail.server_ids.split(",")
    for server_id in server_id_list:
        server = server_business.get_server(server_id)
        if server.is_test == 0:#没有正式服权限
            if not user_roles.had_privilege(request, PageConstant.page_approve_mail_id, 11):
                return -1, None
           
    return mail_business.system_mail_approve(system_mail_id, username, int(approve) == 1)
Exemple #9
0
def system_pay_reward_list(request, reward_type=1):
    page = int(request.REQUEST.get('page', 1))
    pagesize = int(request.REQUEST.get('pagesize', 20))
    show_all = int(request.REQUEST.get('all', 0))
    name = u"单笔充值" if reward_type == 1 else u"累积充值"

    username = None
    if show_all == 0:
        user = user_roles.get_userinfo(request)
        if user:
            username = user.username

    infos, total = activity_business.get_system_pay_reward_list(
        page, pagesize, reward_type, username)
    return render_to_response(request, "manager/system_pay_reward_list.html",
                              locals())
Exemple #10
0
def add_system_pay_reward(request, rid, name, reward_type, server_ids):
    user = user_roles.get_userinfo(request)
    if user:
        username = user.username
    else:
        username = ""

    server_id_list = server_ids.split(",")
    for server_id in server_id_list:
        server = server_business.get_server(server_id)
        if server.is_test == 0:  #没有正式服权限
            if not user_roles.had_privilege(
                    request, PageConstant.page_pay_reward_id, 11):
                return -1

    return activity_business.add_system_pay_reward(rid, name, reward_type,
                                                   server_ids, username)
Exemple #11
0
def add_system_mall_discount(request, did, name, start_time, end_time,
                             server_ids):
    user = user_roles.get_userinfo(request)
    if user:
        username = user.username
    else:
        username = ""

    server_id_list = server_ids.split(",")
    for server_id in server_id_list:
        server = server_business.get_server(server_id)
        if server.is_test == 0:  #没有正式服权限
            if not user_roles.had_privilege(
                    request, PageConstant.page_mall_discount_id, 11):
                return -1

    return activity_business.add_system_mall_discount(did, name, start_time,
                                                      end_time, server_ids,
                                                      username)
def set_server_list(request):
    
    server_id = request.REQUEST.get('server_id', None)
    if server_id:
        request.COOKIES['sid'] = server_id
    
    server_id = request.COOKIES.get('sid', server_id)
    
    server_list = server_business.get_all_server_list()
    partner_list = partner_business.get_all_partner_list()
    user = user_roles.get_userinfo(request)
    
    server_list_map = {}
    for server in server_list:
        server_zone = server.server_zone
        server_zone_server_list = server_list_map.get(server_zone, [])
        server_zone_server_list.append(server)
        server_list_map[server_zone] = server_zone_server_list
        
    for k, values in server_list_map.iteritems():
        values = sorted(values, cmp=lambda x, y : cmp(int(x.server_id[1:]), int(y.server_id[1:])))
        server_list_map[k] = values
        
    return {'server_list': server_list, 'server_id': server_id, 'partner_list': partner_list, "user": user, "server_list_map": server_list_map, "server_zone_map": server_zone_map} 
Exemple #13
0
 def replace_function(*args, **kwargs):  #被替换执行的函数,主要工作就在这里完成
     request = args[0]  #这里要求参数传进来,第一个必须是request对象
     user = user_roles.get_userinfo(request)
     user_page = UserPage.load(user_id=int(user.id), page_id=page_id)
     if not user_page:
         response = HttpResponseRedirect("/privilege_error/")
         return response
     value = user_page.value
     if value == 1:
         response = HttpResponseRedirect("/privilege_error/")
         return response
     if operator_id and operator_id == 1 and value % 2 == 0:
         return input_function(*args, **kwargs)
     if operator_id and operator_id == 2 and value % 3 == 0:
         return input_function(*args, **kwargs)
     if operator_id and operator_id == 3 and value % 5 == 0:
         return input_function(*args, **kwargs)
     if operator_id and operator_id == 4 and value % 7 == 0:
         return input_function(*args, **kwargs)
     if operator_id and operator_id == 5 and value % 11 == 0:
         return input_function(*args, **kwargs)
     else:
         response = HttpResponseRedirect("/privilege_error/")
         return response
Exemple #14
0
 def replace_function(*args, **kwargs): #被替换执行的函数,主要工作就在这里完成
     request = args[0]#这里要求参数传进来,第一个必须是request对象
     user = user_roles.get_userinfo(request)
     user_page = UserPage.load(user_id=int(user.id), page_id=page_id)
     if not user_page:
         response = HttpResponseRedirect("/privilege_error/")
         return response
     value = user_page.value
     if value == 1:
         response = HttpResponseRedirect("/privilege_error/")
         return response
     if operator_id and operator_id == 1 and value % 2 == 0:
         return input_function(*args, **kwargs)
     if operator_id and operator_id == 2 and value % 3 == 0:
         return input_function(*args, **kwargs)
     if operator_id and operator_id == 3 and value % 5 == 0:
         return input_function(*args, **kwargs)
     if operator_id and operator_id == 4 and value % 7 == 0:
         return input_function(*args, **kwargs)
     if operator_id and operator_id == 5 and value % 11 == 0:
         return input_function(*args, **kwargs)
     else:
         response = HttpResponseRedirect("/privilege_error/")
         return response