Esempio n. 1
0
    def user_logout(self, uid):
        user = Session().query(models.User).filter(models.User.id == uid).first()
        user.api_token = ''
        Session.commit()

        # dispatch the event
        signal = json.dumps({
            'print': True,
            'message': "User disconnected"
        })
        dispatcher.send(signal, sender="Users")
Esempio n. 2
0
    def user_login(self, user_name, password):
        user = Session().query(models.User).filter(models.User.username == user_name).first()
            
        if user is None:
            return None

        if not self.check_password(password, user.password):
            return None

        user.api_token = user.api_token or self.refresh_api_token()
        user.last_logon_time = helpers.getutcnow()
        user.username = user_name
        Session.commit()

        # dispatch the event
        signal = json.dumps({
            'print': True,
            'message': "{} connected".format(user_name)
        })
        dispatcher.send(signal, sender="Users")
        return user.api_token