Esempio n. 1
0
def login(request):
	response_json={}
	try:
		if(request.method=='POST'):
			fcm=str(request.POST.get('fcm'))
			name=str(request.POST.get('name'))
			mobile=str(request.POST.get('mobile'))
			otp=random.randint(100000,999999)
			msg='Hope you have a good health.You One Time Password is '+str(otp)
			send_sms(mobile,msg)
			print 'Otp Sent'
			try:
				otp_list=otp_data.objects.get(mobile=str(mobile))
		 		setattr(otp_list,'otp',int(otp))
		 		setattr(otp_list,'flag',False)
		 		setattr(otp_list,'fcm',fcm)
		 		otp_list.save()
				print 'old user'
				print 'User Details Updated'
		
			except Exception,e:
		 		otp_data.objects.create(mobile=str(mobile),otp=int(otp))
		 		user_data.objects.create(
					name=name,
					email=email,
					mobile=str(mobile)
					)
				print 'User Created'
				print e
			response_json['success']=True
			response_json['message']="Otp Sent Successfully"	
	except Exception, e:
		response_json['success']=False
		response_json['message']='Unable to send otp at this time'
Esempio n. 2
0
def send_otp(request):
    if request.method == 'POST':
        response_json = {}
        try:
            name = str(request.POST.get('name'))
            mobile = str(request.POST.get('mobile_no'))
            email = str(request.POST.get('email'))
            print(name)
            print(mobile)
            otp = random.randint(1000, 9999)
            msg = str(otp) + ' is the OTP for Spectrum App.'
            send_sms(mobile, msg)
            print('Otp Sent')
            try:
                # otp_list = OtpData.objects.create(mobile=str(mobile))
                # setattr(otp_list, 'otp', int(otp))
                # setattr(otp_list, 'flag', False)
                # otp_list.save()
                # print('old user')
                user_list = UserData.objects.get(mobile=str(mobile))
                setattr(user_list, 'name', name)
                setattr(user_list, 'email', email)
                user_list.save()
                print('User Details Updated')
                try:
                    otp_instance = OtpData.objects.get(mobile=str(mobile))
                    otp_instance.otp = otp
                    otp_instance.save()
                except Exception as e:
                    print(e)
                    OtpData.objects.create(mobile=str(mobile), otp=int(otp))
            except Exception as e:
                OtpData.objects.create(mobile=str(mobile), otp=int(otp))
                UserData.objects.create(name=name,
                                        email=email,
                                        mobile=str(mobile))
                print('User Created')
                print(e)
            response_json['success'] = True
            response_json['message'] = "Otp Sent Successfully"
            pass
        except Exception as e:
            response_json['success'] = False
            response_json['message'] = 'Unable to send otp at this time'
            print(e)
        print(str(response_json))
        return JsonResponse(response_json)
Esempio n. 3
0
def send_otp(request):
    if request.method == 'POST':
        response_json = {}
        try:
            name = str(request.POST.get('name'))
            mobile = str(request.POST.get('mobile'))
            email = str(request.POST.get('email'))
            print(name)
            print(mobile)
            print(email)
            otp = random.randint(100000, 999999)
            msg = 'Welcome to Discount-Store. You One Time Password is ' + str(otp)
            send_sms(mobile, msg)
            print('Otp Sent')
            try:
                otp_list = OtpData.objects.get(mobile=str(mobile))
                setattr(otp_list, 'otp', int(otp))
                setattr(otp_list, 'flag', False)
                otp_list.save()
                print('old user')
                user_list = UserData.objects.get(mobile=str(mobile))
                setattr(user_list, 'name', name)
                setattr(user_list, 'email', email)
                setattr(user_list, 'city', "")
                user_list.save()
                print('User Details Updated')

            except Exception as e:
                OtpData.objects.create(mobile=str(mobile), otp=int(otp))
                UserData.objects.create(
                    name=name,
                    email=email,
                    mobile=str(mobile)
                )
                print('User Created')
                print(e)
            response_json['success'] = True
            response_json['message'] = "Otp Sent Successfully"
            pass
        except Exception as e:
            response_json['success'] = False
            response_json['message'] = 'Unable to send otp at this time'
            print(e)
        print(str(response_json))
        return JsonResponse(response_json)
