Mercurial > libervia-web
comparison src/server/server.py @ 1090:9c41b7e91172
server: set jid and started time in session on log-in:
session make the difference between local libervia session ("started"), and backend session ("backend_started")
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 01 Jun 2018 12:55:25 +0200 |
parents | d1324e43d448 |
children | eda7a1c6532a |
comparison
equal
deleted
inserted
replaced
1089:3996acd7c796 | 1090:9c41b7e91172 |
---|---|
1567 kwargs["callback"] = _callback | 1567 kwargs["callback"] = _callback |
1568 kwargs["errback"] = _errback | 1568 kwargs["errback"] = _errback |
1569 getattr(self.bridge, method_name)(*args, **kwargs) | 1569 getattr(self.bridge, method_name)(*args, **kwargs) |
1570 return d | 1570 return d |
1571 | 1571 |
1572 @defer.inlineCallbacks | |
1572 def _logged(self, profile, request): | 1573 def _logged(self, profile, request): |
1573 """Set everything when a user just logged in | 1574 """Set everything when a user just logged in |
1574 | 1575 |
1575 @param profile | 1576 @param profile |
1576 @param request | 1577 @param request |
1579 - C.PROFILE_LOGGED_EXT_JID | 1580 - C.PROFILE_LOGGED_EXT_JID |
1580 @raise exceptions.ConflictError: session is already active | 1581 @raise exceptions.ConflictError: session is already active |
1581 """ | 1582 """ |
1582 register_with_ext_jid = self.waiting_profiles.getRegisterWithExtJid(profile) | 1583 register_with_ext_jid = self.waiting_profiles.getRegisterWithExtJid(profile) |
1583 self.waiting_profiles.purgeRequest(profile) | 1584 self.waiting_profiles.purgeRequest(profile) |
1584 _session = request.getSession() | 1585 session = request.getSession() |
1585 sat_session = session_iface.ISATSession(_session) | 1586 sat_session = session_iface.ISATSession(session) |
1586 if sat_session.profile: | 1587 if sat_session.profile: |
1587 log.error(_(u'/!\\ Session has already a profile, this should NEVER happen!')) | 1588 log.error(_(u'/!\\ Session has already a profile, this should NEVER happen!')) |
1588 raise failure.Failure(exceptions.ConflictError("Already active")) | 1589 raise failure.Failure(exceptions.ConflictError("Already active")) |
1589 | 1590 |
1590 sat_session.profile = profile | 1591 sat_session.profile = profile |
1604 except KeyError: | 1605 except KeyError: |
1605 pass | 1606 pass |
1606 #and now we disconnect the profile | 1607 #and now we disconnect the profile |
1607 self.bridge.disconnect(profile) | 1608 self.bridge.disconnect(profile) |
1608 | 1609 |
1609 _session.notifyOnExpire(onExpire) | 1610 session.notifyOnExpire(onExpire) |
1610 | 1611 |
1611 return C.PROFILE_LOGGED_EXT_JID if register_with_ext_jid else C.PROFILE_LOGGED | 1612 # FIXME: those session infos should be returned by connect or isConnected |
1613 infos = yield self.bridgeCall('sessionInfosGet', profile) | |
1614 sat_session.jid = jid.JID(infos['jid']) | |
1615 sat_session.backend_started = int(infos['started']) | |
1616 | |
1617 state = C.PROFILE_LOGGED_EXT_JID if register_with_ext_jid else C.PROFILE_LOGGED | |
1618 defer.returnValue(state) | |
1612 | 1619 |
1613 @defer.inlineCallbacks | 1620 @defer.inlineCallbacks |
1614 def connect(self, request, login, password): | 1621 def connect(self, request, login, password): |
1615 """log user in | 1622 """log user in |
1616 | 1623 |
1723 )) | 1730 )) |
1724 raise exceptions.InternalError("profile mismatch") | 1731 raise exceptions.InternalError("profile mismatch") |
1725 defer.returnValue(C.SESSION_ACTIVE) | 1732 defer.returnValue(C.SESSION_ACTIVE) |
1726 log.info(_(u"profile {profile} was already connected in backend".format(profile=profile))) | 1733 log.info(_(u"profile {profile} was already connected in backend".format(profile=profile))) |
1727 # no, we have to create it | 1734 # no, we have to create it |
1728 defer.returnValue(self._logged(profile, request)) | 1735 |
1736 state = yield self._logged(profile, request) | |
1737 defer.returnValue(state) | |
1729 | 1738 |
1730 def registerNewAccount(self, request, login, password, email): | 1739 def registerNewAccount(self, request, login, password, email): |
1731 """Create a new account, or return error | 1740 """Create a new account, or return error |
1732 @param request(server.Request): request linked to the session | 1741 @param request(server.Request): request linked to the session |
1733 @param login(unicode): new account requested login | 1742 @param login(unicode): new account requested login |