def check(self): ''' 用于检测用户的登录状态 :return: ''' self.user_info = mine.get_value('user_info') logging.warning(self.user_info) ret = get_notes(self.user_info['username']) if not ret['status']: logging.error(ret['msg']) records = ret['records'] if 'records' in ret.keys() else list() if not records: table = 'Msg' dict = { 'message': 'Welcome', 'detail': 'Thanks\ you\ support', 'username': self.user_info['username'] } dict['message'] = cryptograph_text( dict['message'], 'message', user_name=self.user_info['username']) dict['detail'] = cryptograph_text( dict['detail'], 'detail', user_name=self.user_info['username']) sql = be_sql().ins_sql(table, dict) sqlite_db.transaction(sql) return self.user_info['username']
def update_notes(data, ele, **kwargs): # 加密 data[ele] = cryptograph_text(data[ele], ele, username=kwargs['username']) sql = "update Msg set {}=:{},update_time=datetime(CURRENT_TIMESTAMP, 'localtime') where id != -1 and id = ?".format( ele, ele) ret = sqlite_db.transaction(sql, [data['id']]) if not ret['status']: logging.error("message:{}\nsql:{}".format(ret['msg'], ret['errorsql'])) return ret
def add_notes(data): for k, v in data.items(): if 'username' != k: ele = k data[k] = cryptograph_text(v, k, username=data['username']) sql = "insert into Msg({},username) values(?,?)".format(ele) ret = sqlite_db.transaction(sql, [data[ele], data['usename']]) if not ret['status']: logging.error("message:{}\nsql:{}".format(ret['msg'], ret['errorsql'])) sql = "select * from Msg where username = ? and is_del = 0 order by id desc limit 0 ,1" ret = sqlite_db.select(sql, [data['username']], just_first=True) return ret
def add_msg(data: dict): ''' 添加数据 更改会影响 增加逻辑 延后重构 wrb :param filename: sqlit3文件名 :param data: dict {'id':-1,'{ele}':'','username':''} :return: ''' if data['id'] == -1: data.pop('id') # 明文加密 for k, v in data.items(): if 'username' != k: data[k] = cryptograph_text(v, k, user_name=data['username']) sql = "insert into msg(username,msg,detail) values(?,?,?)" ret = sqlite_db.transaction( sql, [data['username'], data['msg'], data['detail']]) if not ret['status']: logging.error("msg:{}\nsql:{}".format(ret['msg'], ret['sql'])) return ret
def login(username, password): ''' 客户端登录请求 :param username: :param password: :return: ''' url = '/api/login' headers = {'User-Agent': 'AirMemo'} # cryptograph_password() data = { 'username': username, 'password': cryptograph_text(password, 'password') } try: r = requests.post(protocol + user_host + url, headers=headers, data=data, proxies=config.proxies) return r.json() except Exception as e: logging.warning(e) return dict()
def login(url,username, password,*args,**kwargs): """request login api """ # cryptograph_password() data = {'username': username, 'password': cryptograph_text(password, 'password')} return air_api().post(url, data=data)