朋友们,有些人可以给我一些材料,如更改密码,电子邮件和在个人资料中添加新的字段,如性别,年龄城市添加照片。不使用集合或aldeed-autoform。 所有这一切都使用我自己的代码,所以有一点点控制一些alded-autoform选择函数,如select或datepicker在设计中看起来不太好。
Template.update.events({
'submit form' ( event, template ) {
event.preventDefault();
const target = event.target;
var oldPass = $('#password');
var newPass = $('#password-new');
var verifyPass = $('#password-confirm');
if(newPass.val() === verifyPass.val()){
Accounts.changePassword(oldPass.val(), verifyPass.val(), function(err){
if(err) {
console.log(err);
} else {
let profile = {
address: {
city: target.city.value,
street: target.street.value
},
gender: target.gender.value,
favoriteColor: target.favoriteColor.value,
}
console.log("datos actualizados");
}
});
oldPass.val('');
verifyPass.val('');
newPass.val('');
} else {
console.log("password no match");
}
//}
console.log(profile);
Meteor.call('updateUser', profile);
}
});
{
_id: "bbca5d6a-2156-41c4-89da-0329e8c99a4f",
emails: [
{ address: "cool@example.com", verified: true },
],
createdAt: Wed Aug 21 2013 15:16:52 GMT-0700 (PDT),
profile: {
name: "Joe Schmoe",
phone: "5555-555-555",
gender: "male",
city: "DC",
country: "USA",
birthday: "01-01-2017"
}
答案 0 :(得分:0)
Marcelrama,
我将分享我是如何做到这一点的。对于我的项目,我存储的内容如skype Id和时区。所以当我在Meteor Method中创建一个新用户时
Accounts.createUser({
email: 'example@example.com',
password: 'testing',
profile: {
name: "Jack",
gender: "Male",
skypeid: "jack123",
timezone: {
name: "UTC",
offset: "UTC"
}
}
});
您也可以这样做。
let newUser = { ... };
let user = Accounts.createUser(newUser);
将其存储在变量中会返回Mongo Id。
然后当你去更新个人资料时,你可以这样做。
Meteor.users.update({ _id: user }, { $set: { "profile.name": "Jake" } });
如果在尚不存在的字段上使用Meteor.users.update,它将使用您指定的值创建该字段,但请确保使用"引号"钥匙周围。
Meteor.users.update({ _id: user },
{
$set: { "profile.address.city": "Orlando" }
}
);
这是官方文档。 http://docs.meteor.com/api/accounts.html
这是一个非常基本的例子
包---
meteor add accounts-base
meteor add accounts-password
npm install --save bcrypt
模板---
<template name="signup">
<form>
<input type="email" name="email"><br>
<input type="password" name="password"><br>
<input type="text" name="name"><br>
<input type="submit" value="submit">
</form>
</template>
事件---
import { Meteor } from 'meteor/meteor';
Template.signup.events({
'submit form' ( event, template ) {
event.preventDefault();
const target = event.target;
let newUser = {
email: target.email.value,
password: target.password.value,
profile: {
name: target.name.value
}
}
Meteor.call('createNewUser', newUser);
}
});
方法---
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
Meteor.methods({
'createNewUser' ( userObj ) {
let user = Accounts.createUser(userObj);
user = Accounts.users.findOne(user);
console.log(user);
}
});
答案 1 :(得分:0)
<template name="update">
<form>
<input type="text" name="gender" placeholder="gender"><br>
<input type="text" name="favoriteColor" placeholder="color"><br>
<input type="text" name="city" placeholder="city"><br>
<input type="text" name="street" placeholder="street"><br>
<input type="submit" value="submit">
</form>
</template>
Template.update.events({
'submit form' ( event, template ) {
event.preventDefault();
const target = event.target;
let profile = {
address: {
city: target.city.value,
street: target.street.value
},
gender: target.gender.value,
favoriteColor: target.favoriteColor.value,
}
console.log(profile);
Meteor.call('updateUser', profile);
}
});
import { Meteor } from 'meteor/meteor';
Meteor.methods({
'updateUser' ( profileObj ) {
let userId = Meteor.userId();
console.log(userId);
Meteor.users.update(
{ '_id': userId },
{ '$set': {
'profile.gender': profileObj.gender,
'profile.favoriteColor': profileObj.favoriteColor,
'profile.address': profileObj.address
}
}
);
}
});