[973924]: / qiita_db / handlers / user.py

Download this file

53 lines (42 with data), 1.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -----------------------------------------------------------------------------
# Copyright (c) 2014--, The Qiita Development Team.
#
# Distributed under the terms of the BSD 3-clause License.
#
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------
import qiita_db as qdb
from .oauth2 import OauthBaseHandler, authenticate_oauth
from .util import _get_instance
class UserInfoDBHandler(OauthBaseHandler):
@authenticate_oauth
def get(self, email):
"""Retrieves the User information
Parameters
----------
email: str
The email of the user whose information is being retrieved
Returns
-------
dict
The user information as a dict
"""
with qdb.sql_connection.TRN:
user = _get_instance(qdb.user.User, email,
'Error instantiating user')
response = {'data': {'email': email, 'level': user.level,
'password': user.password,
'name': user.info['name']}}
self.write(response)
class UsersListDBHandler(OauthBaseHandler):
@authenticate_oauth
def get(self):
"""Retrieves the Users basic information
Returns
-------
list of dict
The user information as a dict
"""
with qdb.sql_connection.TRN:
response = {'data': [dict(d) for d in qdb.user.User.iter()]}
self.write(response)