Пример #1
0
		def request(self, request):

			# check overall rate limit.
			response = self.rate_limit.verify(ip=utils.get_client_ip(request), mode="daily", limit=1000, reset_minutes=3600*24, increment=True)
			if not response.success: 
				self.website.metrics.count_auth_request(request, data={
					"url":self.url,
					"response":response,
				})
				return self.response(response)

			# check signin rate limit.
			response = self.rate_limit.verify(ip=utils.get_client_ip(request), mode="signin", limit=10, reset_minutes=5, increment=True)
			if not response.success: 
				self.website.metrics.count_auth_request(request, data={
					"url":self.url,
					"response":response,
				})
				return self.response(response)

			# retrieve params.
			parameters, response = self.parameters.get(request, [
				"username",
				"password",])
			if not response.success: 
				self.website.metrics.count_auth_request(request, data={
					"url":self.url,
					"response":response,
				})
				return self.response(response)
			optional_parameters, _ = self.parameters.get(request, {
				"code":None,
			})

			# html
			html = ""
			if self._2fa:
				title = "Sign In - Verification Code"
				html = Files.load(f"{SOURCE_PATH}/classes/apps/authentication/mail/authentication.html")

			# make request.
			response = self.users.authenticate(
				username=parameters["username"],
				password=parameters["password"],
				_2fa_code=optional_parameters["code"],
				_2fa=self._2fa,
				html=html,
				request=request,)
			self.website.metrics.count_auth_request(request, data={
				"url":self.url,
				"response":response,
			})
			return self.response(response)
Пример #2
0
		def request(self, request):

			# check overall rate limit.
			response = self.rate_limit.verify(ip=utils.get_client_ip(request), mode="daily", limit=1000, reset_minutes=3600*24, increment=True)
			if not response.success: return self.response(response)

			# retrieve params.
			parameters, response = self.parameters.get(request, [
				"code",
				"email",
				"password",
				"verify_password",])
			if not response.success: return self.response(response)
			if parameters["email"] in ["undefined", "null", "None", "none", ""]:
				return self.error("Refresh the web page.")

			# make request.
			response = self.users.verify_code(
				email=parameters["email"],
				code=parameters["code"],
				mode="reset_password",)
			if not response.success: return self.response(response)

			# make request.
			response = self.users.update(
				email=parameters["email"], # for id.
				password=parameters["password"],
				verify_password=parameters["verify_password"],)
			if response.success: 
				response["message"] = f"Succesfully resetted the password of user [{user.email}]."
				_response_ = self.users.save_password(email=user.email, username=user.username, password=parameters["password"])
				if not _response_.success: return self.response(_response_)
			return self.response(response)
Пример #3
0
		def request(self, request):

			# check overall rate limit.
			response = self.rate_limit.verify(ip=utils.get_client_ip(request), mode="daily", limit=1000, reset_minutes=3600*24, increment=True)
			if not response.success: return self.response(response)

			# retrieve params.
			parameters, response = self.parameters.get(request, [
				"code",
				"email",])
			if not response.success: return self.response(response)
			if parameters["email"] in ["undefined", "null", "None", "none", ""]:
				return self.error("Refresh the web page.")

			# make request.
			response = self.users.verify_code(
				email=parameters["email"],
				code=parameters["code"],
				mode="activation",)
			if not response.success: return self.response(response)

			# make request.
			response = self.users.update(
				email=parameters["email"],
				email_verified=True,)
			if response.success: response["message"] = f"Succesfully activated the account user [{user.email}]."
			return self.response(response)
Пример #4
0
            def request(self, request):

                # check overall rate limit.
                response = self.rate_limit.verify(
                    ip=utils.get_client_ip(request),
                    mode="daily",
                    limit=1000,
                    reset_minutes=3600 * 24,
                    increment=True)
                if not response.success: return self.response(response)

                # check authenticated.
                response = self.users.authenticated(request)
                if not response.success: return self.response(response)
                email = response.email

                ###################
                # by subscription id.

                # get parameters.
                parameters, response = self.parameters.get(
                    request, [
                        "subscription_id",
                    ])
                if response.success:

                    # request.
                    return self.response(
                        self.stripe.subscriptions.cancel(
                            email=email,
                            subscription_id=parameters["subscription_id"],
                        ))

                ###################
                # by plan & product.
                else:

                    # get parameters.
                    parameters, response = self.parameters.get(
                        request, [
                            "product",
                            "plan",
                        ])
                    if not response.success: return self.response(response)

                    # convert plan.
                    response = self.stripe.get_plan_id(
                        product=parameters["product"], plan=parameters["plan"])
                    if not response.success: return self.response(response)
                    plan_id = response.id

                    # request.
                    return self.response(
                        self.stripe.subscriptions.cancel(
                            email=email,
                            plan=plan_id,
                        ))
