Esempio n. 1
0
def update(request, uid, **kwargs):
    user_id = uid
    account = {
        'user_id': user_id.encode('utf-8'),
        'username': '',
        'fullname': '',
        'email': '',
        'phone': '',
        'user_groups': []
    }
    my_auth = MyBasicAuthentication()
    is_login = my_auth.is_authenticated(request, **kwargs)
    if is_login:
        visit_permit = BackendRequest.can_visit({
            "token": is_login['t'],
            "operator": is_login['u'],
            "requestUrl": request.path[1:]
        })
        if (visit_permit['result']
                and visit_permit['can_visit']) or user_id == str(
                    is_login['i']):
            user_param = {
                'id': user_id,
                'token': is_login['t'],
                'operator': is_login['u']
            }
            res = BackendRequest.get_account(user_param)
            if res['result']:
                one_account = res.get('accounts', [])[0]
                account['username'] = one_account['name'].encode('utf-8')
                account['fullname'] = one_account['full_name'].encode('utf-8')
                account['email'] = one_account['email'].encode('utf-8')
                account['phone'] = one_account['phone'].encode('utf-8')
                account['user_groups'] = one_account['user_groups']

            page_data = {
                'account': account,
                "email": is_login["e"],
                "user": is_login["u"],
                "userid": is_login["i"]
            }
            return render(request, 'account/users_new.html',
                          {"page_data": json.dumps(page_data)})

        else:
            raise PermissionDenied
    elif is_login:
        page_data = {
            "user": is_login["u"],
            "email": is_login["e"],
            "userid": is_login["i"]
        }
        return render(request, 'account/users.html',
                      {"page_data": json.dumps(page_data)})
    else:
        return HttpResponseRedirect('/auth/login/')
Esempio n. 2
0
    def feedback_new(self, request, **kwargs):
        self.method_check(request, allowed=['post'])
        req_data = request.POST
        feedback_type = req_data.get('type', '')
        feedback_content = req_data.get('content', '')
        feedback_referrer = req_data.get('ref', '')

        dummy_data = {}
        my_auth = MyBasicAuthentication()
        es_check = my_auth.is_authenticated(request, **kwargs)
        if es_check:
            user_info_res = BackendRequest.get_account({
                "id": es_check['i'],
                'token': es_check['t'],
                'operator': es_check['u']
            })
            account = {
                "username": "",
                "fullname": "",
                "email": ""
            }
            if user_info_res["result"]:
                one_account = user_info_res.get('accounts', [])[0]
                account['username'] = one_account['name']
                account['fullname'] = one_account['full_name']
                account['email'] = one_account['email']

            ua = request.META.get('HTTP_USER_AGENT')

            email = "问题描述:"+ feedback_content + "</br></br>" + "-----------------------------------------</br>" + "useragent: " + \
                ua + "</br>" + "url:" + feedback_referrer + "</br>" + "</br>-----------------------------------------</br>" + "用户名:" + \
                    account['username'] +"</br>姓名:" + account["fullname"] + "</br>邮件:" + \
                account['email']
            res = self.send_mail(feedback_type, email)
            if res:
                dummy_data["status"] = "1"
            else:
                dummy_data = err_data.build_error({})
        else:
            data = err_data.build_error({}, "auth error!")
            data["location"] = "/auth/login/"
            dummy_data = data
        bundle = self.build_bundle(obj=dummy_data, data=dummy_data, request=request)
        response_data = bundle
        resp = self.create_response(request, response_data)
        return resp