예제 #1
0
    def get_all_adOffs(self, request):
        user, ts = User.get_by_auth_token(int(request.user_id), request.user_token)
        if user is None:
            raise endpoints.ForbiddenException('User auth failed')

        cursor = None
        if request.last_cursor:
            cursor = ndb.Cursor.from_websafe_string(request.last_cursor)

        school_type = None
        if request.school_type and request.school_type != '':
            school_type = request.school_type

        college_rank = None
        if request.college_rank and request.college_rank != '':
            college_rank = request.college_rank

        if school_type and college_rank:
            ad_off_query = AdmissionsOfficer.query(AdmissionsOfficer.college_rank == college_rank,
                                                   AdmissionsOfficer.school_type == school_type).order(-AdmissionsOfficer.created,
                                                                                                       AdmissionsOfficer.key)
        elif school_type and not college_rank:
            ad_off_query = AdmissionsOfficer.query(AdmissionsOfficer.school_type == school_type).order(-AdmissionsOfficer.created,
                                                                                                       AdmissionsOfficer.key)
        elif not school_type and college_rank:
            ad_off_query = AdmissionsOfficer.query(AdmissionsOfficer.college_rank == college_rank).order(-AdmissionsOfficer.created,
                                                                                                         AdmissionsOfficer.key)
        else:
            ad_off_query = AdmissionsOfficer.query().order(-AdmissionsOfficer.created, AdmissionsOfficer.key)

        ad_offs, next_cursor, more = ad_off_query.fetch_page(10, start_cursor=cursor)

        ret_ad_off = AdmissionsOfficer.ToMessageCollection(ad_offs, next_cursor=next_cursor)
        return ret_ad_off
예제 #2
0
    def check_login(self, *args, **kwargs):
        self.response.headers['Content-Type'] = "application/json"
        user_id = self.request.get('user_id')
        token = self.request.get('token')

        # Does the user id and token exist in the datastore
        response_tuple = User.get_by_auth_token(int(user_id), token)

        # Response is a None tuple then the user id & token do not exist
        if response_tuple == (None, None):
            self.send_response(self.RESPONSE_CODE_401,
                               "User not authenticated", "")
        else:
            return handler(self, *args, **kwargs)
예제 #3
0
파일: auth.py 프로젝트: Yury191/hyperAdmit
    def check_login(self, *args, **kwargs):
        self.response.headers['Content-Type'] = "application/json"
        user_id = self.request.get('user_id')
        token = self.request.get('token')

        # Does the user id and token exist in the datastore
        response_tuple = User.get_by_auth_token(int(user_id), token)

        # Response is a None tuple then the user id & token do not exist
        if response_tuple == (None, None):
            self.send_response(self.RESPONSE_CODE_401,
                               "User not authenticated",
                               "")
        else:
            return handler(self, *args, **kwargs)
예제 #4
0
파일: auth.py 프로젝트: Yury191/hyperAdmit
    def post(self):
        self.response.headers['Content-Type'] = "application/json"

        jsn = json.loads(self.request.body)
        token = jsn['token']
        user_id = jsn['user_id']

        # Reset current user's device token
        user = User.get_by_auth_token(int(user_id), token)
        user = user[0]
        user.deviceToken = None
        user.put()

        self.user_model.delete_auth_token(user_id, token)
        self.send_response(self.RESPONSE_CODE_200, "User logged out", "")
예제 #5
0
    def post(self):
        self.response.headers['Content-Type'] = "application/json"

        jsn = json.loads(self.request.body)
        token = jsn['token']
        user_id = jsn['user_id']

        # Reset current user's device token
        user = User.get_by_auth_token(int(user_id), token)
        user = user[0]
        user.deviceToken = None
        user.put()

        self.user_model.delete_auth_token(user_id, token)
        self.send_response(self.RESPONSE_CODE_200, "User logged out", "")
예제 #6
0
    def get_all_adOffs(self, request):
        user, ts = User.get_by_auth_token(int(request.user_id),
                                          request.user_token)
        if user is None:
            raise endpoints.ForbiddenException('User auth failed')

        cursor = None
        if request.last_cursor:
            cursor = ndb.Cursor.from_websafe_string(request.last_cursor)

        school_type = None
        if request.school_type and request.school_type != '':
            school_type = request.school_type

        college_rank = None
        if request.college_rank and request.college_rank != '':
            college_rank = request.college_rank

        if school_type and college_rank:
            ad_off_query = AdmissionsOfficer.query(
                AdmissionsOfficer.college_rank == college_rank,
                AdmissionsOfficer.school_type == school_type).order(
                    -AdmissionsOfficer.created, AdmissionsOfficer.key)
        elif school_type and not college_rank:
            ad_off_query = AdmissionsOfficer.query(
                AdmissionsOfficer.school_type == school_type).order(
                    -AdmissionsOfficer.created, AdmissionsOfficer.key)
        elif not school_type and college_rank:
            ad_off_query = AdmissionsOfficer.query(
                AdmissionsOfficer.college_rank == college_rank).order(
                    -AdmissionsOfficer.created, AdmissionsOfficer.key)
        else:
            ad_off_query = AdmissionsOfficer.query().order(
                -AdmissionsOfficer.created, AdmissionsOfficer.key)

        ad_offs, next_cursor, more = ad_off_query.fetch_page(
            10, start_cursor=cursor)

        ret_ad_off = AdmissionsOfficer.ToMessageCollection(
            ad_offs, next_cursor=next_cursor)
        return ret_ad_off