def ckeck_user_reports(self, request): user = request.args.get('logUser') # print user data = [] # 数据库获取数据 downloadpath = u'/static/files/' userid = DBHelper(ad_users).get_by(ad_user_name=user).id datas = DBHelper(task_data).find_by(user_id=userid) for item in datas: itemtime = item.upload_time.split(' ')[0] itemreport = item.task_report itemJournal = item.task_journal if itemreport and itemJournal: result = True reportpath = downloadpath + 'Report-files/' + itemreport journalpath = downloadpath + 'Journal-files/' + itemJournal else: result = False reportpath = '' journalpath = '' data.append({ 'Number': item.id, 'Taskname': item.task_name, 'Uploadtime': itemtime, 'Result': result, 'Reportpath': reportpath, 'Journalpath': journalpath }) return {"data": data}
def judge_user(self, request): user = request.form.get('logUser') pwd = request.form.get('logPwd') print pwd, user # _adusers = ad_users.handle() # sql = 'SELECT * FROM paic_admin.ad_users where ad_user_name = "{0}"'.format(user) # result = HANDLE('paic_admin', sql).submit() # if result: # if pwd ==result.ad_user_password: # return {'data':result.ad_user_family} # else: # return {'data':'密码错误,请重新输入密码!'} # else: # return {'data':'此账号不存在,请注册后登录!'} if DBHelper(ad_users).get_by(ad_user_name=user): data = DBHelper(ad_users).get_by(ad_user_name=user) if data.ad_user_try == 5: if self.unlocktime(data.ad_user_time): return self.jg_password(data, user, pwd) else: return { 'data': '您的账号被锁定1小时,请于 {0} 后再尝试登录!'.format(data.ad_user_time), 'status': 201 } else: return self.jg_password(data, user, pwd) else: return {'data': '此账号不存在,请注册后登录!', 'status': 202}
def account_ver(self, user, pwd, comeform): if user not in DBHelper(ad_users).find_col_by('ad_user_name'): safepwd = self.pwd_encrypt(pwd) DBHelper(ad_users).new(ad_user_name=user, ad_user_password=safepwd, ad_user_family=comeform) return {'status': 200, 'msg': ''} else: return {'msg': '账号已存在,请登录或联系管理员.', 'status': 101}
def admin_check_phone(self, request): Number = request.args.get('id') data = [] for item in DBHelper(task_data).get_by( id=Number).task_models.split(','): print int(item) model = DBHelper(phone_model).get_by( id=int(item)).phone_model_name_ch data.append(model) return {'data': data}
def reportdata_save(self, taskNumb, filename, tasktype): data = DBHelper(task_data).get_by(id=taskNumb) if int(tasktype) == 0: if data.task_report: # print data.task_report self.delete_report_data(data.task_report, 'Report-files') DBHelper(task_data).set({'task_report': filename}, {'id': taskNumb}) else: if data.task_journal: self.delete_report_data(data.task_journal, 'Journal-files') DBHelper(task_data).set({'task_journal': filename}, {'id': taskNumb})
def updata_save(self, Number, filename, Times, style): if style == 'apk': DBHelper(task_data).set( { 'apk_data': filename, 'upload_time': Times }, {'id': Number}) elif style == 'case': DBHelper(task_data).set( { 'case_data': filename, 'upload_time': Times }, {'id': Number})
def uploaddata_save(self, apk_result, excel_result, taskname, models, user, remarks): uploadtime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") # print '-------------' userid = DBHelper(ad_users).get_by(ad_user_name=user).id DBHelper(task_data).new(user_id=userid, task_name=taskname, apk_data='{0}'.format(apk_result), case_data='{0}'.format(excel_result), task_models=','.join(models), task_remarks=remarks, upload_time=uploadtime)
def send_repair_info(self, request): user = request.form.get('logUser') oldpwd = request.form.get('oldPwd') newpwd = request.form.get('newPwd') # print user,oldpwd,newpwd if DBHelper(ad_users).get_by(ad_user_name=user): data = DBHelper(ad_users).get_by(ad_user_name=user) if self.check_ecrypt_pwd(data.ad_user_password, oldpwd): DBHelper(ad_users).set( {'ad_user_password': self.pwd_encrypt(newpwd)}, {'ad_user_name': user}) return {'msg': '密码修改成功!', 'status': 200} else: return {'msg': '原密码错误,请输入正确的原密码!', 'status': 202} else: return {'msg': '此账号错误,请稍后再试或联系服务人员!', 'status': 201}
def jg_password(self, data, user, pwd): if self.check_ecrypt_pwd(data.ad_user_password, pwd): session_id = Encrypt_Helper().makeSessionId(user) DBHelper(ad_users).set( { "ad_user_token": session_id, 'ad_user_time': nowtime(), 'ad_user_try': 0 }, dict(ad_user_name=user)) self.set_session(user, session_id, data.ad_user_family) return { 'data': data.ad_user_family, 'status': 200, 'username': user } else: if data.ad_user_try < 4: DBHelper(ad_users).set( { 'ad_user_time': nowtime(), 'ad_user_try': data.ad_user_try + 1 }, dict(ad_user_name=user)) return { 'data': '密码错误,请重新输入密码,您还有{0}次尝试的机会,5次错误账号将锁定1小时!'.format( 4 - data.ad_user_try), 'status': 201 } elif data.ad_user_try == 4: unlocktime = datetime.datetime.now() + datetime.timedelta( hours=1) DBHelper(ad_users).set( { 'ad_user_time': unlocktime.strftime("%Y-%m-%d %H:%M:%S"), 'ad_user_try': data.ad_user_try + 1 }, dict(ad_user_name=user)) return { 'data': '您的账号将锁定1小时,请于 {0} 后再尝试登录!'.format( unlocktime.strftime("%Y-%m-%d %H:%M:%S")), 'status': 201 }
def delete_user_data(self, Number, style): # 通过任务ID获取信息并且操作 task = DBHelper(task_data).get_by(id=Number) if style == 'apk': if task.apk_data: self.delete_apk_data('Apk-files', task.apk_data) elif style == 'case': if task.case_data: self.delete_apk_data('TestCase-files', task.case_data)
def unlocktime(self, datatime): print datatime, nowtime() if datatime < nowtime(): DBHelper(ad_users).set( { 'ad_user_time': nowtime(), 'ad_user_try': 0 }, dict(ad_user_name=user)) return True else: return False
def get_phone_brand(self): brands = [] for item in DBHelper(phone_brand).find_by(remark=u'1'): models = self.get_brand_model(item.id) brands.append({ "id": item.id, 'name': item.brand_name, 'name_ch': item.brand_name_ch, 'model_total': models }) return {'data': brands}
def get_admin_check(self, request): user = request.args.get('logUser') APK_files = u'/static/files/Apk-files/' Test_files = u'/static/files/TestCase-files/' datas = DBHelper(task_data).all() data = [] if user == 'admin': for item in datas: apkpath = testpath = False if item.apk_data: apkpath = APK_files + item.apk_data if item.case_data: testpath = Test_files + item.case_data timeshare = item.upload_time.split(' ')[0] report = False journal = False Remarks = False if item.task_remarks and item.task_remarks != ' ': Remarks = True if item.task_report: report = True if item.task_journal: journal = True data.append({ 'Number': item.id, 'Taskname': item.task_name, 'Uploadtime': timeshare, 'APK': apkpath, 'TestCase': testpath, 'Report': report, 'remarks': Remarks, 'Journal': journal }) return {'data': data}
def admin_check_msg(self, request): Number = request.args.get('id') data = DBHelper(task_data).get_by(id=Number).task_remarks return {'data': data}
def get_session(self, name): # print name return DBHelper(ad_users).get_by(ad_user_name=name).ad_user_token
def login_out(self): name = session.pop('username') session.pop('userform') session.pop(name) DBHelper(ad_users).set({"ad_user_token": ''}, dict(ad_user_name=name)) return