def post(self): userJson = GetCurrentUserDetails.get(self) getUser = userJson[0] print(getUser['userName']) checkUser = VolunteerModel.find_by_username(getUser['userName']) if not checkUser.id == 1: return {'message': 'You are not admin user'}, 400 data = _city_parser.parse_args() check_cityEntry = IndiaCitiesStates.find_by_city(str(data['cities_states']).title().strip()) if check_cityEntry: return {'message': f'{data["cities_states"]} already in database'}, 400 try: newCity = IndiaCitiesStates( str(data['cities_states']).title().strip() ) newCity.save_to_db() return {'message': 'City added successfully'}, 200 except Exception as e: print(f'Error while adding city {e}') return {'message': 'Internal server error'}, 500
def put(self, status): getuserjson = GetCurrentUserDetails.get(self) getuser = getuserjson[0] checkUser = VolunteerModel.find_by_username(getuser['userName']) if not checkUser: return {'message': 'User not found'}, 400 if status.isnumeric(): print('true, Is numeric') statusNow = int(status) try: if checkUser.keep_private == str(statusNow): return {'message': 'No changes made'}, 400 checkUser.keep_private = str(statusNow) checkUser.save_to_db() return {'message': 'Profile update successfully'}, 200 except Exception as e: print(f'Error while updating profile status {e}'), 500 return {'message': 'Something went wrong'}, 500 else: print('False, Is not numeric') return {'message': 'Error'}, 400
def post(self): userJson = GetCurrentUserDetails.get(self) getUser = userJson[0] print(getUser['userName']) checkUser = VolunteerModel.find_by_username(getUser['userName']) if not checkUser.id == 1: return {'message': 'You are not admin user'}, 400 data = _service_parser.parse_args() check_ExistingCategory = ServiceTypeCategories.find_by_service( str(data['service_category']).title().strip()) if check_ExistingCategory: return {'message': 'This category already in database'}, 400 try: newCategory = ServiceTypeCategories( str(data['service_category']).title().strip()) newCategory.save_to_db() return {'message': 'Category added successfully'}, 200 except Exception as e: print(f'Error while adding category {e}') return {'message': 'Internal server error'}, 500
def post(self): check_username = VolunteerModel.find_by_username(get_jwt_identity()) if not check_username: return {'message': 'Unauthorized'}, 401 identity = get_jwt_identity() access_token = create_access_token(identity=identity, fresh=True) return {'access_token': access_token}, 200
def get(self): check_username = VolunteerModel.find_by_username(get_jwt_identity()) if not check_username: return {'userName': '******'}, 400 if check_username.is_active != '1': return {'userName': '******'}, 400 current_user_customer = get_jwt_identity() return {'userName': current_user_customer}, 200
def get(self, username): checkUser = VolunteerModel.find_by_username( str(username).lower().strip()) if not checkUser: return {'message': 'Requested volunteer not found'}, 400 if checkUser.keep_private == '1': return { 'name': checkUser.volunteer_name, 'contactinfo': 'Private' }, 200 return { 'name': checkUser.volunteer_name, 'contactinfo': checkUser.volunteer_emailAddress }, 200
def post(self): _customer_login = reqparse.RequestParser() _customer_login.add_argument('AppLoginPassword', type=str, required=False) # covidHelp _customer_login.add_argument('username', type=str, required=True, help='Username is required') _customer_login.add_argument('password', type=str, required=True, help='Password is required') data = _customer_login.parse_args() if data['AppLoginPassword'] != 'covidHelp': return {'message': 'Request from unknown source'}, 400 check_username = VolunteerModel.find_by_username( str(data['username']).lower().strip()) if check_username: if check_username.is_active != '1': return {'message': 'Your account disabled by admin'}, 400 if check_username and safe_str_cmp(check_username.password, data['password']): access_token = create_access_token( identity=check_username.volunteer_username, fresh=True) refresh_token = create_refresh_token( check_username.volunteer_username) return { 'access_token': access_token, 'refresh_token': refresh_token }, 200 return {'message': 'Invalid credentials'}, 401 return {'message': 'Invalid credentials'}, 401
def post(self): data = _volunteer_parser.parse_args() if data['AppLoginPassword'] != 'covidApp': return {'message': 'Request from unknown source'}, 400 # length error if len(data['volunteer_name']) > 16: return {'message': 'Name character exceeds'}, 400 if len(data['volunteer_username']) > 16: return {'message': 'Username character exceeds'}, 400 if len(data['volunteer_contact']) > 15: return {'message': 'Contact character exceeds'}, 400 if len(data['volunteer_contact']) > 15: return {'message': 'Contact character exceeds'}, 400 if len(data['volunteer_emailAddress']) > 30: return {'message': 'Email address character exceeds'}, 400 if len(data['password']) > 15: return {'message': 'Email address character exceeds'}, 400 if len(data['keep_private']) > 2: return {'message': 'Is private character exceeds'}, 400 if len(data['volunteer_name']) < 5: return { 'message': 'Name length must be five or more than five character' }, 400 if len(data['password']) < 6: return { 'message': 'Password length must be six or more than six character' }, 400 if " " in data['volunteer_username']: return { 'message': 'please enter single character in username' }, 400 regex_username = re.compile('[@_!#$%^&*()<>?/\|}{~:]') if not regex_username.search(data['volunteer_name']) is None: return { 'message': 'Special character not accepted in username' }, 400 regex_email = '^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$' if str(data['volunteer_emailAddress']).lower().strip() != '': if not re.search( regex_email, str(data['volunteer_emailAddress']).lower().strip()): return { 'message': 'Email id seems invalid, please check it!' }, 400 if str(data['volunteer_name']).strip() == '': return {'message': 'Name can\'t be empty'}, 400 if str(data['volunteer_username']).strip() == '': return {'message': 'Username can\'t be empty'}, 400 if str(data['password']).strip() == '': return {'message': 'Password can\'t be empty'}, 400 # password checks if str(data['password']) != str(data['confirm_password']): return { 'message': 'Password and confirm password not matching' }, 400 if VolunteerModel.find_by_username( str(data['volunteer_username']).lower().strip()): return { 'message': f'{data["volunteer_username"]} username already taken' }, 400 try: newVolunteer = VolunteerModel( str(data['volunteer_name']).title().strip(), str(data['volunteer_username']).lower().strip(), str(data['password']).strip(), str(data['volunteer_contact']).strip(), str(data['volunteer_emailAddress']).lower().strip(), str(data['keep_private']).strip(), '1') newVolunteer.save_to_db() try: url = "https://api.sendinblue.com/v3/smtp/email" payload = { "sender": { "name": "CoviRescue", "email": "*****@*****.**" }, "to": [{ "email": str(data['volunteer_emailAddress']).strip().lower(), "name": str(data['volunteer_name']).title().strip() }], "textContent": f'''Hello {str(data["volunteer_name"]).title().strip()} !,\nThanks for joining us on CoviRescue Platform as a Volunteer, Please remember your credentials\nUsername - {str(data['volunteer_username']).lower().strip()}\nPassword - {str(data['password']).strip()}\n\nShare this app as much you can so needy people can get the required service easily\n\nThanks\nTeam Kaizen Innovations''', "subject": "Welcome to CoviRescue!" } headers = { "Accept": "application/json", "Content-Type": "application/json", "api-key": sendInBlueEmailKey } email_response = requests.request("POST", url, json=payload, headers=headers) print(email_response.text) if email_response.status_code == 201: print('Email sent successfully') except Exception as e: print(f'Error in sending registration email {e}') return {'message': 'registered successfully'}, 200 except Exception as e: print(f'Error while registering new volunteer {e}') return {'message': 'Internal server error'}, 500