django - 避免他人请求 URL 和修改用户数据 [DJANGO]
问题描述
在我的问题中,我提到了 django,但这是关于与后端的用户交互机制的一般问题。我正在开发 iOS 应用程序,例如,我想让用户更新电子邮件地址,因此我的后端是:
class UpdateEmail(APIView):
serializer_class = EmailSerializer
def put(self, request):
user_id = request.data.get('id')
new_email = request.data.get('new_email').lower()
User.objects.filter(id=user_id).update(email=new_email)
return Response('OK')
如您所见,我提出了这种类型的 put 请求:
{
"id":user_id_logged_in_mobile_device_stored_locally,
"email":new_email
}
我的问题是,如何避免其他人发出 PUT 请求并修改某些用户的信息?也许这不是解决问题的正确方法。
解决方案
推荐阅读
- html - 我在移动设备上的下拉菜单不起作用
- wpf - 在窗口 10 版本 1903 和 Visual Studio 2019 中安装 Nuget 包 Microsoft.UI.Xaml 时出错
- c# - 限制用户可以绘制和擦除的行数
- authentication - 如何从 Blazor 访问 HttpContext
- c# - 使用 EPplus 导出图表时 X 轴标签中的日期时间格式问题
- sql-server - 您如何为分层表中的每一行动态分配唯一代码?
- swift - 我想使用 SWIFT 将图像上传到服务器与肥皂连接
- authentication - 如何使用 SQS 为事件消费实现自定义身份验证/授权?
- typescript - [label: string] 的语法:作为参数接收时的数字类型?
- python - Spark pandas_udf 并不快