コード例 #1
0
def get_user(req: Request):
    try:
        uao = base.utils.UserAuthenticationObject(req.obj["username"],
                                                  req.obj["password"])
        user = base.get_user(uao)
        response = Response(body=user)
    except base.utils.AuthenticationError:
        response = error_response(401)
    except base.utils.UserDoesNotExist:
        response = Response(404, body="User not found.")
    return response
コード例 #2
0
def delete_user(req: Request):
    try:
        uao = base.utils.UserAuthenticationObject(req.obj["username"],
                                                  req.obj["password"])
        user = base.get_user(uao)
        base.delete_user(user.get("id", 0), uao)
        response = Response()
    except base.utils.AuthenticationError as e:
        serverly.logger.handle_exception(e)
        response = error_response(401)
    except base.utils.UserDoesNotExist as e:
        serverly.logger.handle_exception(e)
        response = Response(404, body="User not found.")
    except base.utils.InvalidParameterError as e:
        serverly.logger.handle_exception(e)
        response = Response(406, body=str(e))
    return response
コード例 #3
0
 def __init__(self, message=None, user_id=None):
     if message or user_id:
         args = base.get_user(
             (int(message.from_user.id) if message else int(user_id)))
         if not args and message:
             base.authorize(message)
             return
         args = args[-1]
         self.username = args[1]
         self.name = args[2]
         self.surname = args[3]
         self.user_id = args[4]
         self.source = args[5]
         self.dialogues = args[6]
         self.sphere = args[7]
         self.salary = args[8]
         self.interests = args[9]
         self.registration_time = args[10]
コード例 #4
0
def test_db_setup():
    """test whether the db is set up correctly for tests"""
    user = get_user(test_user)
    ident = user.get("id")
    assert type(ident) == int
    try:
        assert ident == 1
    except AssertionError:
        print(ident)
        warnings.warn(
            "User 'tester' does not have id 1. It needs to for testing.")
        assert False
    try:
        exec_sql("SELECT * FROM users")
        exec_sql("SELECT * FROM tasks")
        exec_sql("SELECT * FROM statistics")
        exec_sql("SELECT * FROM tests")
    except ProgrammingError:
        raise ConfigError(
            "tables not configured correctly. Expected to get tables: 'users', 'tasks', 'statistics', and 'tests'. Refer to the project documentation for more info."
        )
コード例 #5
0
ファイル: mailservice.py プロジェクト: mithem/helix2
def send_user_data(uao: UserAuthenticationObject):
    try:
        logger.context = "send_user_data"
        user = base.get_user(uao)
        sessions = base.statistics.get_sessions(uao)
        user_data = {"username": uao.username,
                     "password": uao.raw_password, "dateJoined": user.get("joined"), "email": user.get("email"), "sessions": []}
        for s in sessions:
            user_data["sessions"].append(
                {"start": s.get("start"), "end": s.get("end"), "duration": session_length(s)})
        filecontent = json.dumps(user_data)
        fname = file_paths["repo"] + "userData.json"
        with open(fname, "w") as f:
            f.write(filecontent)
        text = """Hi username,
        you recently requested your personal user data. So here you have it (in json format). Thanks for using Helix!
        Bye!\n\n
        """.replace("username", uao.username)
        text += filecontent
        send_email(user.get("email"), text, "Your Helix data")
    except Exception as e:
        logger.handle_exception(e)
        raise e