Пример #5
0
		def request(self, request):

			# check overall rate limit.
			response = self.rate_limit.verify(ip=utils.get_client_ip(request), mode="daily", limit=1000, reset_minutes=3600*24, increment=True)
			if not response.success: return self.response(response)

			# check signup rate limit.
			response = self.rate_limit.verify(ip=utils.get_client_ip(request), mode="signup", limit=3, reset_minutes=3600*24, increment=False)
			if not response.success: return self.response(response)

			# retrieve params.
			parameters, response = self.parameters.get(request, [
				"username",
				"email",
				"password",
				"verify_password",])
			if not response.success: return self.response(response)
			optional_parameters, _ = self.parameters.get(request, {
				"name":None,
			})

			# make request.
			response = self.users.create(
				email=parameters["email"],
				username=parameters["username"],
				password=parameters["password"],
				verify_password=parameters["verify_password"],
				name=optional_parameters["name"],)
			if not response.success: return self.response(response)

			# increment.
			_response_ = self.rate_limit.increment(ip=utils.get_client_ip(request), mode="signup")
			if not _response_.success: return _response_


			# send activation code.
			_response_ = self.send_code.send_code(username=parameters["username"], mode="activation", request=request)
			if not _response_.success: return self.response(_response_)

			# return create response.
			if response.success:
				del response["user"]
			return self.response(response)
Пример #6
0
            def request(self, request):

                # check overall rate limit.
                response = self.rate_limit.verify(
                    ip=utils.get_client_ip(request),
                    mode="daily",
                    limit=1000,
                    reset_minutes=3600 * 24,
                    increment=True)
                if not response.success: return self.response(response)

                # check authenticated.
                response = self.users.authenticated(request)
                if not response.success: return self.response(response)
                email = response.email

                # get customer id.
                response = self.stripe.customers.get_id(email=email)
                if not response.success: return self.response(response)
                customer_id = response.id

                # list.
                response = self.stripe.subscriptions.get(email=email,
                                                         active_only=True)
                if not response.success: return self.response(response)
                subscriptions = response.subscriptions
                for plan_id in list(subscriptions.keys()):
                    response = self.stripe.get_product_id_by_plan_id(plan_id)
                    if not response.success: return self.response(response)
                    product_id = response.id
                    response = self.stripe.get_product_name(product_id)
                    if not response.success: return self.response(response)
                    product = response.name
                    response = self.stripe.get_plan_name(plan_id)
                    if not response.success: return self.response(response)
                    plan = response.name
                    subscriptions[plan_id]["product"] = product
                    subscriptions[plan_id]["plan"] = plan
                    subscriptions[plan_id][
                        "favicon"] = self.stripe.template_data["PRODUCTS"][
                            product][plan]["favicon"]
                    subscriptions[plan_id][
                        "price"] = self.stripe.template_data["PRODUCTS"][
                            product][plan]["price"]

                # request.
                return self.success(
                    f"Successfully listed {len(subscriptions)} active subscription(s).",
                    {
                        "subscriptions": subscriptions,
                    })
Пример #7
0
		def request(self, request):

			# check overall rate limit.
			response = self.rate_limit.verify(ip=utils.get_client_ip(request), mode="daily", limit=1000, reset_minutes=3600*24, increment=True)
			if not response.success: return self.response(response)

			# check 2fa rate limit.
			response = self.rate_limit.verify(ip=utils.get_client_ip(request), mode="2fa", limit=15, reset_minutes=3600, increment=True)
			if not response.success: return self.response(response)

			# retrieve params.
			parameters, response = self.parameters.get(request, [
				"username",
				"mode",])
			if not response.success: return self.response(response)
			if parameters["username"] in ["undefined", "null", "None", "none", ""]:
				return self.error("Refresh the web page.")

			# make request.
			return self.response(self.send_code(
				username=parameters["username"],
				mode=parameters['mode'],
				request=request,))
