我是node.js的新手,並且想爲user.also創建一個註冊和登錄頁面,並且必須爲用戶進行適當的授權。我想存儲用戶信息裏面mongodb數據庫。我怎麼能做到這一點。有人給我提供代碼這樣做,所以我可以開始使用node.js和mongodb.Please幫助在node.js和mongodb中創建註冊和登錄表單
回答
你可以找到你在做什麼完整的示例做登錄試圖在Nodepad application by Alex Young做。 2.重要的文件,你應該看看這些是2:
https://github.com/alexyoung/nodepad/blob/master/models.js
https://github.com/alexyoung/nodepad/blob/master/app.js
模型的一部分是這樣的:
User = new Schema({
'email': { type: String, validate: [validatePresenceOf, 'an email is required'], index: { unique: true } },
'hashed_password': String,
'salt': String
});
User.virtual('id')
.get(function() {
return this._id.toHexString();
});
User.virtual('password')
.set(function(password) {
this._password = password;
this.salt = this.makeSalt();
this.hashed_password = this.encryptPassword(password);
})
.get(function() { return this._password; });
User.method('authenticate', function(plainText) {
return this.encryptPassword(plainText) === this.hashed_password;
});
User.method('makeSalt', function() {
return Math.round((new Date().valueOf() * Math.random())) + '';
});
User.method('encryptPassword', function(password) {
return crypto.createHmac('sha1', this.salt).update(password).digest('hex');
});
User.pre('save', function(next) {
if (!validatePresenceOf(this.password)) {
next(new Error('Invalid password'));
} else {
next();
}
});
Alex的教程正是我所需要的。 – mwilcox
http://dailyjs.com/2010/12/06/node-tutorial-5/這是驗證頁面。 –
爲了一個簡單的方法開始看看ExpressJS + MongooseJS + MongooseAuth。
特別是,最後插件提供了一個標準的簡單的方法使用幾種不同的身份驗證方法(密碼,Facebook,微博等)
我寫了一個boilerplate project做exactly this.它支持賬戶創建,通過電子郵件獲取密碼,會話,當用戶返回時記住用戶的本地cookie以及通過bcyrpt安全密碼加密。
There's also a detailed explanation of the project's architecture on my blog.
- 1. 在Node.js和MongoDB中登錄表單(mongoose)
- 2. 如何使用node.js創建簡單的restful api登錄和註冊mongodb express.js
- 3. 登錄和註冊表格
- 4. 註冊和登錄表格
- 5. cakephp註冊和登錄表單
- 6. 登錄表單和註冊PHP
- 7. 註冊和登錄
- 8. 創建登錄/註冊表格
- 9. 如何使用Laravel 5.1創建簡單的註冊和登錄?
- 10. Node.js用標籤表示登錄和註冊表格
- 11. 當用戶登錄時隱藏註冊和登錄表單ASP.NET
- 12. 如何使用asp.net中的成員身份創建登錄和註冊表單?
- 13. Node.js,MongoDB登錄表
- 14. 如何創建註冊和登錄與jQuery和CouchDB的?
- 15. 如何使用php和xampp創建登錄和註冊頁面
- 16. 在Silverlight中執行登錄和註冊表單動畫
- 17. 無法在laravel中切換登錄和註冊表單
- 18. WordPress的 - 單獨登錄和註冊表單在同一頁
- 19. 錯誤註冊和登錄
- 20. PHP OO登錄和註冊
- 21. 登錄和註冊MySql Issuse
- 22. 登錄和註冊PythonSocialAuth
- 23. MySQL的登錄和註冊
- 24. Android - Facebook登錄和註冊
- 25. 登錄和註冊屏幕
- 26. 登錄和註冊系統
- 27. 註冊和登錄系統
- 28. 在註冊表和登錄表單之間翻轉
- 29. 安全登錄表單和註冊表單(帶序列號)
- 30. 如何在WooCommerce中創建單獨的登錄和註冊頁面
到目前爲止,您的嘗試有哪些? – beny23