Skip to content

Commit

Permalink
Nologin (modelscope#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
rayrayraykk authored Sep 11, 2024
1 parent f2a609e commit d3186c4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/agentscope/studio/_app_online.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import ipaddress
import json
import os
import uuid
import time
import secrets
import tempfile
from typing import Tuple, Any
Expand Down Expand Up @@ -196,6 +198,22 @@ def _home() -> str:
return render_template("login.html", client_id=CLIENT_ID, ip=IP, port=PORT)


@_app.route("/login_as_guest")
def login_as_guest() -> str:
"""Render the workstation page without login."""
user_login = f"guest_{uuid.uuid4().hex}_{int(time.time())}"
session["verification_token"] = generate_verification_token()
session["user_login"] = user_login
session["jwt_token"] = generate_jwt(
user_login=user_login,
access_token="access_token",
verification_token=session["verification_token"],
secret_key=SECRET_KEY,
version="online",
)
return redirect(url_for("_workstation_online"))


@_app.route("/logout")
def logout() -> str:
"""
Expand All @@ -208,7 +226,7 @@ def logout() -> str:
@_app.route("/oauth/callback")
def oauth_callback() -> str:
"""
Github oauth callback.
GitHub oauth callback.
"""
code = request.args.get("code")
if not code:
Expand Down
32 changes: 32 additions & 0 deletions src/agentscope/studio/static/css/login.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,38 @@ body {
cursor: not-allowed;
}

#loginGuestButton {
color: #a0a0a0;
font-size: 12px;
padding: 5px 8px;
cursor: pointer;
box-shadow: none;
transition: transform 0.2s;
margin-top: 0.5rem;
display: inline-block;
width: auto;
background: none;
border: none;
text-decoration: underline;
}

#loginGuestButton:hover {
transform: scale(1.01);
text-decoration: underline;
}

#loginGuestButton:active {
transform: scale(1);
text-decoration: underline;
}

#loginGuestButton:disabled {
color: #d3d3d3;
cursor: not-allowed;
text-decoration: none;
transform: none;
}

.terms {
background: #fff;
padding: 20px;
Expand Down
16 changes: 16 additions & 0 deletions src/agentscope/studio/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ <h4>{{ _("Please log in and star the AgentScope repository") }}.</h4>
<button onclick="redirectToGitHub()" disabled
id="loginButton">{{ _("Login with GitHub") }}
</button>
<button onclick="loginAsGuest()" disabled
id="loginGuestButton">{{ _("Login as Guest") }}
</button>
<br><br>

<div id="loaderContainer" class="waiting" style="display: none;">
Expand All @@ -95,6 +98,8 @@ <h3>{{ _("We want to hear from you") }}</h3>
const checkBox = document.getElementById('agreeTerms');
const loginButton = document.getElementById('loginButton');
loginButton.disabled = !checkBox.checked;
const loginGuestButton = document.getElementById('loginGuestButton');
loginGuestButton.disabled = !checkBox.checked;
}

function showLoader() {
Expand Down Expand Up @@ -128,6 +133,17 @@ <h3>{{ _("We want to hear from you") }}</h3>
}, 500);
}

function loginAsGuest() {
showLoader();
setTimeout(() => {
const ip = "{{ ip }}";
const port = "{{ port }}";
let address;
address = `http://${ip}:${port}/login_as_guest`
window.location.href = address;
}, 500);
}

document.addEventListener("DOMContentLoaded", function () {
window.addEventListener("pageshow", function (event) {
if (event.persisted) {
Expand Down

0 comments on commit d3186c4

Please sign in to comment.