用于验证Parse.Cloud.beforeSave(Parse.User [英] Parse.com procedure for validating password requirements in Parse.Cloud.beforeSave(Parse.User

查看:121
本文介绍了用于验证Parse.Cloud.beforeSave(Parse.User的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到通过Parse.com添加密码要求的最佳过程.看起来最简单的方法是在保存用户数据之前立即使用云功能执行.我唯一的警告是,仅当密码与数据库中存储的密码不同或数据库中不存在用户时,我才想验证用户密码.

I am trying to find the best procedure for adding password requirements with Parse.com. It appears the easiest way would be to use a cloud function to execute right before user data is saved. My only caveat is that I want to validate user passwords only when the password is different from what is stored in the db or if the user does not exist in the db.

Parse.Cloud.beforeSave(Parse.User,function(request,response){ ... }

Parse.Cloud.beforeSave(Parse.User, function(request, response) { ... }

问题对:

  1. request.object.existed()是否可以像afterSave一样在beforeSave函数中工作?
  2. 是否可以通过beforeSave函数中的request.object访问用户密码(使用Parse.Cloud.useMasterKey())?还是我需要在函数内部查询用户的对象.
  3. 在日志中,beforeSave函数的输入似乎具有原始和更新的密钥,类似于下面的json.但是,我无法通过request.object访问原始文件并更新json.我将如何访问这些数据?如果在request.object.original.password!== request.object.updated.password之间进行比较,则仅需要执行一次检查来验证用户密码是否已更改,那将是很好的选择.
  1. Does request.object.existed() work in beforeSave functions as it does with afterSave?
  2. Can I access the user's password (using Parse.Cloud.useMasterKey()) via the request.object in the beforeSave functions? Or do I need to query the user's object inside the function.
  3. In the log the input to the beforeSave function appears to have original and updated keys similar to the json below. However, I was not able to access the original and update json through the request.object. How would I access this data? It would be nice if the only check needed to be performed to verify whether a user's password as changed if a comparison between request.object.original.password !== request.object.updated.password

示例云代码日志输出:

输入:{原始":{电子邮件":等等", "firstname":等等", "emailVerified":是的, "username":等等", "createdAt":"2014-04-28T23:05:47.452Z", "updatedAt":"2014-0716T01:55:52.907Z",
"objectId":等等", "sessionToken":等等"}, "update":{"firstname":"blah2"}}

Input: {"original":{"email":"blah", "firstname" : "blah", "emailVerified":true, "username":"blah", "createdAt":"2014-04-28T23:05:47.452Z", "updatedAt":"2014-0716T01:55:52.907Z",
"objectId":"blah", "sessionToken":"blah"}, "update":{"firstname":"blah2"}}

推荐答案

尝试如下操作:

Parse.Cloud.beforeSave(Parse.User, function(request, response) {

  if (request.object.isNew()) {
      // new object.. 
      response.success();
  } else {
    if (request.object.dirtyKeys().indexOf("password") > -1) {
      // Attempted to change the password.
      response.error('No.');
    }
  }

});

这篇关于用于验证Parse.Cloud.beforeSave(Parse.User的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