2016-06-12 2 views
-2

서버 측의 메소드에 문제가 있습니다. 두 번 호출되지만 하나만 있어야합니다. 암호를 변경하면 오류가 발생합니다. 암호를 변경하려면 Accounts.setpassword()를 사용합니다. 그것에메소드가 두 번 호출됩니다. 왜 그럴까요?

import { Meteor } from 'meteor/meteor'; 
import { check } from 'meteor/check'; 
import { TAPi18n } from 'meteor/tap:i18n'; 
import { Accounts } from 'meteor/accounts-base'; 
import _ from 'lodash'; 

Meteor.methods({ 
    'users/change-user-settings'(formData) { 
    if (!this.userId) { 
     throw new Meteor.Error(401, TAPi18n.__('errors.you_are_not_logged')); 
    } 
    check(formData, App.Schemas.userSettingsSchema); 

    //change password 
    if (formData.password) { 
     Accounts.setPassword(this.userId, formData.password, {logout: false}); 
    } 


    //change email 
    if (formData.email) { 
     Meteor.users.update({_id: this.userId}, { 
      $set: { 
       'emails.0.address': formData.email 
      } 
     }); 
    } 

    //change phone number 
    if (formData.phoneNumber) { 
     Meteor.users.update({_id: this.userId}, { 
      $set: { 
       'phoneNumber': formData.phoneNumber 
      } 
     }); 
    } 

    return true; 
    } 
}); 

내 자동 폼 양식 및 스키마 : 그 방법의 코드를 아래

<template name="userSettingsTemplate"> 
    <div class="user-settings-form-wrapper"> 
    <h4>Change settings</h4> 

    {{ #autoForm id="userSettingsForm" type="method" meteormethod="users/change-user-settings" schema=getUserSettingsSchema class="form-horizontal"}} 
     {{ > afQuickField name="password" label="Change password: " template="bootstrap3-horizontal" label-class="col-xs-6" input-col-class="col-xs-6"}} 
     {{ > afQuickField name="passwordConfirmation" label="Confirm password: " template="bootstrap3-horizontal" label-class="col-xs-6" input-col-class="col-xs-6"}} 
     {{ > afQuickField name="email" label="E-mail: " template="bootstrap3-horizontal" label-class="col-xs-6" input-col-class="col-xs-6"}} 
     {{ > afQuickField name="phoneNumber" label="Phone number: " template="bootstrap3-horizontal" label-class="col-xs-6" input-col-class="col-xs-6"}} 
     <div class="form-group"> 
     <button type="submit" class="btn btn-primary full-width">Send</button> 
     </div> 
    {{/autoForm }} 

    </div> 
</template> 

스키마 :

import { SimpleSchema } from 'meteor/aldeed:simple-schema'; 
import { TAPi18n } from 'meteor/tap:i18n'; 
import { Meteor } from 'meteor/meteor'; 

Meteor.startup(() => { 
    // for running tests this is temporary workaround 
    try { 
    SimpleSchema.messages({ 
     "passwordMismatch": "passwords are not the same" 
    }); 
    } 
    catch (e) { 
    console.log(e.message, e.name, e.stack); 
    } 
}); 

App.Schemas.userSettingsSchema = new SimpleSchema({ 
    password: { 
    type: String, 
    optional: true, 
    min: 6, 
    autoform: { 
     type: "password" 
    } 
    }, 
    passwordConfirmation: { 
    type: String, 
    min: 6, 
    optional: true, 
    autoform: { 
     type: "password" 
    }, 
    custom: function() { 
     if (this.value !== this.field('password').value) { 
     return "passwordMismatch"; 
     } 
    } 
    }, 
    email: { 
    type: String, 
    optional: true, 
    regEx: SimpleSchema.RegEx.Email 
    }, 
    phoneNumber: { 
    type: String, 
    optional: true 
    } 
}); 

답변

-1

그냥 보조 노트. 여기서 뭔가를 놓치지 않는다면, Accounts.setPassword()을 사용해서는 안됩니다. 이것은 서버 쪽 방법이기 때문에 새 암호는 일반 텍스트로 전송됩니다. 대신 클라이언트에서 실행되는 Accounts.changePassword()을보고 원하는 것을하기위한 것입니다.

관련 문제