def user_register(request): username = request.POST.get('username') password = request.POST.get('password') first_name = request.POST.get('first_name') last_name = request.POST.get('last_name') state = request.POST.get('state') city = request.POST.get('city') address = request.POST.get('address') contact = request.POST.get('contact') weight = request.POST.get('weight') gender = request.POST.get('gender') user = get_or_none(User, username=username) assert_true(user != None, "Account with this username already exists") user_obj = User.objects.create_user(username=username, password=password) user_obj.save() user_detail_obj = UserDetail.objects.create(username=user_obj, first_name=first_name, last_name=last_name, state=state, city=city, address=address, contact=contact, weight=weight, gender=gender) user_detail_obj.save() response = {} response['success'] = False reponse['data'] = get_model_json(user_detail_obj) return respond(reponse)
def register(request): response = {} data = json.loads(request.body) username = data['username'] password = data['password'] first_name = data['first_name'] last_name = data['last_name'] user_type = data['user_type'] contact = data['contact'] email = data['email'] latitude = data['latitude'] longitude = data['longitude'] fcm_token = data['fcm_token'] user = get_or_none(User, username = username) # assert_true(user != None, "User with username already exists") if user is not None: response['success'] = False response['message'] = "User with username already exists" return respond(response) user_obj = User.objects.create(username = username, password = password) user_obj.save() user_detail_obj = UserDetail.objects.create(user = user_obj, first_name = first_name, last_name = last_name, user_type = user_type, contact = contact, email = email, latitude = latitude, longitude = longitude) user_detail_obj.save() #Fcm register device = FcmModel.objects.create(user = user_detail_obj, token = fcm_token, contact = contact) device.save() response['success'] = True response['message'] = "Registration completed" return respond(response)
def hospital_register(request): username = request.POST.get('username') password = request.POST.get('password') name = request.POST.get('name') state = request.POST.get('state') city = request.POST.get('city') address = request.POST.get('address') contact = request.POST.get('contact') latitude = request.POST.get('latitude') longitude = request.POST.get('longitude') hospital = get_or_none(User, username=username) assert_true(hospital != None, "Account with this username already exists") hospital_user_obj = User.objects.create_user(username=username, password=password) hospital_user_obj.save() hospital_obj = Hospital.objects.create(username=hospital_user_obj, name=name, state=state, city=city, address=address, contact=contact) hospital_obj.save() for a, b in BLOOD_GROUP: blood_bank_obj = BloodBankStock.objects.create(hospital=hospital_obj, blood_group=b) blood_bank_obj.save() response = {} response['success'] = False reponse['data'] = get_model_json(hospital_obj) return respond(reponse)
def upload_product(request): data = json.loads(request.body) token = request.META.get('token') user = get_user(token) merchant_obj = get_or_none(Merchant, user__user=user) assert_found(merchant_obj, "No merchant object found") name = data['name'] product_type = data['product_type'] price = data['price'] quantity = data['quantity'] quantity_type = data['quantity_type'] # image = request.FILES.get('product_image') product_obj = Product.objects.create(merchant=merchant_obj, name=name, product_type=product_type, price=price, quantity=quantity, quantity_type=quantity_type) product_obj.save() response = {} response['success'] = True response['message'] = "Product uploaded successfully" response['details'] = get_model_json(product_obj) return respond(response)
def user_hospital_login(request): username = request.POST.get('username') password = request.POST.get('password') user = get_or_none(User, username=username) assert_found(user, "Account with username not found") response = {} if user.check_password(password): response['success'] = True response['token'] = generate_token(user) return respond(reponse) response['success'] = False response['message'] = "Invalid Credentials" return respond(response)
def login(request): data = json.loads(request.body) username = data['username'] password = data['password'] user = get_or_none(User, username = username) assert_found(user, "Account with username not found") response = {} if user.check_password(password): response['success'] = True response['token'] = generate_token(user) response['role'] = user.user_type return respond(response) response['success'] = False response['message'] = "Invalid Credentials" return respond(response)
def register_merchant(request): data = json.loads(request.body) token = request.META.get("token") user = get_user(token) name = data['name'] email = data['email'] address = data['address'] contact = data['contact'] user_detail_object = get_or_none(UserDetail, user = user) assert_found(user_detail_object, "No user detail object found") merchant_obj = Merchant.objects.create(user = user_detail_object, name = name, email = email, address = address, contact = contact) merchant_obj.save() response = {} response['success'] = True response['message'] = "Merchant created successfully" response['details'] = get_model_json(merchant_obj) return respond(response)
def get_user(token): user = get_or_none(User, username=get_token_data(token)['user']['username']) assert_found(user, "No user found") return user