Skip to content

Commit 0ff101d

Browse files
committed
fix
1 parent aba6489 commit 0ff101d

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

app/http/api/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ async def signin(request: Request):
1818
user = await request.json()
1919
result = authenticate(user['username'], user['password'])
2020
if result is True:
21-
token = slurm_auth.makejwt(user['username'])
2221
isadmin = isAdmin(user['username'], token)
22+
token = slurm_auth.makejwt(user['username'], isadmin)
2323
return {'success': True, 'token': token, 'userinfos': {'username': user['username'], 'name': user['username'], "isAdmin": isadmin}}
2424
else:
2525
return JSONResponse({"status": 'error', 'message': 'Invalid username or password'}, status_code=403)

slurm/slurm_auth.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ def add_slurm_header(request: Request):
3535
)
3636

3737

38-
def makejwt(username):
38+
def makejwt(username, isadmin):
3939
message = {
4040
"exp": int(time.time() + 604800),
4141
"iat": int(time.time()),
4242
"sun": username,
43-
"name": username
43+
"name": username,
44+
"isAdmin": isadmin
4445
}
4546
compact_jws = a.encode(message, signing_key, algorithm="HS256")
4647
return compact_jws

slurm/slurm_operation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
def updateUser(username, groups):
1010
session = requests.Session()
11-
newToken = slurm_auth.makejwt("root")
11+
newToken = slurm_auth.makejwt("root", True)
1212
headers = {
1313
"Content-type": "application/json",
1414
"X-SLURM-USER-NAME": "root",
@@ -68,7 +68,7 @@ def updateUser(username, groups):
6868

6969
def updateUsers(userGroups: list):
7070
session = requests.Session()
71-
newToken = slurm_auth.makejwt("root")
71+
newToken = slurm_auth.makejwt("root", True)
7272
headers = {
7373
"Content-type": "application/json",
7474
"X-SLURM-USER-NAME": "root",
@@ -131,7 +131,7 @@ def updateUsers(userGroups: list):
131131

132132
def updateGroup(name, desc, org="opencsg"):
133133
session = requests.Session()
134-
newToken = slurm_auth.makejwt("root")
134+
newToken = slurm_auth.makejwt("root", True)
135135
headers = {
136136
"Content-type": "application/json",
137137
"X-SLURM-USER-NAME": "root",
@@ -162,7 +162,7 @@ def updateGroup(name, desc, org="opencsg"):
162162

163163
def assignUsersToGroup(message):
164164
session = requests.Session()
165-
newToken = slurm_auth.makejwt("root")
165+
newToken = slurm_auth.makejwt("root", True)
166166
headers = {
167167
"Content-type": "application/json",
168168
"X-SLURM-USER-NAME": "root",

0 commit comments

Comments
 (0)