mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 17:06:17 +00:00
Converting api:user
This commit is contained in:
parent
5f1502d41d
commit
4dd8c28729
@ -23,7 +23,7 @@ from xml.etree import ElementTree
|
|||||||
import simplejson
|
import simplejson
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from web import app
|
from web import app, store
|
||||||
from managers.user import UserManager
|
from managers.user import UserManager
|
||||||
|
|
||||||
@app.before_request
|
@app.before_request
|
||||||
@ -58,7 +58,7 @@ def authorize():
|
|||||||
error = request.error_formatter(40, 'Unauthorized'), 401
|
error = request.error_formatter(40, 'Unauthorized'), 401
|
||||||
|
|
||||||
if request.authorization:
|
if request.authorization:
|
||||||
status, user = UserManager.try_auth(request.authorization.username, request.authorization.password)
|
status, user = UserManager.try_auth(store, request.authorization.username, request.authorization.password)
|
||||||
if status == UserManager.SUCCESS:
|
if status == UserManager.SUCCESS:
|
||||||
request.username = request.authorization.username
|
request.username = request.authorization.username
|
||||||
request.user = user
|
request.user = user
|
||||||
@ -68,7 +68,7 @@ def authorize():
|
|||||||
if not username or not password:
|
if not username or not password:
|
||||||
return error
|
return error
|
||||||
|
|
||||||
status, user = UserManager.try_auth(username, password)
|
status, user = UserManager.try_auth(store, username, password)
|
||||||
if status != UserManager.SUCCESS:
|
if status != UserManager.SUCCESS:
|
||||||
return error
|
return error
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ def get_entity(req, ent, param = 'id'):
|
|||||||
except:
|
except:
|
||||||
return False, req.error_formatter(0, 'Invalid %s id' % ent.__name__)
|
return False, req.error_formatter(0, 'Invalid %s id' % ent.__name__)
|
||||||
|
|
||||||
entity = ent.query.get(eid)
|
entity = store.get(ent, eid)
|
||||||
if not entity:
|
if not entity:
|
||||||
return False, (req.error_formatter(70, '%s not found' % ent.__name__), 404)
|
return False, (req.error_formatter(70, '%s not found' % ent.__name__), 404)
|
||||||
|
|
||||||
|
14
api/user.py
14
api/user.py
@ -19,7 +19,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from flask import request
|
from flask import request
|
||||||
from web import app
|
from web import app, store
|
||||||
from db import User
|
from db import User
|
||||||
from managers.user import UserManager
|
from managers.user import UserManager
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ def user_info():
|
|||||||
if username != request.username and not request.user.admin:
|
if username != request.username and not request.user.admin:
|
||||||
return request.error_formatter(50, 'Admin restricted')
|
return request.error_formatter(50, 'Admin restricted')
|
||||||
|
|
||||||
user = User.query.filter(User.name == username).first()
|
user = store.find(User, User.name == username).one()
|
||||||
if user is None:
|
if user is None:
|
||||||
return request.error_formatter(0, 'Unknown user')
|
return request.error_formatter(0, 'Unknown user')
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ def users_info():
|
|||||||
if not request.user.admin:
|
if not request.user.admin:
|
||||||
return request.error_formatter(50, 'Admin restricted')
|
return request.error_formatter(50, 'Admin restricted')
|
||||||
|
|
||||||
return request.formatter({ 'users': { 'user': [ u.as_subsonic_user() for u in User.query.all() ] } })
|
return request.formatter({ 'users': { 'user': [ u.as_subsonic_user() for u in store.find(User) ] } })
|
||||||
|
|
||||||
@app.route('/rest/createUser.view', methods = [ 'GET', 'POST' ])
|
@app.route('/rest/createUser.view', methods = [ 'GET', 'POST' ])
|
||||||
def user_add():
|
def user_add():
|
||||||
@ -55,7 +55,7 @@ def user_add():
|
|||||||
return request.error_formatter(10, 'Missing parameter')
|
return request.error_formatter(10, 'Missing parameter')
|
||||||
admin = True if admin in (True, 'True', 'true', 1, '1') else False
|
admin = True if admin in (True, 'True', 'true', 1, '1') else False
|
||||||
|
|
||||||
status = UserManager.add(username, password, email, admin)
|
status = UserManager.add(store, username, password, email, admin)
|
||||||
if status == UserManager.NAME_EXISTS:
|
if status == UserManager.NAME_EXISTS:
|
||||||
return request.error_formatter(0, 'There is already a user with that username')
|
return request.error_formatter(0, 'There is already a user with that username')
|
||||||
|
|
||||||
@ -67,11 +67,11 @@ def user_del():
|
|||||||
return request.error_formatter(50, 'Admin restricted')
|
return request.error_formatter(50, 'Admin restricted')
|
||||||
|
|
||||||
username = request.args.get('username')
|
username = request.args.get('username')
|
||||||
user = User.query.filter(User.name == username).first()
|
user = store.find(User, User.name == username).one()
|
||||||
if not user:
|
if not user:
|
||||||
return request.error_formatter(70, 'Unknown user')
|
return request.error_formatter(70, 'Unknown user')
|
||||||
|
|
||||||
status = UserManager.delete(user.id)
|
status = UserManager.delete(store, user.id)
|
||||||
if status != UserManager.SUCCESS:
|
if status != UserManager.SUCCESS:
|
||||||
return request.error_formatter(0, UserManager.error_str(status))
|
return request.error_formatter(0, UserManager.error_str(status))
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ def user_changepass():
|
|||||||
if username != request.username and not request.user.admin:
|
if username != request.username and not request.user.admin:
|
||||||
return request.error_formatter(50, 'Admin restricted')
|
return request.error_formatter(50, 'Admin restricted')
|
||||||
|
|
||||||
status = UserManager.change_password2(username, password)
|
status = UserManager.change_password2(store, username, password)
|
||||||
if status != UserManager.SUCCESS:
|
if status != UserManager.SUCCESS:
|
||||||
return request.error_formatter(0, UserManager.error_str(status))
|
return request.error_formatter(0, UserManager.error_str(status))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user