|
@@ -6,11 +6,6 @@ import typing as typing
|
6
|
6
|
|
7
|
7
|
from tracim.models.auth import User
|
8
|
8
|
|
9
|
|
-# TODO - G.M -28-03-2018 - [CurrentUser][auth]
|
10
|
|
-# Check if "current user" stuff is always needed for tracimv2
|
11
|
|
-# CURRENT_USER_WEB = 'WEB'
|
12
|
|
-# CURRENT_USER_WSGIDAV = 'WSGIDAV'
|
13
|
|
-
|
14
|
9
|
|
15
|
10
|
class UserApi(object):
|
16
|
11
|
|
|
@@ -53,18 +48,11 @@ class UserApi(object):
|
53
|
48
|
if do_save:
|
54
|
49
|
self.save(user)
|
55
|
50
|
|
56
|
|
- if email and self._user and user.user_id==self._user.user_id:
|
57
|
|
- pass
|
58
|
|
- # this is required for the _session to keep on being up-to-date
|
59
|
|
- # TODO - G.M - 28-03-2018 -
|
60
|
|
- # [CurrentUser] Check for pyramid equivalent
|
61
|
|
- # tg.request.identity['repoze.who.userid'] = email
|
62
|
|
- # tg.auth_force_login(email)
|
63
|
|
-
|
64
|
51
|
def user_with_email_exists(self, email: str):
|
65
|
52
|
try:
|
66
|
53
|
self.get_one_by_email(email)
|
67
|
54
|
return True
|
|
55
|
+ # TODO - G.M - 09-04-2018 - Better exception
|
68
|
56
|
except:
|
69
|
57
|
return False
|
70
|
58
|
|
|
@@ -115,64 +103,3 @@ class UserApi(object):
|
115
|
103
|
# calendar_class=UserCalendar,
|
116
|
104
|
# related_object_id=created_user.user_id,
|
117
|
105
|
# )
|
118
|
|
-
|
119
|
|
-
|
120
|
|
-# TODO - G.M - 28-03-2018 - [CurrentUser][auth] Check for pyramid equivalent
|
121
|
|
-# class CurrentUserGetterInterface(object):
|
122
|
|
-# def get_current_user(self) -> typing.Union[None, User]:
|
123
|
|
-# raise NotImplementedError()
|
124
|
|
-#
|
125
|
|
-#
|
126
|
|
-# class BaseCurrentUserGetter(CurrentUserGetterInterface):
|
127
|
|
-# def __init__(self) -> None:
|
128
|
|
-# self.api = UserApi(None)
|
129
|
|
-
|
130
|
|
-
|
131
|
|
-# class WebCurrentUserGetter(BaseCurrentUserGetter):
|
132
|
|
-# def get_current_user(self) -> typing.Union[None, User]:
|
133
|
|
-# # HACK - D.A. - 2015-09-02
|
134
|
|
-# # In tests, the tg.request.identity may not be set
|
135
|
|
-# # (this is a buggy case, but for now this is how the software is;)
|
136
|
|
-# if tg.request is not None:
|
137
|
|
-# if hasattr(tg.request, 'identity'):
|
138
|
|
-# if tg.request.identity is not None:
|
139
|
|
-# return self.api.get_one_by_email(
|
140
|
|
-# tg.request.identity['repoze.who.userid'],
|
141
|
|
-# )
|
142
|
|
-#
|
143
|
|
-# return None
|
144
|
|
-
|
145
|
|
-# TODO - G.M - 28-03-2018 - [Webdav] Reenable Webdav stuff
|
146
|
|
-# class WsgidavCurrentUserGetter(BaseCurrentUserGetter):
|
147
|
|
-# def get_current_user(self) -> typing.Union[None, User]:
|
148
|
|
-# if hasattr(cherrypy.request, 'current_user_email'):
|
149
|
|
-# return self.api.get_one_by_email(
|
150
|
|
-# cherrypy.request.current_user_email,
|
151
|
|
-# )
|
152
|
|
-#
|
153
|
|
-# return None
|
154
|
|
-
|
155
|
|
-
|
156
|
|
-# class CurrentUserGetterApi(object):
|
157
|
|
-# thread_local = threading.local()
|
158
|
|
-# matches = {
|
159
|
|
-# CURRENT_USER_WEB: WebCurrentUserGetter,
|
160
|
|
-# CURRENT_USER_WSGIDAV: WsgidavCurrentUserGetter,
|
161
|
|
-# }
|
162
|
|
-# default = CURRENT_USER_WEB
|
163
|
|
-#
|
164
|
|
-# @classmethod
|
165
|
|
-# def get_current_user(cls) -> User:
|
166
|
|
-# try:
|
167
|
|
-# return cls.thread_local.getter.get_current_user()
|
168
|
|
-# except AttributeError:
|
169
|
|
-# return cls.factory(cls.default).get_current_user()
|
170
|
|
-#
|
171
|
|
-# @classmethod
|
172
|
|
-# def set_thread_local_getter(cls, name) -> None:
|
173
|
|
-# if not hasattr(cls.thread_local, 'getter'):
|
174
|
|
-# cls.thread_local.getter = cls.factory(name)
|
175
|
|
-#
|
176
|
|
-# @classmethod
|
177
|
|
-# def factory(cls, name: str) -> CurrentUserGetterInterface:
|
178
|
|
-# return cls.matches[name]()
|