Skip to content

Commit

Permalink
处理protocol与host信息
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryJi529 committed Jun 5, 2024
1 parent b11c2fc commit 000e39e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 22 deletions.
8 changes: 1 addition & 7 deletions Morningstar/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@ def create_activate_message(username, host):
except:
pass
conn.set(f"{username}-activate", code, ex=60 * 10)

protocol = (
"https://"
if os.environ.get("DJANGO_SETTINGS_MODULE", "Morningstar.settings.dev")
== "Morningstar.settings.production"
else "http://"
)
protocol = "https://" if request.is_secure() else "http://"
link = (
protocol
+ host
Expand Down
7 changes: 1 addition & 6 deletions Morningstar/views/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,7 @@ def get_login_token(request: HttpRequest, identity):
username = user.username
password = user.password
token = html.escape(password[-20:])
protocol = (
"https://"
if os.environ.get("DJANGO_SETTINGS_MODULE", "Morningstar.settings.dev")
== "Morningstar.settings.production"
else "http://"
)
protocol = "https://" if request.is_secure() else "http://"
link = (
protocol
+ request.get_host()
Expand Down
9 changes: 3 additions & 6 deletions apps/share/frontend/src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import Cookies from 'js-cookie'
const route = useRoute()
const BASE_URL = process.env.BASE_URL
const currentPath = ref(window.location.href)
const endpoint = "/submit/"
const url = ref("") // NOTE: 提交的信息
const link = ref("") // NOTE: 返回的加密链接
Expand All @@ -24,7 +21,7 @@ const handleSubmit = async ()=>{
return
}
const response = await axios.post(endpoint,{
const response = await axios.post("/submit/",{
"url": url.value,
})
Expand All @@ -47,8 +44,8 @@ const handleSubmit = async ()=>{
</div>
<div v-else class="max-w-[100vw] overflow-hidden p-4">
<div class="text-base md:text-2xl my-10 text-lime-600 break-words">
<a :href="`${currentPath}${link}`">
{{ currentPath + link }}
<a :href="`${link}`">
{{ link }}
</a>
</div>
<div class="flex justify-center">
Expand Down
6 changes: 3 additions & 3 deletions apps/share/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def submit(request: HttpRequest):
if request.method == "POST":
item = Item(url=request.data["url"])
item.save()
id = item.id
link = f"redirect/{id}/"
request.session["share-qrcode"] = "https://morningstar369.com/share/" + link
protocol = "https://" if request.is_secure() else "http://"
link = protocol + request.META["HTTP_HOST"] + f"/share/redirect/{item.id}/"
request.session["share-qrcode"] = link
return Response({"link": link})

0 comments on commit 000e39e

Please sign in to comment.