def put(self, id): data = user.parser.parse_args() User = userModel.find_by_id(id) data1 = [] if User and User.Status == True: # if userModel.find_by_name(data['username']): # return {'message': "A user with name '{}' already exists.".format(data['username'])}, 400 # # # if userModel.find_by_name(data['email']): # return {'message': "A user with name '{}' already exists.".format(data['email'])}, 400 if len(data['mobilephone']) == 10 and data['mobilephone'].isdigit( ) == True: mobilephone1 = data['mobilephone'] else: return ("invalid mobilephone") User.name = data['name'] User.username = data['username'] User.email = data['email'] User.mobilephone = data['mobilephone'] User.department_id = data['department_id'] User.designation_id = data['designation_id'] data = {"message": "record upadated successfully", "id": User.id} User.save_to_db() data1.append(data) return (data1) else: return {"message": "no record found"}, 404
def get(self, survey_id, user_id): survey = surveyresponseModel.find3_by_id(survey_id, user_id) # print(survey.id) # question=questionModel.find3_by_id() data1 = [] if survey: for x in survey: question = questionModel.find_by_id(x.question_id) user = userModel.find_by_id(x.user_id) survey1 = surveyModel.find_by_id(x.survey_id) option1 = optionsModel.find_by_id(x.option) print("sarathsssss", option1.options) # print(question.description) que_des = question.description user_name = user.name survey1 = survey1.name option = option1.options data5 = { "questionID": x.question_id, "question": question.description } data6 = {"optionID": x.option, "option": option1.options} # print(survey.user_id) data = {"id": x.id, "question": data5, "option": data6} data1.append(data) data2 = { "employee name": user_name, "survey name": survey1, "results": data1 } return (data2) else: return {"message": 'user have no option on respective survey'}
def get(self): audit=[] args = request.args search = request.args s_final = search.to_dict() # page = int(s_final['page']) # page = page-1 # print(page) # per_page = 5 startdatess = datetime.strptime('2020-09-12 04:30:35.306285','%Y-%m-%d %H:%M:%S.%f') print(startdatess, datetime.now()) if "startDate" in args and args.get("startDate") !='': startdates = datetime.strptime(args.get("startDate"), '%Y-%m-%d %H:%M:%S.%f') else: startdates = datetime.strptime('2020-09-12 04:30:35.306285','%Y-%m-%d %H:%M:%S.%f') if "endDate" in args and args.get("endDate") !='': enddates = datetime.strptime(args.get("endDate"), '%Y-%m-%d %H:%M:%S.%f') else: enddates = datetime.now() print(enddates) if "page" in args and args.get("page")!='': page = int(s_final['page']) page = int(page-1) else: page=1 # page = page-1 if "per_page" in args and args.get("per_page")!='': per_page=int(args.get('per_page')) else: per_page=apps.config["PER_PAGE"] for x in auditlogModel.query.filter(auditlogModel.created >= startdates, auditlogModel.created <= enddates): user =userModel.find_by_id(x.user_id) time=str(x.created) data={ "username":user.username, "page":x.page, "action":x.action, "timestamp":time, # "sourceIp":x.sourceIp } audit.append(data) if audit==[]: return{"message":"no record found"}, 404 else: if page!=-1: print("222",len(audit)) length=len(audit) p=length/per_page l=math.ceil(p) my_list = [audit[i:i + per_page] for i in range(0, len(audit), per_page)][page] return {"data": my_list,"maximum page":l} else: return{"message":"page starts from 1"}
def post(self, id): data = request.get_json() min = apps.config["PASSWOR_MIN_LENGTH"] max = apps.config["PASSWOR_MAX_LENGTH"] SpecialSym = apps.config["SPECIAL_SYMBOL"] if len(data['new Password']) < min: return ('length should be at least 6') if len(data['new Password']) > max: return ('length should be not be greater than 12') if not any(char.isdigit() for char in data['new Password']): return ('Password should have at least one numeral') if not any(char.isupper() for char in data['new Password']): return ('Password should have at least one uppercase letter') if not any(char.islower() for char in data['new Password']): return ('Password should have at least one lowercase letter') if not any(char in SpecialSym for char in data['new Password']): return ('Password should have at least one of the symbols $@#%') current = userModel.find_by_id(id) if current: result = (check_password_hash(current.password, data['current Password'])) print(result) if result == True: if data['new Password'] == data['confirm Password']: data['current Password'] = data['new Password'] hashed_value = generate_password_hash( data['current Password']) print(hashed_value) userModel.change(id, hashed_value) accesstoken = create_access_token(identity=current.id, fresh=True) userModel.tokenUpdate1(id, accesstoken) return {"message": "changed password successfully"} else: return {"message": "unmatched passwords"}, 401 else: return {"message": "unmatched current password"}, 401 else: return {"message": "no record found"}, 404
def delete(self, id): user = userModel.find_by_id(id) data1 = [] if user: if user.Status == True: user_data_del = userModel.update_by_status(id) data = {"message": "record deleted", "id": user.id} data1.append(data) return (data1) else: return {'message': 'no record found.'}, 404 else: return {"message": "no record found"}, 404
def get(self, id): user = userModel.find_by_id(id) # print(user) if user and user.Status == True: depart = user.department_id design = user.designation_id depart_data = departmentModel.find_by_id(depart) design_data = designationModel.find_by_id(design) if depart_data and design_data: res_depart = depart_data.json() res_design = design_data.json() user.department_id = res_depart user.designation_id = res_design return user.json() else: return {"message": "no record found"}, 404
def post(self, user_id, accesstoken): data = request.get_json() min = apps.config["PASSWOR_MIN_LENGTH"] max = apps.config["PASSWOR_MAX_LENGTH"] SpecialSym = apps.config["SPECIAL_SYMBOL"] # user_id1=int(user_id) user = userModel.find_by_id(user_id) # print('ssssssssss',user) # token=userModel.find_by_token(accesstoken) if len(data['new Password']) < min: return ('length should be at least 6') if len(data['new Password']) > max: return ('length should be not be greater than 12') if not any(char.isdigit() for char in data['new Password']): return ('Password should have at least one numeral') if not any(char.isupper() for char in data['new Password']): return ('Password should have at least one uppercase letter') if not any(char.islower() for char in data['new Password']): return ('Password should have at least one lowercase letter') if not any(char in SpecialSym for char in data['new Password']): return ('Password should have at least one of the symbols $@#%') if user: if user.id == user_id and user.accesstoken == accesstoken: if data['new Password'] == data['confirm Password']: accesstoken = create_access_token(identity=user.id, fresh=True) hashed_value = generate_password_hash(data['new Password']) userModel.change(user_id, hashed_value) userModel.tokenUpdate1(user_id, accesstoken) return {"message": "password reset succesfully"} else: return {"message": "unmatched reset and confirm password"} else: return {"message": "access denied"} else: return {"message": "access denied"}
def identity( payload ): #The identity function takes the payload where payload is the content of the JWT token user_id = payload['identity'] return userModel.find_by_id(user_id)