小编Jef*_*uel的帖子

NodeJS 更新用户 Bcrypt - 密码未经过哈希处理

我正在尝试使用 bcrypt-nodejs 模块为具有哈希密码的 Node.JS 应用程序上的用户配置文件设置更新功能。它在登录时有效,但是当我更新配置文件时,它会使用纯文本更新用户对象(即:我输入“文本”作为密码,数据库显示“文本”)。我想在更新配置文件时对密码进行哈希处理。我该如何解决这个问题?

下面是我的控制器代码:

exports.editUser = function(req, res) {
 // user edit form set to findonendupdate
 User.findByIdAndUpdate({ _id: req.params.user_id, randString: req.body.randString }, req.body, function(err, user) { 

   if (err) 
    res.send(err); 
   res.json({ data: user }); 
 });
};
Run Code Online (Sandbox Code Playgroud)

作为参考,这是适用于新用户注册的用户模型代码:

 passport.use('local', new LocalStrategy(
  function(username, password, callback) {
   User.findOne({ username: username } , function (err, user) {
     if (err) { return callback(err); }

     // No user found with that username
     if (!user) { return callback(null, false); }

     // Make sure the password is …
Run Code Online (Sandbox Code Playgroud)

updates bcrypt node.js passport-local passport.js

2
推荐指数
1
解决办法
6053
查看次数

AngularJS编辑数据/表格

我想在AngularJS上创建一个表单来编辑通过REST API访问的数据库行.我没有访问数据的问题,我真正遇到的问题是配置表单进行编辑.我如何能够显示数据,如果用户单击提交按钮,则能够更新数据.下面是我的Angular代码.

   countryApp.controller('EditLocation', function($scope, $http, $routeParams, $location) { 
      //get the item information
      var id = $routeParams.locid; 
      $scope.activePath = null;    

      $http.get('http://localhost/slimtest2/location/'+id).success(function(data) { 
        $scope.location = data;  

      }); 

      $scope.editrel = function() { 
          var editData = { 
              location_title : $scope.l.location_title, 
              location_latitude : $scope.l.location_latitude, 
              location_longitude : $scope.l.location_longitude     
          } 

          //convert data to JSON string
          var loce = JSON.stringify(editData); 


          $http.put('http://localhost/slimtest2/location/edit', loce); 

      }

      $scope.reset = function() { 
        $scope.location = data; 
      } 


    }); 
Run Code Online (Sandbox Code Playgroud)

HTML - 编辑表单

<div ng-controller="EditLocation"> 

   <form name="editform" ng-submit="editrel()"> 
      <div ng-repeat="l in location.location">  
     <label for="location_title">Location Title</label>
     <input …
Run Code Online (Sandbox Code Playgroud)

javascript json sql-update angularjs

1
推荐指数
1
解决办法
7372
查看次数

如何上传带有表单数据的图像?

我正在通过 Expo 学习 React Native。对于测试项目,我有一个名为“创建配置文件”的屏幕,我试图在其中添加在 Expo 图像选择器上选择的图像以及其他文本输入(位置、描述)。如何将输入与图像选择器中的图像组合起来?

我当前的猜测是对图像使用 base64 或将图像输入设置为“this.state.image”以从选择器中调用 image:uri。尽管我可能走错了路。另一种选择是使用 Content-Type:multipart-form/data,尽管尝试时它不会将任何数据发布到 API 调用。

该 API 是使用 Django Rest Framework 在 Django 应用程序上构建的。

我的代码如下: render() { let { image } = this.state;

function handleSubmit(props) {
  fetch('<API URL HERE>', {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
    }, 
    body:JSON.stringify({
      'location': this.state.location,
      'description': this.state.description,
      //user image field and input below
      'user_image':this.state.image


    })
  });
} 
Run Code Online (Sandbox Code Playgroud)

图像选择器

_pickImage = async () => {
try {
  let result = await ImagePicker.launchImageLibraryAsync({
    mediaTypes: ImagePicker.MediaTypeOptions.All,
    allowsEditing: …
Run Code Online (Sandbox Code Playgroud)

react-native expo

0
推荐指数
1
解决办法
7699
查看次数