def _create_user(self, _request): from ppmessage.db.models import DeviceUser _user_email = _request.get("user_email") _user_fullname = _request.get("user_fullname") _user_password = _request.get("user_password") _user_language = _get_config().get("server").get("language").get("locale") _user_icon = random_identicon(_user_email) IOLoop.current().spawn_callback(download_random_identicon, _user_icon) _user_uuid = str(uuid.uuid1()) _row = DeviceUser(uuid=_user_uuid, user_email=_user_email, user_icon=_user_icon, user_status=USER_STATUS.OWNER_2, user_fullname=_user_fullname, user_password=_user_password, user_language=_user_language) _row.create_redis_keys(self.application.redis) _insert_into(_row) self._user_uuid = _user_uuid self._user_fullname = _user_fullname return True
def _create_user(self, _request): from ppmessage.db.models import DeviceUser _user_email = _request.get("user_email") _user_fullname = _request.get("user_fullname") _user_password = _request.get("user_password") _user_icon = random_identicon(_user_email) IOLoop.current().spawn_callback(download_random_identicon, _user_icon) _row = DeviceUser( uuid=self._user_uuid, user_email=_user_email, user_icon=_user_icon, user_status=USER_STATUS.OWNER_2, user_fullname=_user_fullname, user_password=_user_password, is_removed_user=False, is_owner_user=True, is_service_user=True, is_anonymous_user=False ) _row.create_redis_keys(self.application.redis) _insert_into(_row) self._user_fullname = _user_fullname return True
def _create(self, _ppcom_trace_uuid): _redis = self.application.redis _key = DeviceUser.__tablename__ + ".ppcom_trace_uuid." + _ppcom_trace_uuid _uuid = _redis.get(_key) if _uuid != None: _user = redis_hash_to_dict(_redis, DeviceUser, _uuid) if _user != None: _rdata = self.getReturnData() _rdata["user_uuid"] = _uuid _rdata["user_email"] = _user["user_email"] _rdata["user_fullname"] = _user["user_fullname"] _rdata["user_icon"] = _user["user_icon"] _rdata["user_status"] = _user.get("user_status") return _du_uuid = str(uuid.uuid1()) _user_email = _du_uuid[:6] + "@" + self.app_uuid[:6] _user_name = self._unknown_user_name() _user_icon = random_identicon(_du_uuid) _values = { "uuid": _du_uuid, "ppcom_trace_uuid": _ppcom_trace_uuid, "user_status": USER_STATUS.ANONYMOUS, "is_anonymous_user": True, "user_name": _user_name, "user_email": _user_email, "user_fullname": _user_name, "user_icon": _user_icon } _row = DeviceUser(**_values) _row.async_add(self.application.redis) _row.create_redis_keys(self.application.redis) _data_uuid = str(uuid.uuid1()) _values = { "uuid": _data_uuid, "user_uuid": _du_uuid, "user_fullname": _user_name, "app_uuid": self.app_uuid, "is_portal_user": True, "is_service_user": False, "is_owner_user": False } _row = AppUserData(**_values) _row.async_add(self.application.redis) _row.create_redis_keys(self.application.redis) _rdata = self.getReturnData() _rdata["user_uuid"] = _du_uuid _rdata["user_fullname"] = _user_name _rdata["user_email"] = _user_email _rdata["user_name"] = _user_name _rdata["user_icon"] = _user_icon _ip = self.request.headers.get("X-Real-Ip") or self.request.headers.get("remote_ip") or self.request.remote_ip IOLoop.current().spawn_callback(self._create_user_name, user_uuid=_du_uuid, data_uuid=_data_uuid, ip=_ip) return
def _create_user(self, _request): from ppmessage.db.models import DeviceUser _user_email = _request.get("user_email") _user_fullname = _request.get("user_fullname") _user_password = _request.get("user_password") _user_language = _get_config().get("server").get("language").get( "locale") _user_icon = random_identicon(_user_email) IOLoop.current().spawn_callback(download_random_identicon, _user_icon) _row = DeviceUser(uuid=self._user_uuid, app_uuid=self._app_uuid, user_email=_user_email, user_icon=_user_icon, user_status=USER_STATUS.OWNER_2, user_fullname=_user_fullname, user_password=_user_password, user_language=_user_language) _row.create_redis_keys(self.application.redis) _insert_into(_row) self._user_fullname = _user_fullname return True
def _create_third_party(self, _app_uuid, _user_email, _user_fullname, _user_icon): _redis = self.application.redis _du_uuid = str(uuid.uuid1()) _values = { "uuid": _du_uuid, "user_status": USER_STATUS.THIRDPARTY, "user_name": _user_email, "user_email": _user_email, "user_fullname": _user_fullname, "is_anonymous_user": False, } if _user_icon != None: _values["user_icon"] = _user_icon _row = DeviceUser(**_values) _row.async_add() _row.create_redis_keys(_redis) _data_uuid = str(uuid.uuid1()) _values = { "uuid": _data_uuid, "user_uuid": _du_uuid, "app_uuid": _app_uuid, "is_portal_user": True, "is_service_user": False, "is_owner_user": False, "is_distributor_user": False, } _row = AppUserData(**_values) _row.async_add() _row.create_redis_keys(_redis) _r = self.getReturnData() _r["user_uuid"] = _du_uuid return
def _create_user(self, _request): from ppmessage.db.models import DeviceUser _user_email = _request.get("user_email") _user_fullname = _request.get("user_fullname") _user_password = _request.get("user_password") _user_icon = random_identicon(_user_email) _row = DeviceUser( uuid=self._user_uuid, user_email=_user_email, user_icon=_user_icon, user_status=USER_STATUS.OWNER_2, user_fullname=_user_fullname, user_password=_user_password, is_removed_user=False, is_owner_user=True, is_service_user=True, is_anonymous_user=False ) _row.create_redis_keys(_redis) _insert_into(_row) self._user_fullname = _user_fullname return True
def _create_third_party(self, _user_email, _user_fullname, _user_icon): _redis = self.application.redis _du_uuid = str(uuid.uuid1()) _values = { "uuid": _du_uuid, "user_status": USER_STATUS.THIRDPARTY, "user_name": _user_email, "user_email": _user_email, "user_fullname": _user_fullname, "is_anonymous_user": False, } if _user_icon != None: _values["user_icon"] = _user_icon _row = DeviceUser(**_values) _row.async_add() _row.create_redis_keys(_redis) _data_uuid = str(uuid.uuid1()) _values = { "uuid": _data_uuid, "user_uuid": _du_uuid, "app_uuid": self.app_uuid, "is_portal_user": True, "is_service_user": False, "is_owner_user": False, "is_distributor_user": False, } _row = AppUserData(**_values) _row.async_add() _row.create_redis_keys(_redis) _r = self.getReturnData() _r["user_uuid"] = _du_uuid return
def create_device_user(redis, request): _uuid = request.get("uuid") if not _uuid: logging.error("no uuid provided. %s" % request) return None _is_service_user = bool(request.get("is_service_user")) _is_anonymous_user = bool(request.get("is_anonymous_user")) _is_owner_user = bool(request.get("is_owner_user")) _user_email = request.get("user_email") if not _user_email: import strgen _user_email = strgen.StringGenerator("[\d\w]{10}").render( ) + "@" + strgen.StringGenerator("[\d\w]{10}").render() _user_icon = request.get("user_icon") if not _user_icon: _user_icon = random_identicon(_user_email) _user_name = request.get("user_name") _user_mobile = request.get("user_mobile") _user_fullname = request.get("user_fullname") _user_password = request.get("user_password") _user_language = request.get("user_language") or "cn" _ent_user_uuid = request.get("ent_user_uuid") _ent_user_createtime = request.get("ent_user_createtime") import pypinyin if not isinstance(_user_fullname, unicode): _user_fullname = _user_fullname.decode("utf-8") _user_pinyin = "".join(pypinyin.lazy_pinyin(_user_fullname)) _user_py = "".join( pypinyin.lazy_pinyin(_user_fullname, style=pypinyin.FIRST_LETTER)) _values = { "uuid": _uuid, "is_service_user": _is_service_user, "is_owner_user": _is_owner_user, "is_ppmessage_user": _is_ppmessage_user, "is_anonymous_user": _is_anonymous_user, "user_name": _user_name, "user_mobile": _user_mobile, "user_email": _user_email, "user_icon": _user_icon, "user_fullname": _user_fullname, "user_password": _user_password, "user_pinyin": _user_pinyin, "user_py": _user_py, "ent_user_uuid": _ent_user_uuid, "ent_user_createtime": _ent_user_createtime } _row = DeviceUser(**_values) _row.async_add(redis) _row.create_redis_keys(redis) return _values
def _create(self, _ppcom_trace_uuid): _redis = self.application.redis _key = DeviceUser.__tablename__ + ".ppcom_trace_uuid." + _ppcom_trace_uuid _uuid = _redis.get(_key) if _uuid != None: _user = redis_hash_to_dict(_redis, DeviceUser, _uuid) if _user != None: _rdata = self.getReturnData() _rdata["user_uuid"] = _uuid _rdata["user_email"] = _user["user_email"] _rdata["user_fullname"] = _user["user_fullname"] _rdata["user_icon"] = _user["user_icon"] return _du_uuid = str(uuid.uuid1()) _user_email = _du_uuid[:6] + "@" + self.app_uuid[:6] _user_name = self._unknown_user_name() _values = { "uuid": _du_uuid, "ppcom_trace_uuid": _ppcom_trace_uuid, "user_status": USER_STATUS.ANONYMOUS, "is_anonymous_user": True, "user_name": _user_name, "user_email": _user_email, "user_fullname": _user_name, "user_icon": create_user_icon(_du_uuid), } _row = DeviceUser(**_values) _row.async_add(self.application.redis) _row.create_redis_keys(self.application.redis) _data_uuid = str(uuid.uuid1()) _values = { "uuid": _data_uuid, "user_uuid": _du_uuid, "app_uuid": self.app_uuid, "is_portal_user": True, "is_service_user": False, "is_owner_user": False } _row = AppUserData(**_values) _row.async_add(self.application.redis) _row.create_redis_keys(self.application.redis) _rdata = self.getReturnData() _rdata["user_uuid"] = _du_uuid _rdata["user_fullname"] = _user_name _rdata["user_email"] = _user_email _rdata["user_name"] = _user_name _ip = self.request.headers.get("X-Real-Ip") or self.request.headers.get("remote_ip") or self.request.remote_ip logging.info(str(self.request.headers)) logging.info("create anonymous ip: %s" % _ip) IOLoop.instance().spawn_callback(self._create_user_name, user_uuid=_du_uuid, ip=_ip) return
def create_device_user(redis, request): _uuid = request.get("uuid") if not _uuid: logging.error("no uuid provided. %s" % request) return None _is_service_user = bool(request.get("is_service_user")) _is_anonymous_user = bool(request.get("is_anonymous_user")) _is_owner_user = bool(request.get("is_owner_user")) _user_email = request.get("user_email") if not _user_email: import strgen _user_email = strgen.StringGenerator("[\d\w]{10}").render() + "@" + strgen.StringGenerator("[\d\w]{10}").render() _user_icon = request.get("user_icon") if not _user_icon: _user_icon = random_identicon(_user_email) _user_name = request.get("user_name") _user_mobile = request.get("user_mobile") _user_fullname = request.get("user_fullname") _user_password = request.get("user_password") _user_language = request.get("user_language") or "cn" _ent_user_uuid = request.get("ent_user_uuid") _ent_user_createtime = request.get("ent_user_createtime") import pypinyin if not isinstance(_user_fullname, unicode): _user_fullname = _user_fullname.decode("utf-8") _user_pinyin = "".join(pypinyin.lazy_pinyin(_user_fullname)) _user_py = "".join(pypinyin.lazy_pinyin(_user_fullname, style=pypinyin.FIRST_LETTER)) _values = { "uuid": _uuid, "is_service_user": _is_service_user, "is_owner_user": _is_owner_user, "is_ppmessage_user": _is_ppmessage_user, "is_anonymous_user": _is_anonymous_user, "user_name": _user_name, "user_mobile": _user_mobile, "user_email": _user_email, "user_icon": _user_icon, "user_fullname": _user_fullname, "user_password": _user_password, "user_pinyin": _user_pinyin, "user_py": _user_py, "ent_user_uuid": _ent_user_uuid, "ent_user_createtime": _ent_user_createtime } _row = DeviceUser(**_values) _row.async_add(redis) _row.create_redis_keys(redis) return _values
def _create(self, _ppcom_trace_uuid): _redis = self.application.redis _key = DeviceUser.__tablename__ + ".ppcom_trace_uuid." + _ppcom_trace_uuid _uuid = _redis.get(_key) logging.info(_key) if _uuid != None: _user = redis_hash_to_dict(_redis, DeviceUser, _uuid) if _user != None: _rdata = self.getReturnData() _rdata["user_uuid"] = _uuid _rdata["user_email"] = _user["user_email"] _rdata["user_fullname"] = _user["user_fullname"] _rdata["user_icon"] = _user["user_icon"] return _du_uuid = str(uuid.uuid1()) _user_email = _du_uuid[:6] + "@" + self.app_uuid[:6] _user_name = self._create_user_name() _values = { "uuid": _du_uuid, "ppcom_trace_uuid": _ppcom_trace_uuid, "user_status": USER_STATUS.ANONYMOUS, "is_anonymous_user": True, "user_name": _user_name, "user_email": _user_email, "user_fullname": _user_name, "user_icon": create_user_icon(_du_uuid), } _row = DeviceUser(**_values) _row.async_add() _row.create_redis_keys(self.application.redis) _data_uuid = str(uuid.uuid1()) _values = { "uuid": _data_uuid, "user_uuid": _du_uuid, "app_uuid": self.app_uuid, "is_portal_user": True, "is_service_user": False, "is_owner_user": False, "is_distributor_user": False, } _row = AppUserData(**_values) _row.async_add() _row.create_redis_keys(self.application.redis) _rdata = self.getReturnData() _rdata["user_uuid"] = _du_uuid _rdata["user_fullname"] = _user_name _rdata["user_email"] = _user_email _rdata["user_name"] = _user_name return
def _create(self, _ppcom_trace_uuid): _redis = self.application.redis _key = DeviceUser.__tablename__ + ".ppcom_trace_uuid." + _ppcom_trace_uuid _uuid = _redis.get(_key) if _uuid != None: _user = redis_hash_to_dict(_redis, DeviceUser, _uuid) if _user != None: _rdata = self.getReturnData() _rdata["user_uuid"] = _uuid _rdata["user_email"] = _user["user_email"] _rdata["user_fullname"] = _user["user_fullname"] _rdata["user_icon"] = _user["user_icon"] _rdata["user_status"] = _user.get("user_status") return _app_uuid = _get_config().get("team").get("app_uuid") _du_uuid = str(uuid.uuid1()) _user_email = _du_uuid + "@" + _app_uuid _user_name = self._unknown_user_name() _user_icon = random_identicon(_du_uuid) _values = { "uuid": _du_uuid, "ppcom_trace_uuid": _ppcom_trace_uuid, "user_status": USER_STATUS.ANONYMOUS, "is_anonymous_user": True, "is_service_user": False, "is_owner_user": False, "is_removed_user": False, "user_name": _user_name, "user_email": _user_email, "user_fullname": _user_name, "user_icon": _user_icon } _row = DeviceUser(**_values) _row.async_add(self.application.redis) _row.create_redis_keys(self.application.redis) _rdata = self.getReturnData() _rdata["user_uuid"] = _du_uuid _rdata["user_fullname"] = _user_name _rdata["user_email"] = _user_email _rdata["user_name"] = _user_name _rdata["user_icon"] = _user_icon _ip = self.request.headers.get( "X-Real-Ip") or self.request.headers.get( "remote_ip") or self.request.remote_ip IOLoop.current().spawn_callback(self._create_user_name, user_uuid=_du_uuid, ip=_ip) return
def _create(self, _ppcom_trace_uuid): _redis = self.application.redis _key = DeviceUser.__tablename__ + ".ppcom_trace_uuid." + _ppcom_trace_uuid _uuid = _redis.get(_key) logging.info(_key) if _uuid != None: _user = redis_hash_to_dict(_redis, DeviceUser, _uuid) if _user != None: _rdata = self.getReturnData() _rdata["user_uuid"] = _uuid _rdata["user_email"] = _user["user_email"] _rdata["user_fullname"] = _user["user_fullname"] _rdata["user_icon"] = _user["user_icon"] return _du_uuid = str(uuid.uuid1()) _user_email = _du_uuid[:6] + "@" + self.app_uuid[:6] _user_name = self._create_user_name() _values = { "uuid": _du_uuid, "ppcom_trace_uuid": _ppcom_trace_uuid, "user_status": USER_STATUS.ANONYMOUS, "is_anonymous_user": True, "user_name": _user_name, "user_email": _user_email, "user_fullname": _user_name, "user_icon": create_user_icon(_du_uuid), } _row = DeviceUser(**_values) _row.async_add(self.application.redis) _row.create_redis_keys(self.application.redis) _data_uuid = str(uuid.uuid1()) _values = { "uuid": _data_uuid, "user_uuid": _du_uuid, "app_uuid": self.app_uuid, "is_portal_user": True, "is_service_user": False, "is_owner_user": False, "is_distributor_user": False, } _row = AppUserData(**_values) _row.async_add(self.application.redis) _row.create_redis_keys(self.application.redis) _rdata = self.getReturnData() _rdata["user_uuid"] = _du_uuid _rdata["user_fullname"] = _user_name _rdata["user_email"] = _user_email _rdata["user_name"] = _user_name return
def create_user(_redis, _request): _user_email = _request.get("user_email") _user_status = _request.get("user_status") _user_fullname = _request.get("user_fullname") _user_language = _request.get("user_language") _user_password = _request.get("user_password") _is_service_user = _request.get("is_service_user") if not all([_user_email, _user_fullname]): return None _key = DeviceUser.__tablename__ + ".user_email." + _user_email if _redis.exists(_key): return None if _is_service_user == None: _is_service_user = False if _user_status == None: _user_status = USER_STATUS.THIRDPARTY _user_icon = random_identicon(_user_email) IOLoop.current().spawn_callback(download_random_identicon, _user_icon) _du_uuid = str(uuid.uuid1()) _values = { "uuid": _du_uuid, "user_status": _user_status, "user_name": _user_email, "user_email": _user_email, "user_icon": _user_icon, "user_language": _user_language, "user_fullname": _user_fullname, "user_password": _user_password, "is_removed_user": False, "is_anonymous_user": False, "is_service_user": _is_service_user, "is_owner_user": False } _row = DeviceUser(**_values) _row.async_add(_redis) _row.create_redis_keys(_redis) _user_values = _values return _user_values
def _create_user(self, _request): from ppmessage.db.models import DeviceUser _user_email = _request.get("user_email") _user_fullname = _request.get("user_fullname") _user_password = _request.get("user_password") _user_language = _request.get("user_language") _user_uuid = str(uuid.uuid1()) _row = DeviceUser(uuid=_user_uuid, user_email=_user_email, user_password=_user_password, user_language=_user_language) _row.create_redis_keys(self.application.redis) _row.async_add(self.application.redis) self._user_uuid = _user_uuid return True
def _create_third_party(self, _app_uuid, _user_email, _user_fullname, _user_icon): _redis = self.application.redis _du_uuid = str(uuid.uuid1()) _values = { "uuid": _du_uuid, "user_status": USER_STATUS.THIRDPARTY, "user_name": _user_email, "user_email": _user_email, "user_fullname": _user_fullname, "is_anonymous_user": False, } if _user_icon != None: _values["user_icon"] = _user_icon IOLoop.current().spawn_callback(download_random_identicon, _user_icon) else: _user_icon = random_identicon(_user_email) _values["user_icon"] = _user_icon IOLoop.current().spawn_callback(download_random_identicon, _user_icon) _row = DeviceUser(**_values) _row.async_add(_redis) _row.create_redis_keys(_redis) _data_uuid = str(uuid.uuid1()) _values = { "uuid": _data_uuid, "user_uuid": _du_uuid, "app_uuid": _app_uuid, "user_fullname": _user_fullname, "is_portal_user": True, "is_service_user": False, "is_owner_user": False } _row = AppUserData(**_values) _row.async_add(_redis) _row.create_redis_keys(_redis) _r = self.getReturnData() _r["user_uuid"] = _du_uuid return
def _create_user(self, _request): from ppmessage.db.models import DeviceUser _user_email = _request.get("user_email") _user_fullname = _request.get("user_fullname") _user_password = _request.get("user_password") _user_language = _get_config().get("server").get("language").get("locale") _user_uuid = str(uuid.uuid1()) _row = DeviceUser(uuid=_user_uuid, user_email=_user_email, user_status=USER_STATUS.OWNER_2, user_fullname=_user_fullname, user_password=_user_password, user_language=_user_language) _row.create_redis_keys(self.application.redis) _insert_into(_row) self._user_uuid = _user_uuid return True
def _create_user(self, _request): from ppmessage.db.models import DeviceUser _user_email = _request.get("user_email") _user_fullname = _request.get("user_fullname") _user_password = _request.get("user_password") _user_language = _get_config().get("server").get("language").get( "locale") _user_uuid = str(uuid.uuid1()) _row = DeviceUser(uuid=_user_uuid, user_email=_user_email, user_status=USER_STATUS.OWNER_2, user_fullname=_user_fullname, user_password=_user_password, user_language=_user_language) _row.create_redis_keys(self.application.redis) _insert_into(_row) self._user_uuid = _user_uuid return True
def create_user(redis, _request): ''' @param redis @param _request a dictionary contains create user's related param @return { 'error_code': xx, 'xxx': xx, 'yyy': xx, ... } ''' _return_data = { "error_code": API_ERR.NO_ERR } _app_uuid = _request.get("app_uuid") _user_email = _request.get("user_email") _user_firstname = _request.get("user_firstname") _user_lastname = _request.get("user_lastname") _user_fullname = _request.get("user_fullname") _user_language = _request.get("user_language") _user_company = _request.get("user_company") _is_service_user = _request.get("is_service_user") _user_status = _request.get("user_status") _user_password = _request.get("user_password") if _user_email == None or _app_uuid == None: _return_data["error_code"] = API_ERR.NO_PARA return _return_data if _user_fullname == None and _user_firstname == None and _user_lastname == None: _return_data["error_code"] = API_ERR.NO_PARA return _return_data _redis = redis _key = DeviceUser.__tablename__ + ".user_email." + _user_email if _redis.exists(_key): logging.error("user %s existed." % _user_email) _return_data["error_code"] = API_ERR.EX_USER _return_data["user_uuid"] = _redis.get(_key) return _return_data if _user_firstname != None and _user_lastname != None: _user_fullname = _user_firstname + " " + _user_lastname if _is_service_user != None: _is_portal_user = not _is_service_user _is_distributor_user = _is_service_user else: _is_service_user = False _is_portal_user = not _is_service_user _is_distributor_user = _is_service_user if _user_status == None: _user_status = USER_STATUS.THIRDPARTY _du_uuid = str(uuid.uuid1()) _values = { "uuid": _du_uuid, "user_status": _user_status, "user_name": _user_email, "user_email": _user_email, "user_fullname": _user_fullname, "user_firstname": _user_firstname, "user_lastname": _user_lastname, "user_company": _user_company, "user_password": _user_password, "is_anonymous_user": False, } _row = DeviceUser(**_values) _row.async_add() _row.create_redis_keys(_redis) _user_values = _values # if _app_uuid != PPMESSAGE_APP["uuid"]: # _data_uuid = str(uuid.uuid1()) # _values = { # "uuid": _data_uuid, # "user_uuid": _du_uuid, # "app_uuid": PPMESSAGE_APP["uuid"], # "is_portal_user": True, # "is_service_user": False, # "is_distributor_user": False, # "is_owner_user": False, # } # _row = AppUserData(**_values) # _row.async_add() # _row.create_redis_keys(_redis) _data_uuid = str(uuid.uuid1()) _values = { "uuid": _data_uuid, "user_uuid": _du_uuid, "app_uuid": _app_uuid, "is_portal_user": _is_portal_user, "is_service_user": _is_service_user, "is_distributor_user": _is_distributor_user, "is_owner_user": False, } _row = AppUserData(**_values) _row.async_add() _row.create_redis_keys(_redis) _rdata = _return_data _rdata.update(_user_values) return _rdata
def create_user(_redis, _request): ''' @param _redis @param _request a dictionary contains create user's related param @return user dict ''' _app_uuid = _request.get("app_uuid") _user_email = _request.get("user_email") _user_status = _request.get("user_status") _user_fullname = _request.get("user_fullname") _user_language = _request.get("user_language") _user_password = _request.get("user_password") _is_service_user = _request.get("is_service_user") if _user_email == None or _app_uuid == None or _user_fullname == None: return None _key = DeviceUser.__tablename__ + ".user_email." + _user_email if _redis.exists(_key): return None if _is_service_user != None: _is_portal_user = not _is_service_user _is_distributor_user = _is_service_user else: _is_service_user = False _is_portal_user = not _is_service_user _is_distributor_user = _is_service_user if _user_status == None: _user_status = USER_STATUS.THIRDPARTY _du_uuid = str(uuid.uuid1()) _values = { "uuid": _du_uuid, "user_status": _user_status, "user_name": _user_email, "user_email": _user_email, "user_language": _user_language, "user_fullname": _user_fullname, "user_password": _user_password, "is_anonymous_user": False, } _row = DeviceUser(**_values) _row.async_add(_redis) _row.create_redis_keys(_redis) _user_values = _values _data_uuid = str(uuid.uuid1()) _values = { "uuid": _data_uuid, "user_uuid": _du_uuid, "app_uuid": _app_uuid, "is_portal_user": _is_portal_user, "is_service_user": _is_service_user, "is_distributor_user": _is_distributor_user, "is_owner_user": False, } _row = AppUserData(**_values) _row.async_add(_redis) _row.create_redis_keys(_redis) return _user_values
def create_user(_redis, _request): ''' @param _redis @param _request a dictionary contains create user's related param @return user dict ''' _app_uuid = _request.get("app_uuid") _user_email = _request.get("user_email") _user_status = _request.get("user_status") _user_fullname = _request.get("user_fullname") _user_language = _request.get("user_language") _user_password = _request.get("user_password") _is_service_user = _request.get("is_service_user") if _user_email == None or _app_uuid == None or _user_fullname == None: return None _key = DeviceUser.__tablename__ + ".user_email." + _user_email if _redis.exists(_key): return None if _is_service_user != None: _is_portal_user = not _is_service_user else: _is_service_user = False _is_portal_user = not _is_service_user if _user_status == None: _user_status = USER_STATUS.THIRDPARTY _user_icon = random_identicon(_user_email) IOLoop.current().spawn_callback(download_random_identicon, _user_icon) _du_uuid = str(uuid.uuid1()) _values = { "uuid": _du_uuid, "user_status": _user_status, "user_name": _user_email, "user_email": _user_email, "user_icon": _user_icon, "user_language": _user_language, "user_fullname": _user_fullname, "user_password": _user_password, "is_anonymous_user": False, } _row = DeviceUser(**_values) _row.async_add(_redis) _row.create_redis_keys(_redis) _user_values = _values _data_uuid = str(uuid.uuid1()) _values = { "uuid": _data_uuid, "user_uuid": _du_uuid, "app_uuid": _app_uuid, "user_fullname": _user_values["user_fullname"], "is_portal_user": _is_portal_user, "is_service_user": _is_service_user, "is_owner_user": False } _row = AppUserData(**_values) _row.async_add(_redis) _row.create_redis_keys(_redis) return _user_values
def create_user(redis, _request): ''' @param redis @param _request a dictionary contains create user's related param @return { 'error_code': xx, 'xxx': xx, 'yyy': xx, ... } ''' _return_data = {"error_code": API_ERR.NO_ERR} _app_uuid = _request.get("app_uuid") _user_email = _request.get("user_email") _user_firstname = _request.get("user_firstname") _user_lastname = _request.get("user_lastname") _user_fullname = _request.get("user_fullname") _user_language = _request.get("user_language") _user_company = _request.get("user_company") _is_service_user = _request.get("is_service_user") _user_status = _request.get("user_status") _user_password = _request.get("user_password") if _user_email == None or _app_uuid == None: _return_data["error_code"] = API_ERR.NO_PARA return _return_data if _user_fullname == None and _user_firstname == None and _user_lastname == None: _return_data["error_code"] = API_ERR.NO_PARA return _return_data _redis = redis _key = DeviceUser.__tablename__ + ".user_email." + _user_email if _redis.exists(_key): logging.error("user %s existed." % _user_email) _return_data["error_code"] = API_ERR.EX_USER _return_data["user_uuid"] = _redis.get(_key) return _return_data if _user_firstname != None and _user_lastname != None: _user_fullname = _user_firstname + " " + _user_lastname if _is_service_user != None: _is_portal_user = not _is_service_user _is_distributor_user = _is_service_user else: _is_service_user = False _is_portal_user = not _is_service_user _is_distributor_user = _is_service_user if _user_status == None: _user_status = USER_STATUS.THIRDPARTY _du_uuid = str(uuid.uuid1()) _values = { "uuid": _du_uuid, "user_status": _user_status, "user_name": _user_email, "user_email": _user_email, "user_fullname": _user_fullname, "user_firstname": _user_firstname, "user_lastname": _user_lastname, "user_company": _user_company, "user_password": _user_password, "is_anonymous_user": False, } _row = DeviceUser(**_values) _row.async_add() _row.create_redis_keys(_redis) _user_values = _values # if _app_uuid != PPMESSAGE_APP["uuid"]: # _data_uuid = str(uuid.uuid1()) # _values = { # "uuid": _data_uuid, # "user_uuid": _du_uuid, # "app_uuid": PPMESSAGE_APP["uuid"], # "is_portal_user": True, # "is_service_user": False, # "is_distributor_user": False, # "is_owner_user": False, # } # _row = AppUserData(**_values) # _row.async_add() # _row.create_redis_keys(_redis) _data_uuid = str(uuid.uuid1()) _values = { "uuid": _data_uuid, "user_uuid": _du_uuid, "app_uuid": _app_uuid, "is_portal_user": _is_portal_user, "is_service_user": _is_service_user, "is_distributor_user": _is_distributor_user, "is_owner_user": False, } _row = AppUserData(**_values) _row.async_add() _row.create_redis_keys(_redis) _rdata = _return_data _rdata.update(_user_values) return _rdata