reyserver 1.1.51__py3-none-any.whl → 1.1.52__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
reyserver/rauth.py CHANGED
@@ -9,11 +9,12 @@
9
9
  """
10
10
 
11
11
 
12
- from typing import Literal
12
+ from typing import Any, Literal
13
+ from datetime import datetime as Datetime
13
14
  from fastapi import APIRouter
14
15
  from reydb import rorm, DatabaseEngine, DatabaseEngineAsync
15
- # from reykit.rdata import encode_jwt, is_hash_bcrypt
16
- # from reykit.rtime import now
16
+ from reykit.rdata import encode_jwt, is_hash_bcrypt
17
+ from reykit.rtime import now, time_to
17
18
 
18
19
  from .rbase import ServerConfig, Bind, exit_api
19
20
 
@@ -263,41 +264,39 @@ async def create_sessions(
263
264
  " SELECT `perm_id`, `name`, CONCAT(`method`, ':', `path`) as `api`\n"
264
265
  ' FROM `test`.`perm`\n'
265
266
  ') AS `perm`\n'
266
- 'ON `role_perm`.`perm_id` = `perm`.`perm_id`'
267
+ 'ON `role_perm`.`perm_id` = `perm`.`perm_id`\n'
268
+ 'GROUP BY `user_id`'
267
269
  )
268
- print(1111111111111)
269
270
  result = await conn.execute(
270
271
  sql,
271
272
  account=account
272
273
  )
273
- print(result.fetchall())
274
- return {'message': 'ok'}
275
-
276
- # # Check.
277
- # table = result.to_table()
278
- # print(table)
279
- # if table == []:
280
- # exit_api(401)
281
- # json = table[0]
282
- # if not is_hash_bcrypt(password, json['password']):
283
- # exit_api(401)
284
-
285
- # # JWT.
286
- # now_timestamp_s = now('timestamp_s')
287
- # json['sub'] = json.pop('user_id')
288
- # json['iat'] = now_timestamp_s
289
- # json['nbf'] = now_timestamp_s
290
- # json['exp'] = now_timestamp_s + sess_seconds
291
- # json['role_names'] = json['role_names'].split(';')
292
- # json['perm_names'] = json['perm_names'].split(';')
293
- # perm_apis: list[str] = json['perm_apis'].split(';')
294
- # perm_api_dict = {}
295
- # for perm_api in perm_apis:
296
- # for method, path in perm_api.split(':', 1):
297
- # paths: list = perm_api_dict.setdefault(method, [])
298
- # paths.append(path)
299
- # json['perm_apis'] = perm_api_dict
300
- # token = encode_jwt(json, key)
301
- # data = {'token': token}
302
- # print(111111, data)
303
- # return data
274
+
275
+ # Check.
276
+ if result.empty:
277
+ exit_api(401)
278
+ json: dict[str, Datetime | Any] = result.to_row()
279
+ if not is_hash_bcrypt(password, json['password']):
280
+ exit_api(401)
281
+
282
+ # JWT.
283
+ now_timestamp_s = now('timestamp_s')
284
+ json['sub'] = json.pop('user_id')
285
+ json['iat'] = now_timestamp_s
286
+ json['nbf'] = now_timestamp_s
287
+ json['exp'] = now_timestamp_s + sess_seconds
288
+ json['role_names'] = json['role_names'].split(';')
289
+ json['perm_names'] = json['perm_names'].split(';')
290
+ perm_apis: list[str] = json['perm_apis'].split(';')
291
+ perm_api_dict = {}
292
+ for perm_api in perm_apis:
293
+ method, path = perm_api.split(':', 1)
294
+ paths: list = perm_api_dict.setdefault(method, [])
295
+ paths.append(path)
296
+ json['perm_apis'] = perm_api_dict
297
+ json['create_time'] = json['create_time'].timestamp()
298
+ json['update_time'] = json['update_time'].timestamp()
299
+ token = encode_jwt(json, key)
300
+ data = {'token': token}
301
+
302
+ return data
reyserver/rserver.py CHANGED
@@ -138,7 +138,10 @@ class Server(ServerBase, Singleton):
138
138
  response = await call_next(request)
139
139
 
140
140
  # After.
141
- if request.method == 'POST':
141
+ if (
142
+ response.status_code == 200
143
+ and request.method == 'POST'
144
+ ):
142
145
  response.status_code = 201
143
146
 
144
147
  return response
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reyserver
3
- Version: 1.1.51
3
+ Version: 1.1.52
4
4
  Summary: Backend server method set.
5
5
  Project-URL: homepage, https://github.com/reyxbo/reyserver/
6
6
  Author-email: Rey <reyxbo@163.com>
@@ -1,11 +1,11 @@
1
1
  reyserver/__init__.py,sha256=7GX64p7uI2eetJH9NJ-DTg-8iyQwOsGcviADFJCPxVA,373
2
2
  reyserver/rall.py,sha256=riyDRTUsigco_Bee1H4aZFb8IgvjnxdX9qcnVb9i9mE,270
3
- reyserver/rauth.py,sha256=T2oafUAmXr4WfVYmEHO5v0j9K703KUYLGNVEom0J76Q,11716
3
+ reyserver/rauth.py,sha256=oa6Iwuutcj9eO6RH7DaT-rPn_YqYwKuyHYaBd3lZoZE,11728
4
4
  reyserver/rbase.py,sha256=xgdLP_O77e-pSrRWm9GVSziPSqEOh2w20cWkF4HBeWo,7042
5
5
  reyserver/rclient.py,sha256=IWZ3smyIP0_YJrfSrM8JFCr0FCtN02AyT3hp8YuSsDQ,5103
6
6
  reyserver/rfile.py,sha256=bvuXOYO3UDM1jMiyNzQDz56_0ekZUEIRcfNFAhGgdUY,9010
7
- reyserver/rserver.py,sha256=gOvLfaLqiDgHcZbzd3h2iIaDtraCuBcmsy1d61TaJ2c,6717
8
- reyserver-1.1.51.dist-info/METADATA,sha256=F4eENaUB_2lE1aEeV4ZZ_W7AHW7iB6NfPuTsR1fy-8U,1689
9
- reyserver-1.1.51.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
- reyserver-1.1.51.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
11
- reyserver-1.1.51.dist-info/RECORD,,
7
+ reyserver/rserver.py,sha256=bfakJGhcHF0CIiAmRyMVOURLbPNCIALGyrnKpf_Yi80,6800
8
+ reyserver-1.1.52.dist-info/METADATA,sha256=ujWE6YB95IdJf4nCYtq7FZW2sw0s_TGSeyuEwAjfHW8,1689
9
+ reyserver-1.1.52.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
+ reyserver-1.1.52.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
11
+ reyserver-1.1.52.dist-info/RECORD,,