Beispiel #1
0
    def auth_register(self, request, **kwargs):
        self.method_check(request, allowed=['post'])
        post_dict = request.POST
        param = {
            "token": "system",
            "from": post_dict.get('from', ''),
            "name": post_dict.get('username', ''),
            "full_name": post_dict.get('fullname', ''),
            "company": post_dict.get('company', ''),
            "email": post_dict.get('email', ''),
            "phone": post_dict.get('phone', ''),
            "server": post_dict.get('server', 0),
            "domain": post_dict.get('domain', ''),
            "passwd": post_dict.get('password', ''),
            "repasswd": post_dict.get('repassword', '')
        }
        param_check = self.__check_param(self, param, request)
        param['passwd'] = hashlib.md5(param['passwd']).hexdigest()
        param['repasswd'] = hashlib.md5(param['repasswd']).hexdigest()

        es_check = False
        dummy_data = {}
        token = ""
        if param['domain'] in self._meta.domain_blacklist:
            dummy_data["status"] = "0"
            dummy_data["msg"] = "domain is used"
            dummy_data["err_code"] = "3"
        elif param_check['has_error']:
                dummy_data["status"] = "0"
                dummy_data["msg"] = param_check['msg']
                dummy_data["err_code"] = param_check['err_code']
        else:
            # go to es-fe check user&password
            req = BackendRequest.create_domain(param,'')
            es_check = req['result']
            if es_check:
                token = req.get('token', '')
                request.session['user_name'] = param['name']
                request.session['user_pwd'] = param['passwd']
                request.session['user_tkn'] = token
                dummy_data["status"] = "1"
                dummy_data["location"] = "http://"+param['domain']+param['from']+"/search/"
            else:
                data = err_data.build_error(req)
                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)
        if es_check:
            cookie_string = hashlib.md5(param['name'] + ',' + param['domain'] + ',' + token).hexdigest()
            request.session['user_yottac'] = cookie_string
        return resp
Beispiel #2
0
    def auth_director(self, request, **kwargs):
        self.method_check(request, allowed=['post'])
        post_dict = request.POST
        param = {
            "token": "system",
            "from": post_dict.get('from', ''),
            "name": post_dict.get('username', ''),
            "full_name": post_dict.get('fullname', ''),
            "company": post_dict.get('company', ''),
            "email": post_dict.get('email', ''),
            "phone": post_dict.get('phone', ''),
            "server": post_dict.get('server', 0),
            "domain": post_dict.get('domain', ''),
            "passwd": post_dict.get('password', ''),
            "repasswd": post_dict.get('repassword', '')
        }
        param_check = self.__check_param(self, param, request)
        param['passwd'] = hashlib.md5(param['passwd']).hexdigest()
        param['repasswd'] = hashlib.md5(param['repasswd']).hexdigest()

        es_check = False
        dummy_data = {}
        token = ""
        if param['domain'] in self._meta.domain_blacklist:
            dummy_data["status"] = "0"
            dummy_data["msg"] = "domain is used"
            dummy_data["err_code"] = "3"
        elif param_check['has_error']:
                dummy_data["status"] = "0"
                dummy_data["msg"] = param_check['msg']
                dummy_data["err_code"] = param_check['err_code']
        else:
            # todo: new interface-- send active email to user when register and return token
            # key: active code
            # url: email url
            user_info_str = base64.b64encode(param['email'] + "|||" + param['domain'] + "|||" +
                                             str(time.time()))
            param['activate_key'] = hashlib.md5(user_info_str + SECRET).hexdigest()
            param['pre_activate'] = 1
            param['send_email'] = 1
            mail_url = "https://" + param['domain'] + from_url + "/auth/register/active/" + param['activate_key'] + "/" + \
                       user_info_str + "/"
            req = BackendRequest.create_domain(param, mail_url)
            es_check = req['result']
            if es_check:
                token = req.get('token', '')
                request.session['user_name'] = param['name']
                request.session['user_pwd'] = param['passwd']
                request.session['user_tkn'] = token
                for_base64 = base64.b64encode(param['email'] + '|||' + param['domain'] + '|||' + token)
                for_md5 = hashlib.md5(for_base64 + SECRET).hexdigest()
                dummy_data["status"] = "1"
                dummy_data["location"] = "https://"+param['domain']+param['from']+"/auth/register_info/"+for_md5+"/"+\
                                         for_base64+"/"
            else:
                data = err_data.build_error(req)
                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)
        if es_check:
            cookie_string = hashlib.md5(param['name'] + ',' + param['domain'] + ',' + token).hexdigest()
            request.session['user_yottac'] = cookie_string
        return resp