Esempio n. 4
0
def buy_offer(request):
    response_json = {}
    if request.method == 'POST':
        try:
            for x, y in request.POST.items():
                print(x, ":", y)
            access_token = request.POST.get('access_token')
            offer_id = request.POST.get('offer_id')
            json = jwt.decode(str(access_token), '999123', algorithms=['HS256'])
            print(json['mobile'])
            mobile = json['mobile']
            response_json["success"] = True
            response_json["message"] = 'Successful'
            user = UserData.objects.get(mobile=str(json['mobile']))
            wallet = user.wallet
            offer_details = OfferData.objects.get(id=int(offer_id))
            price = offer_details.price
            if wallet < price:
                response_json["success"] = False
                response_json[
                    "message"] = 'Transaction Unsuccessful, wallet does not have that amount of money. Please Add ' \
                                 'some Money in your Wallet '
            else:
                offer_code = code_generator()
                OfferBoughtData.objects.create(mobile=str(mobile), price=price, offer_id=offer_id,
                                               offer_code=offer_code, avialable=True)
                user.wallet = wallet - price
                user.save()
                shop_details = ShopData.objects.get(name=offer_details.shop_id)
                try:
                    msg = ' Thank you for using Discount Store. You have successfully bought the Offer " ' + str(
                        offer_details.name) + ' "" for Shop ' + str(shop_details.name) + '. Your Offer Code is  ' + str(
                        offer_code) + '. To Redeem the offer Please show this Message and Code During Billing.%0A ' \
                                      '%0AThanks Team Discount Store '
                    send_sms(mobile, msg)
                    send_sms('8109109457', msg)
                    send_sms('8519072717', msg)
                except Exception as e:
                    print(e)
                response_json["offer_name"] = offer_details.name
                response_json["price"] = offer_details.price
        except Exception as e:
            response_json["success"] = False
            response_json["message"] = "error in buyoffers"
            print(e)

    else:
        response_json['success'] = False
        response_json['message'] = "Get Out From Here"
    return JsonResponse(response_json)
Esempio n. 5
0
def create_shop(request):
    response_json = {}
    if request.method == 'POST':
        try:
            for x, y in request.GET.items():
                print(x, ":", y)
            name = str(request.POST.get('name'))
            mobile = str(request.POST.get('mobile'))
            password = str(request.POST.get('password'))
            description = str(request.POST.get('description'))
            address = str(request.POST.get('address'))
            category = str(request.POST.get('category'))
            city = str(request.POST.get('city'))

            try:
                image = request.FILES.get('image').name
                folder = 'media/' + 'shop/'
                full_filename = os.path.join(folder, image)
                print("full name", full_filename)
                # fout = open(folder+image, 'wb+')
                print("image=", image)
                fout = open(folder + image, 'w')
                file_content = request.FILES.get('image').read()
                # for chunk in file_content.chunks():
                fout.write(file_content)
                fout.close()
            except Exception as e:
                image = 'image'
                print(e)
            image = request.FILES['image']

            # print("Hashed password is:", make_password(password))
            print(name, mobile, type(image), image)

            try:
                category_instance = CategoryData.objects.get(name=category)
                city_instance = CityData.objects.get(name=city)

                if ShopData.objects.filter(mobile=str(mobile)).count() > 0:
                    print("Shop already exist")
                    response_json['success'] = False
                    response_json['message'] = "Shop already exists"
                else:
                    print("New shop")

                    shop_instance = ShopData.objects.create(
                        name=name,
                        mobile=str(mobile),
                        password=str(password),
                        description=description,
                        address=address,
                        category_id=category_instance,
                        city_id=city_instance,
                        image=image)
                    print('User Created')

                    otp = random.randint(1000, 9999)
                    msg = 'Welcome to Discount Store. You One Time Password is ' + str(
                        otp)
                    send_sms(mobile, msg)

                    try:
                        otp_list = ShopOtpData.objects.get(
                            shop_id=shop_instance)

                        if otp_list.count() == 1:
                            setattr(otp_list, 'otp', int(otp))
                            setattr(otp_list, 'flag', False)
                            otp_list.save()
                            print('old user')
                        else:
                            ShopOtpData.objects.create(shop_id=shop_instance,
                                                       otp=int(otp))

                    except Exception as e:
                        ShopOtpData.objects.create(shop_id=shop_instance,
                                                   otp=int(otp))
                        print("Otp data does not exist, Creating it")

                    response_json['success'] = True
                    response_json['message'] = "Otp Sent Successfully"

            except Exception as e:
                response_json['success'] = False
                response_json['message'] = 'Unable to send otp at this time'
                print(e)
            print(str(response_json))
        except Exception as e:
            response_json['success'] = False
            response_json['message'] = 'Something went wrong'
            print(e)
    else:
        response_json['success'] = False
        response_json['message'] = "Invalid request"
    return JsonResponse(response_json)