Пример #8
0
            def request(self, request):

                # check overall rate limit.
                response = self.rate_limit.verify(
                    ip=utils.get_client_ip(request),
                    mode="daily",
                    limit=1000,
                    reset_minutes=3600 * 24,
                    increment=True)
                if not response.success: return self.response(response)

                # check authenticated.
                response = self.users.authenticated(request)
                if not response.success: return self.response(response)
                email = response.email
                try:
                    api_key = response.api_key
                except:
                    api_key = None

                # get parameters.
                parameters, response = self.parameters.get(
                    request, [
                        "product",
                        "plan",
                        "card_name",
                        "card_number",
                        "card_expiration_month",
                        "card_expiration_year",
                        "card_cvc",
                    ])
                if not response.success: return self.response(response)

                # request.
                return self.response(
                    self.users.create_subscription(
                        email=email,
                        api_key=api_key,
                        product=parameters["product"],
                        plan=parameters["plan"],
                        card_name=parameters["card_name"],
                        card_number=parameters["card_number"],
                        card_cvc=parameters["card_cvc"],
                        card_expiration_month=parameters[
                            "card_expiration_month"],
                        card_expiration_year=parameters[
                            "card_expiration_year"],
                    ))
Пример #9
0
		def request(self, request):

			# check overall rate limit.
			response = self.rate_limit.verify(ip=utils.get_client_ip(request), mode="daily", limit=1000, reset_minutes=3600*24, increment=True)
			if not response.success: return self.response(response)

			# handler.
			try:
				email = request.user.email
			except AttributeError:
				email = None
			return self.success("Successfully checked if the user is authenticated.", {
				"authenticated":request.user.username != None and request.user.is_authenticated == True,
				"username":request.user.username,
				"email":email,
			})
Пример #10
0
            def request(self, request):

                # check overall rate limit.
                response = self.rate_limit.verify(
                    ip=utils.get_client_ip(request),
                    mode="daily",
                    limit=1000,
                    reset_minutes=3600 * 24,
                    increment=True)
                if not response.success: return self.response(response)

                # check authenticated.
                response = self.users.authenticated(request)
                if not response.success: return self.response(response)
                email = response.email

                # get parameters.
                parameters, response = self.parameters.get(
                    request, [
                        "number",
                        "month",
                        "year",
                        "cvc",
                    ])
                if not response.success: return self.response(response)

                # get customer id.
                response = self.stripe.customers.get_id(email=email)
                if not response.success: return self.response(response)
                customer_id = response.id

                # request.
                return self.response(
                    self.stripe.customers.create_card(
                        id=customer_id,
                        number=parameters["number"],
                        month=parameters["month"],
                        year=parameters["year"],
                        cvc=parameters["cvc"],
                    ))
Пример #11
0
		def send_code(self, username=None, mode=None, request=None):

			# check library.
			#if not Files.exists("templates/mail"): os.mkdir("templates/mail")
			#response = utils.__check_package_files__([
			#	["templates/mail/reset_password.html","w3bsite","/classes/requests/mail/reset_password.html"],
			#	["templates/mail/authentication.html","w3bsite","/classes/requests/mail/authentication.html"],
			#	["templates/mail/activation.html","w3bsite","/classes/requests/mail/activation.html"],
			#])
			#if not response.success: return response

			# set mode.
			code = Integer(0).generate(length=6)
			if mode == "reset_password":
				title = "Reset Password - Verification Code"
				path = f"{SOURCE_PATH}/classes/apps/authentication/mail/reset_password.html"
			elif mode == "authentication":
				title = "Sign In - Verification Code"
				path = f"{SOURCE_PATH}/classes/apps/authentication/mail/authentication.html"
			elif mode == "activation":
				title = "Account Activation - Verification Code"
				path = f"{SOURCE_PATH}/classes/apps/authentication/mail/activation.html"
			else:
				return dev0s.response.error("Selected an invalid mode.")

			# parse html.
			ip = utils.get_client_ip(request)
			html = Files.load(path)

			# make request.
			return self.users.send_code(
				username=username,
				mode=mode,
				ip=ip,
				code=code,
				html=html,
				title=title,)
Пример #12
0
            def request(self, request):

                # check overall rate limit.
                response = self.rate_limit.verify(
                    ip=utils.get_client_ip(request),
                    mode="daily",
                    limit=1000,
                    reset_minutes=3600 * 24,
                    increment=True)
                if not response.success: return self.response(response)

                # check authenticated.
                response = self.users.authenticated(request)
                if not response.success: return self.response(response)
                email = response.email

                # get customer id.
                response = self.stripe.customers.get_id(email=email)
                if not response.success: return self.response(response)
                customer_id = response.id

                # request.
                return self.response(
                    self.stripe.customers.get_cards(id=customer_id, ))