def update_password(self, request): current_user = get_endpoints_current_user(raise_unauthorized=False) if current_user is not None: raise endpoints.BadRequestException("Google OAuth User can't update password.") user = auth_user(self.request_state.headers) user.password = md5(request.password) user.put() return message_types.VoidMessage()
def bind_account(self, request): current_user = get_endpoints_current_user(raise_unauthorized=True) auth_source = request.auth_source if auth_source is None: auth_source = 'Google' email = current_user.email() user = User.find_user_by_email(email) if user is not None: user.auth_source = auth_source user.display_name = request.display_name user.put() else: User.insert_user(current_user.email(), request.display_name, auth_source) return message_types.VoidMessage()
def vote_delete(self, request): """ Exposes an API endpoint to delete an existing vote. """ if request.id is None and request.anno_id is None: raise endpoints.BadRequestException('id or anno_id field is required.') if request.id is not None: vote = Vote.get_by_id(request.id) if vote is None: raise endpoints.NotFoundException('No vote entity with the id "%s" exists.' % request.id) anno = vote.anno_key.get() vote.key.delete() anno.vote_count -= 1 anno.put() elif request.anno_id is not None: user = User.find_user_by_email(get_endpoints_current_user().email()) anno = Anno.get_by_id(request.anno_id) for key in Vote.query(Vote.anno_key == anno.key, Vote.creator == user.key).iter(keys_only=True): key.delete() anno.vote_count -= 1 anno.put() return message_types.VoidMessage()