7 from .. import countries
10 from . import ui_modules
12 class IndexHandler(base
.BaseHandler
):
13 @tornado.web
.authenticated
15 self
.render("people/index.html")
18 class CallsHandler(base
.BaseHandler
):
19 @tornado.web
.authenticated
20 def get(self
, uid
, date
=None):
21 account
= self
.backend
.accounts
.get_by_uid(uid
)
23 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
25 # Check for permissions
26 if not account
.can_be_managed_by(self
.current_user
):
27 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
31 date
= datetime
.datetime
.strptime(date
, "%Y-%m-%d").date()
33 raise tornado
.web
.HTTPError(400, "Invalid date: %s" % date
)
35 date
= datetime
.date
.today()
37 self
.render("people/calls.html", account
=account
, date
=date
)
40 class CallHandler(base
.BaseHandler
):
41 @tornado.web
.authenticated
42 def get(self
, uid
, uuid
):
43 account
= self
.backend
.accounts
.get_by_uid(uid
)
45 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
47 # Check for permissions
48 if not account
.can_be_managed_by(self
.current_user
):
49 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
51 call
= self
.backend
.talk
.freeswitch
.get_call_by_uuid(uuid
)
53 raise tornado
.web
.HTTPError(404, "Could not find call %s" % uuid
)
57 self
.render("people/call.html", account
=account
, call
=call
)
60 class ConferencesHandler(base
.BaseHandler
):
61 @tornado.web
.authenticated
63 self
.render("people/conferences.html", conferences
=self
.backend
.talk
.conferences
)
66 class SubscribeHandler(base
.BaseHandler
):
67 @tornado.web
.authenticated
70 self
.current_user
.consents_to_promotional_emails
= True
72 self
.render("people/subscribed.html")
75 class UnsubscribeHandler(base
.BaseHandler
):
76 @tornado.web
.authenticated
78 if self
.current_user
.consents_to_promotional_emails
:
79 return self
.render("people/unsubscribe.html")
81 self
.render("people/unsubscribed.html")
83 @tornado.web
.authenticated
86 self
.current_user
.consents_to_promotional_emails
= False
88 self
.render("people/unsubscribed.html")
91 class SIPHandler(base
.BaseHandler
):
92 @tornado.web
.authenticated
94 account
= self
.backend
.accounts
.get_by_uid(uid
)
96 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
98 # Check for permissions
99 if not account
.can_be_managed_by(self
.current_user
):
100 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
102 self
.render("people/sip.html", account
=account
)
105 class UserEditHandler(base
.BaseHandler
):
106 @tornado.web
.authenticated
108 account
= self
.backend
.accounts
.get_by_uid(uid
)
110 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
112 # Check for permissions
113 if not account
.can_be_managed_by(self
.current_user
):
114 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
116 self
.render("people/user-edit.html", account
=account
, countries
=countries
.get_all())
118 @tornado.web
.authenticated
120 account
= self
.backend
.accounts
.get_by_uid(uid
)
122 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
124 # Check for permissions
125 if not account
.can_be_managed_by(self
.current_user
):
126 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
128 # Unfortunately this cannot be wrapped into a transaction
130 account
.first_name
= self
.get_argument("first_name")
131 account
.last_name
= self
.get_argument("last_name")
132 account
.nickname
= self
.get_argument("nickname", None)
133 account
.street
= self
.get_argument("street", None)
134 account
.city
= self
.get_argument("city", None)
135 account
.postal_code
= self
.get_argument("postal_code", None)
136 account
.country_code
= self
.get_argument("country_code", None)
137 account
.description
= self
.get_argument("description", None)
141 filename
, data
, mimetype
= self
.get_file("avatar")
143 if not mimetype
.startswith("image/"):
144 raise tornado
.web
.HTTPError(400, "Avatar is not an image file: %s" % mimetype
)
146 account
.upload_avatar(data
)
151 account
.mail_routing_address
= self
.get_argument("mail_routing_address", None)
154 account
.phone_numbers
= self
.get_argument("phone_numbers", "").splitlines()
155 account
.sip_routing_address
= self
.get_argument("sip_routing_address", None)
156 except ldap
.STRONG_AUTH_REQUIRED
as e
:
157 raise tornado
.web
.HTTPError(403, "%s" % e
) from e
159 # Redirect back to user page
160 self
.redirect("/users/%s" % account
.uid
)
163 class UserPasswdHandler(base
.BaseHandler
):
164 @tornado.web
.authenticated
166 account
= self
.backend
.accounts
.get_by_uid(uid
)
168 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
170 # Check for permissions
171 if not account
.can_be_managed_by(self
.current_user
):
172 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
174 self
.render("people/passwd.html", account
=account
)
176 @tornado.web
.authenticated
178 account
= self
.backend
.accounts
.get_by_uid(uid
)
180 raise tornado
.web
.HTTPError(404, "Could not find account %s" % uid
)
182 # Check for permissions
183 if not account
.can_be_managed_by(self
.current_user
):
184 raise tornado
.web
.HTTPError(403, "%s cannot manage %s" % (self
.current_user
, account
))
186 # Get current password
187 password
= self
.get_argument("password")
190 password1
= self
.get_argument("password1")
191 password2
= self
.get_argument("password2")
193 # Passwords must match
194 if not password1
== password2
:
195 raise tornado
.web
.HTTPError(400, "Passwords do not match")
197 # XXX Check password complexity
199 # Check if old password matches
200 if not account
.check_password(password
):
201 raise tornado
.web
.HTTPError(403, "Incorrect password for %s" % account
)
204 account
.passwd(password1
)
206 # Redirect back to user's page
207 self
.redirect("/users/%s" % account
.uid
)
210 class AgentModule(ui_modules
.UIModule
):
211 def render(self
, account
):
212 return self
.render_string("people/modules/agent.html", account
=account
)
215 class CDRModule(ui_modules
.UIModule
):
216 def render(self
, account
, date
=None, limit
=None):
217 cdr
= account
.get_cdr(date
=date
, limit
=limit
)
219 return self
.render_string("people/modules/cdr.html",
220 account
=account
, cdr
=list(cdr
))
223 class ChannelsModule(ui_modules
.UIModule
):
224 def render(self
, account
):
225 return self
.render_string("people/modules/channels.html",
226 account
=account
, channels
=account
.sip_channels
)
229 class MOSModule(ui_modules
.UIModule
):
230 def render(self
, call
):
231 return self
.render_string("people/modules/mos.html", call
=call
)
234 class PasswordModule(ui_modules
.UIModule
):
235 def render(self
, account
=None):
236 return self
.render_string("people/modules/password.html", account
=account
)
238 def javascript_files(self
):
239 return "js/zxcvbn.js"
241 def embedded_javascript(self
):
242 return self
.render_string("people/modules/password.js")
245 class RegistrationsModule(ui_modules
.UIModule
):
246 def render(self
, account
):
247 return self
.render_string("people/modules/registrations.html", account
=account
)