def get(self): """Display profile of current operator. """ status = ErrorCode.SUCCESS try: profile = DotDict() # 1: user oper = QueryHelper.get_operator_by_oid(self.current_user.oid, self.db) if not oper: status = ErrorCode.LOGIN_AGAIN logging.error("[UWEB] Operator does not exist, redirect to login.html. oid: %s.", self.current_user.oid) self.write_ret(status) return profile.update(oper) for key in profile.keys(): profile[key] = profile[key] if profile[key] else '' self.write_ret(status, dict_=dict(profile=profile)) except Exception as e: logging.exception("[UWEB] Get corp profile failed. oid:%s, tid:%s, Exception: %s", self.current_user.oid, self.current_user.tid, e.args) status = ErrorCode.SERVER_BUSY self.write_ret(status)
def get(self): status=ErrorCode.SUCCESS # from_ = self.get_argument('from', '').lower() index_html = "index.html" bizcode = None name = '' if self.current_user.oid != UWEB.DUMMY_OID: # operator index_html = "index_corp.html" umobile=self.current_user.oid user_info = QueryHelper.get_operator_by_oid(self.current_user.oid, self.db) corp_info = QueryHelper.get_corp_by_oid(self.current_user.oid, self.db) if user_info: name = user_info.name if user_info.name else user_info.mobile user_type = UWEB.USER_TYPE.OPERATOR bizcode = corp_info.bizcode elif self.current_user.cid != UWEB.DUMMY_CID: # corp index_html = "index_corp.html" umobile=self.current_user.cid user_info = QueryHelper.get_corp_by_cid(self.current_user.cid, self.db) if user_info: name = user_info.c_linkman if user_info.c_linkman else user_info.c_mobile user_type = UWEB.USER_TYPE.CORP bizcode = user_info.bizcode else: # user umobile=self.current_user.uid user_info = QueryHelper.get_user_by_uid(self.current_user.uid, self.db) if user_info: name = user_info.name if user_info.name else user_info.mobile user_type = UWEB.USER_TYPE.PERSON if not user_info: status = ErrorCode.LOGIN_AGAIN logging.error("The user with uid: %s does not exist, redirect to login.html", self.current_user.uid) self.render("login.html", username='', password='', user_type=UWEB.USER_TYPE.PERSON, message=None, message_captcha=None) return static_hash = self.redis.get('static_hash') static_hash = static_hash if static_hash else u'dummy_hash' wspush = dict(id='', key='') json_data = WSPushHelper.register_wspush(umobile, self.redis) if json_data: data = json_data['data'] id = data.get('push_id', '') key = data.get('psd', '') wspush['id'] = id wspush['key'] = key self.render(index_html, map_type=ConfHelper.LBMP_CONF.map_type, user_type=user_type, bizcode=bizcode, status=status, name=name, umobile=umobile, static_hash=static_hash, wspush=wspush,)
def post(self): """Retrieve the password.""" status = ErrorCode.SUCCESS try: data = DotDict(json_decode(self.request.body)) mobile = data.mobile captcha = data.get('captcha','') logging.info("[UWEB] corp retrieve password request: %s", data) except Exception as e: status = ErrorCode.ILLEGAL_DATA_FORMAT self.write_ret(status) return try: status = ErrorCode.SUCCESS psd = get_psd() user = QueryHelper.get_corp_by_cid(mobile, self.db) if user: # corp psd_info = dict(user_id=mobile, user_type=UWEB.USER_TYPE.CORP, password=psd) if not captcha: # old version update_password(psd_info, self.db, self.redis) else: # new version captcha_key = get_captcha_key(mobile) captcha_old = self.redis.get(captcha_key) if captcha_old: if captcha == str(captcha_old): update_password(psd_info, self.db, self.redis) else: status = ErrorCode.WRONG_CAPTCHA logging.error("[UWEB] Crop retrieve password failed." " mobile: %s, captcha: %s, captcha_old: %s, Message: %s", mobile, captcha, captcha_old, ErrorCode.ERROR_MESSAGE[status]) else: status = ErrorCode.NO_CAPTCHA logging.error("[UWEB] Corp retrieve password failed. " " mobile: %s, captcha: %s, Message: %s", mobile, captcha, ErrorCode.ERROR_MESSAGE[status]) else: user = QueryHelper.get_operator_by_oid(mobile, self.db) if user: # operator psd_info = dict(user_id=mobile, user_type=UWEB.USER_TYPE.OPERATOR, password=psd) if not captcha: # old version update_password(psd_info, self.db, self.redis) else: # new version captcha_key = get_captcha_key(mobile) captcha_old = self.redis.get(captcha_key) if captcha_old: if captcha == str(captcha_old): update_password(psd_info, self.db, self.redis) else: status = ErrorCode.WRONG_CAPTCHA logging.error("[UWEB] Operator retrieve password failed. " " mobile: %s, captcha: %s, captcha_old: %s, Message: %s", mobile, captcha, captcha_old, ErrorCode.ERROR_MESSAGE[status]) else: status = ErrorCode.NO_CAPTCHA logging.error("[UWEB] Operator retrieve password failed. " " mobile: %s, captcha: %s, Message: %s", mobile, captcha, ErrorCode.ERROR_MESSAGE[status]) else: status = ErrorCode.USER_NOT_ORDERED logging.error("[UWEB] Operator does not exist, retrieve password failed. mobile: %s", mobile) if status == ErrorCode.SUCCESS: retrieve_password_sms = SMSCode.SMS_RETRIEVE_PASSWORD % (psd) ret = SMSHelper.send(mobile, retrieve_password_sms) ret = DotDict(json_decode(ret)) if ret.status == ErrorCode.SUCCESS: logging.info("[UWEB] Corp retrieve password success, " " mobile: %s, the new passwrod: %s", mobile, psd) else: status = ErrorCode.SERVER_BUSY logging.error("[UWEB] Corp retrieve password failed. mobile: %s", mobile) self.write_ret(status) except Exception as e: logging.exception("[UWEB] Corp retrieve password failed. mobile: %s, Exception: %s", mobile, e.args) status = ErrorCode.SERVER_BUSY self.write_ret(status)