def post(self, action=None): ''' ''' if action: token = self.get_argument('token') manager = self.get_argument('manager') # check manager token self.check_token(manager, token) ids = [] # add holder & ap records if action == 'holder': holders = self.get_argument('holders') for holder in holders: try: _id = account.create_holder('', holder['mobile'], holder['address'], holder['realname']) except: pass if _id: # verify holder account.verify_holder(_id, expired=holder['expired'], mask=3, verify=1) ids.append(_id) elif action == 'ap': aps = self.get_argument('aps', []) # kwargs = {} # kwargs['vendor'] = self.get_argument('vendor') # kwargs['model'] = self.get_argument('model') # kwargs['mac'] = self.get_argument('mac') # kwargs['profile'] = self.get_argument('profile') # kwargs['fm'] = self.get_argument('fm') # ap deploy position # kwargs['point'] = (100, 99) for ap in aps: try: account.create_ap(**ap) except IntegrityError: logger.warning('ap\'s mac exsited: {}'.format(ap['mac'])) raise HTTPError(400, reason='mac address existed') else: raise HTTPError(400) self.render_json_response(Ids=ids, **OK) else: # manager login user = self.get_argument('user') password = self.get_argument('password') _user = account.get_manager(user) if not _user: raise HTTPError(404, reason='account not existed') if _user['password'] not in (password, util.md5(password).hexdigest()): raise HTTPError(403, reason='password error') token = util.token(user) content_type = self.request.headers.get('Content-Type', '') if content_type.startswith('application/json'): self.render_json_response(Manager=user, Token=token, **OK) else: self.redirect('/manager?token={}&manager={}'.format(token, user))
def post(self): ''' check mobile and send verify code to user client check mobile number ''' mobile = self.get_argument('mobile') if not self.check_mobile(mobile): raise HTTPError(400, reason='invalid mobile number') ssid, is_by, is_pynx = '', False, False pn = self.get_argument('pn', '') if pn == '29475': is_by = True elif pn in ('15914', '59484') or self.request.remote_ip == '58.248.228.170' or self.request.remote_ip.startswith('14.215.'): is_pynx = True pass verify = util.generate_verify_code() mask = int(self.get_argument('mask', 0)) # mask: 4 - web portal platform if mask>>8 & 1: code = util.md5(verify).hexdigest() code = code[12:16] + code[-4:] self.render_json_response(verify=code, pn=pn, ssid=ssid, **OK) else: self.render_json_response(verify=verify, pn=pn, ssid=ssid, **OK) # send verify code to special mobile data, request = '', '' if is_by: data = _const['msg_template'].format(verify) url = MobileHandler.BY_URL.format(data, mobile) request = tornado.httpclient.HTTPRequest(url, method='POST', body=b'') elif is_pynx: data = { 'uid':'3SSrNGX5O2eA', 'pas':'******', 'mob': mobile, 'cid':'Qg3Aa9Z57kuq', 'p1' : verify, 'type':'json', } bdata = urllib.urlencode(data).encode('utf-8') request = tornado.httpclient.HTTPRequest(MobileHandler.WEIMI_URL, method='POST', body=bdata) else: data = json_encoder({'mobile':mobile, 'code':verify}) request = tornado.httpclient.HTTPRequest(MobileHandler.URL, method='POST', headers={'Content-Type':'application/json'}, body=data) logger.info('send verify code: {} to mobile: {}, pn: {}'.format(verify, mobile, pn)) http_client = tornado.httpclient.AsyncHTTPClient() response = yield http_client.fetch(request) logger.info('response: {}'.format(response)) if response.code != 200: raise response.error
def wrapper(self, *args, **kwargs): appid = self.get_argument('appid', '') arguments = {key:value[0] for key,value in self.request.arguments.iteritems()} sign = kwargs.pop('sign', '') if appid and sign: record = account.get_appid(appid) # kwargs['appkey'] = record['appkey'] data = u'&'.join([u'{}={}'.format(key, kwargs[key]) for key in sorted(arguments.keys())]) data = data + u'&appkey={}'.format(record['appkey']) md5 = util.md5(data.encode('utf-8')).hexdigest() if sign != md5: raise HTTPError(403, reason='app sign check failed') return method(self)
def post(self, user=None): user = self.get_argument('user') password = self.get_argument('password') _user = account.get_bd_account(user) if not _user: raise HTTPError(404, reason='account not existed') # if password != _user['password']: # if _user['password'] not in (password, util.md5(password).hexdigest(), util.md5(_user['password']).hexdigest()): if password not in (_user['password'], util.md5(_user['password']).hexdigest()): raise HTTPError(403, reason='password error') token = util.token(user) _user.pop('password', '') self.render_json_response(User=_user['user'], Token=token, **OK)
def _gen_file_id_(self, *args): now = util.now() return util.md5(now, *args).hexdigest()
def _gen_project_id_(self, name, mobile): """ generate id by name&mobile """ return util.md5(name, mobile).hexdigest()
def _gen_project_id_(self, name, mobile): ''' generate id by name&mobile ''' return util.md5(name, mobile).hexdigest()