Skip to content

Commit

Permalink
revise for user logout
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyongliang committed Mar 12, 2023
1 parent 547cc76 commit 719eb1e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
18 changes: 18 additions & 0 deletions javascript/ui.js
Expand Up @@ -228,4 +228,22 @@ function login(username) {
train.style.display=(username=='admin'?'none':'block')
user.style.display=(username=='admin'?'block':'none')
extension.style.display=(username=='admin'?'none':'block')
}

function logout() {
var txt2img=gradioApp().querySelector('#tabs').querySelectorAll('button')[0];
var img2img=gradioApp().querySelector('#tabs').querySelectorAll('button')[1];
var extras=gradioApp().querySelector('#tabs').querySelectorAll('button')[2];
var pnginfo=gradioApp().querySelector('#tabs').querySelectorAll('button')[3];
var train=gradioApp().querySelector('#tabs').querySelectorAll('button')[4];
var user=gradioApp().querySelector('#tabs').querySelectorAll('button')[5];
var extension=gradioApp().querySelector('#tabs').querySelectorAll('button')[6];

txt2img.style.display='none'
img2img.style.display='none'
extras.style.display='none'
pnginfo.style.display='none'
train.style.display='none'
user.style.display='block'
extension.style.display='none'
}
2 changes: 2 additions & 0 deletions localizations/zh_CN.json
Expand Up @@ -644,6 +644,8 @@
"Settings saved failed": "设置保存错误",
"Settings changed without save": "设置变更但未保存",
"Settings changed and saved": "设置变更并保存",
"Logout": "登出",
"You have been logout, please refresh page manaully...": "您已登出,请手动刷新页面...",
"SageMaker endpoint": "SageMaker 端点",
"User": "用户",
"Model": "模型",
Expand Down
2 changes: 2 additions & 0 deletions localizations/zh_TW.json
Expand Up @@ -638,6 +638,8 @@
"Settings saved failed": "設置保存錯誤",
"Settings changed without save": "設置變更但未保存",
"Settings changed and saved": "設置變更並保存",
"Logout": "登出",
"You have been logout, please refresh page manaully...": "您已登出,请手动刷新页面...",
"SageMaker endpoint": "SageMaker 端點",
"User": "使用者",
"Model": "模型",
Expand Down
26 changes: 25 additions & 1 deletion modules/ui.py
Expand Up @@ -842,7 +842,31 @@ def run_settings_single(value, key, request : gr.Request):
with gr.Blocks(analytics_enabled=False) as settings_interface:
dummy_component = gr.Label(visible=False)

settings_submit = gr.Button(value="Apply settings", variant='primary')
with gr.Row():
settings_submit = gr.Button(value="Apply settings", variant='primary')
settings_logout = gr.Button(value="Logout")
logout_prompt = gr.HTML(value="<strong>You have been logout, please refresh page manaully...</strong>", visible=False)

def user_logout(request: gr.Request):
tokens = shared.demo.server_app.tokens
cookies = request.headers['cookie'].split('; ')
access_token = None
for cookie in cookies:
if cookie.startswith('access-token'):
access_token = cookie[len('access-token=') : ]
print(access_token)
tokens.pop(access_token)
print(tokens)
break
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)

settings_logout.click(
fn=user_logout,
inputs=[],
outputs=[settings_submit, settings_logout, logout_prompt],
_fs="logout"
)

result = gr.HTML()

settings_cols = 3
Expand Down

0 comments on commit 719eb1e

Please sign in to comment.