Ejemplo n.º 1
0
def user_info_put(body):  # noqa: E501
    """User modify his basic info.

     # noqa: E501

    :param body: 
    :type body: dict | bytes

    :rtype: UserInfo
    """
    if connexion.request.is_json:
        body = UserInfoWithoutId.from_dict(connexion.request.get_json())  # noqa: E501
    
    nickName = body.nick_name
    avatarUrl = body.avatar_url

    result = user_manager.modify(nick_name =nickName, avatar_url = avatarUrl)
    if result is not None:
         return UserInfo(
            user_id=result.user_id, 
            nick_name=result.nickname,
            avatar_url=result.photo,
            prove_state=result.isprove)
    else:
        return ErrorResponse(message="error"), 400
Ejemplo n.º 2
0
def user_session_post(body):  # noqa: E501
    """Users login

    Users login # noqa: E501

    :param body: 
    :type body: dict | bytes

    :rtype: UserInfo
    """
    if connexion.request.is_json:
        body = LoginCode.from_dict(connexion.request.get_json())  # noqa: E501
    js_code = body.js_code
    app_id = body.app_id
    app_secret = body.app_secret
    result = user_manager.login(js_code=js_code, app_id=app_id, app_secret=app_secret)
    if result is not None:
        return UserInfo(
            user_id=result.user_id, 
            nick_name=result.nickname,
            avatar_url=result.photo,
            prove_state=result.isprove)
    else:
        return ErrorResponse(message="登录失败"), 400
    return 'do some magic!'
Ejemplo n.º 3
0
def user_set_info(body):  # noqa: E501
    """Set users' info such as name, language, profile image etc.

    Set all fields to the current values, except for the overridden ones. No field should be missing. User ID must always be the ID of the current user.  # noqa: E501

    :param body: 
    :type body: dict | bytes

    :rtype: SignUpResponse
    """
    if not connexion.request.is_json:
        return SignUpResponse(status=400,
                              error_message="Missing JSON in request"), 400

    body = UserInfo.from_dict(connexion.request.get_json())  # noqa: E501
    me = facebook.load_current_user()

    if me is None:
        return SignUpResponse(status=404, error_message="User not found"), 404

    if me.id != body.id:
        return SignUpResponse(status=400,
                              error_message="ID does not match"), 400

    facebook.patch(me, body)
    facebook.save_user(me)

    cred = facebook.generate_credentials(me)
    user_info = facebook.get_user_info_self(cred)
    return SignUpResponse(status=200, me=user_info)
    def test_user_set_info(self):
        """Test case for user_set_info

        Set users' info such as name, language, profile image etc.
        """
        body = UserInfo()
        response = self.client.open('/api/user/set_info',
                                    method='POST',
                                    data=json.dumps(body),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
Ejemplo n.º 5
0
    def test_application_create_user(self):
        """Test case for application_create_user

        Creates a user with all the necessary information
        """
        user_info = UserInfo()
        response = self.client.open('/app/user',
                                    method='POST',
                                    data=json.dumps(user_info),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
Ejemplo n.º 6
0
    def test_application_login_user(self):
        """Test case for application_login_user

        User login
        """
        user_info = UserInfo()
        response = self.client.open('/app/login',
                                    method='POST',
                                    data=json.dumps(user_info),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
Ejemplo n.º 7
0
    def test_post_user_stats(self):
        """Test case for post_user_stats

        updates current user statistics count
        """
        user_info = UserInfo()
        response = self.client.open(
            '/api/v1/userStats',
            method='POST',
            data=json.dumps(user_info),
            content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
Ejemplo n.º 8
0
def application_create_user(user_info):  # noqa: E501
    """Creates a user with all the necessary information

     # noqa: E501

    :param user_info: User information
    :type user_info: dict | bytes

    :rtype: str
    """
    if connexion.request.is_json:
        user_info = UserInfo.from_dict(
            connexion.request.get_json())  # noqa: E501
    return emp.create_user(user_info=user_info)
Ejemplo n.º 9
0
def application_login_user(user_info):  # noqa: E501
    """User login

     # noqa: E501

    :param user_info: User information
    :type user_info: dict | bytes

    :rtype: str
    """
    if connexion.request.is_json:
        user_info = UserInfo.from_dict(
            connexion.request.get_json())  # noqa: E501
    return emp.login(user_info=user_info)