{"id":224403,"date":"2014-06-29T09:23:03","date_gmt":"2014-06-29T05:23:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=224403"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=224403","title":{"rendered":"<span class=\"post_title\">\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0431\u043b\u043e\u0433\u0430 \u043d\u0430 SailsJS: \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445 (\u0427\u0430\u0441\u0442\u044c 2)<\/span>"},"content":{"rendered":"<div class=\"content html_format\">     \t<habracut\/><\/p>\n<h4>\u0421\u0438\u043d\u043e\u043f\u0441\u0438\u0441<\/h4>\n<p>  <\/p>\n<ul>\n<li><a href=\"http:\/\/habrahabr.ru\/post\/224195\/\">\u041f\u0435\u0440\u0432\u0430\u044f \u0427\u0430\u0441\u0442\u044c<\/a><\/li>\n<\/ul>\n<p>  \u0420\u0430\u043d\u0435\u0435 \u043c\u044b \u0438\u0437\u0443\u0447\u0438\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u044b \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u043b\u043e\u0433\u0430, \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043e\u0441\u043d\u043e\u0432\u044b \u043c\u044b \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043b\u0438\u0441\u044c \u0441 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0441\u0442\u0430\u0442\u0438\u043a\u0438, \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u0434\u0430 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u0423\u0437\u043d\u0430\u043b\u0438 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f\u043c\u0438 \u043f\u0443\u0442\u0435\u0439 (<i>routes.js<\/i>), \u0438 \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u0432 SailsJS. \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0431\u043b\u043e\u0433\u0430 \u043d\u0430 SailsJS, \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0443\u043d\u043a\u0442\u044b: \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435. \u0421\u0435\u0441\u0441\u0438\u0438: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 (\u0432\u0445\u043e\u0434), \u0440\u0430\u0437\u0440\u044b\u0432 (\u0432\u044b\u0445\u043e\u0434). \u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0410\u0434\u043c\u0438\u043d \u041f\u0430\u043d\u0435\u043b\u0438, \u0438 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u043e\u0439 \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430.<\/p>\n<h4>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438<\/h4>\n<p>  \u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0441\u0430 API \u0432\u0432\u043e\u0434\u0438\u043c \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u0443\u044e \u043d\u0430\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0432 \u043a\u043e\u0440\u043d\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430.  <\/p>\n<pre><code class=\"bash\">sails generate api user <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043f\u0440\u0438 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u043e\u043b\u044c, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c <i><a href=\"https:\/\/www.npmjs.org\/package\/password-hash\">password-hash<\/a><\/i>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u0427\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u2014 \u0432 \u043a\u043e\u0440\u043d\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432\u0432\u0435\u0434\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443  <\/p>\n<pre><code class=\"bash\">npm install password-hash --save <\/code><\/pre>\n<p>  \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <i>&#8212;save<\/i> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0442\u043e \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u044c \u043a\u0430\u043a \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0432 <i>package.json<\/i>.<\/p>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0443\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043d\u0430\u0432\u044b\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u043c\u0438 \u0432 SailsJS \u2014 \u0433\u0434\u0435 \u043e\u043d\u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f, \u0438 \u043a\u0430\u043a \u0438\u0445 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c, \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043d\u0430 \u0443\u0436\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0435 \u0432\u0435\u0449\u0438.<\/p>\n<h5>\u041c\u043e\u0434\u0435\u043b\u044c<\/h5>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432:  <\/p>\n<ol>\n<li>\u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f <\/li>\n<li>\u041f\u0430\u0440\u043e\u043b\u044c<\/li>\n<li>\u0410\u0434\u043c\u0438\u043d \u2014 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0434\u043e\u0441\u0442\u0443\u043f\u0430<\/li>\n<\/ol>\n<p>  \u041f\u0440\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0442\u0430\u043a\u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u0440\u043e\u043b\u044f \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 <a href=\"https:\/\/github.com\/balderdashy\/waterline#lifecycle-callbacks\">\u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u043c\u0438 \u0446\u0438\u043a\u043b\u0430\u043c\u0438<\/a> \u043c\u043e\u0434\u0435\u043b\u0435\u0439  <\/p>\n<pre><code class=\"javascript\">var passwordHash = require('password-hash');  var User = {    attributes: {  \tusername: {type: 'string', required: true, unique: true}, \tpassword: {type: 'string', required: true, minLength: 8},      admin: {       type: 'boolean',       defaultsTo: false     },     toJSON: function() {     \tvar element = this.toObject();     \tdelete element.password;     \treturn element;     }    },    beforeCreate: function (values, next) {     \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u043f\u0430\u0440\u043e\u043b\u044f \u0432 \u0411\u0414     var mainPass = passwordHash.generate(values.password);     values.encryptPassword = mainPass;     next();  \t   }  };  module.exports = User;  <\/code><\/pre>\n<p>  \u0414\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u2014 <i>encryptedPassword<\/i>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u043f\u0430\u0440\u043e\u043b\u044f. <\/p>\n<h5>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440<\/h5>\n<p>  \u0412 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443. \u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0430\u043c\u0438 \u043f\u043e \u043f\u043e\u0434\u043e\u0431\u0438\u044e \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u043f\u043e\u0441\u0442\u043e\u0432. \u0412\u043e\u0442 \u043a\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.  <\/p>\n<pre><code class=\"javascript\"> module.exports = {  \t\/\/@API - \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f  \t\/** \t * \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \t * \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \t * \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u0430\u0440\u043e\u043b\u044c, \u0438 \u0431\u0443\u043b\u0435\u0432\u043e\u0435 \t * \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u0434\u043c\u0438\u043d. \u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \t * \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043e\u043d \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f \t * \u0432 \u0441\u0435\u0441\u0441\u0438\u0438. \u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f  \t * \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443 \t * admin (api\/policies\/admin.js) \u0447\u0442\u043e\u0431\u044b \u043a \t * \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043c\u043e\u0433\u043b\u0438 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \t * \u043d\u0435 \u043f\u0440\u0438\u0432\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \t *\/ \t  \tcreate: function (req, res) { \t\tvar elem = { \t\t\tusername : req.param('username'), \t\t\tpassword : req.param('password'), \t\t\tadmin    : req.param('admin') \t\t};  \t\tUser.create(elem).exec(function (err, user) { \t\t\tif (err) return res.send(500); \t\t\treq.session.auth = true; \t\t\tres.redirect('\/'); \t\t}); \t},  \t\/\/ @MAIN \tindex: function (req, res) { \t\tres.view(); \t} };  <\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043f\u0443\u0442\u0435\u0439 (<i>config\/routes.js<\/i>) \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435.  <\/p>\n<pre><code class=\"javascript\">  '\/register' : 'UserController', <\/code><\/pre>\n<p>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0437\u0430\u0449\u0438\u0442\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u043c \u0437\u0430\u0449\u0438\u0442\u0443 <a href=\"http:\/\/ru.wikipedia.org\/wiki\/CSRF\"><i>CSRF<\/i><\/a> \u0432 \u0444\u0430\u0439\u043b\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 (<i>config\/csrf.js<\/i>) \u043e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c  <\/p>\n<pre><code class=\"javascript\">module.exports.csrf = true; <\/code><\/pre>\n<h5>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 (<i>views\/user\/index.ejs<\/i>)<\/h5>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443.  <\/p>\n<pre><code class=\"html\">&lt;div class=&quot;container&quot;&gt; \t&lt;div class=&quot;row&quot;&gt; \t\t&lt;div class=&quot;col-md-4&quot;&gt;&lt;\/div&gt; \t\t&lt;div class=&quot;col-md-4&quot;&gt; \t\t\t&lt;div class=&quot;panel panel-default&quot;&gt; \t\t\t\t&lt;div class=&quot;panel-body&quot;&gt; \t\t\t\t\t&lt;form action=&quot;\/user\/create&quot; method=&quot;post&quot;&gt; \t\t\t\t\t\t&lt;input type=&quot;text&quot; name=&quot;username&quot; placeholder=&quot;\u0418\u043c\u044f \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f&quot;&gt;&lt;br&gt; \t\t\t\t\t\t&lt;input type=&quot;password&quot; name=&quot;password&quot; placeholder=&quot;\u041f\u0430\u0440\u043e\u043b\u044c&quot;&gt;&lt;br&gt; \t\t\t\t\t\t&lt;input type=&quot;hidden&quot; name=&quot;_csrf&quot; value=&quot;&lt;%= _csrf %&gt;&quot;&gt; \t\t\t\t\t\t&lt;!-- \u041f\u043e\u043b\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 --&gt; \t\t\t\t\t\t&lt;input type=&quot;hidden&quot; name=&quot;admin&quot; value=&quot;true&quot;&gt; \t\t\t\t\t\t \t\t\t\t\t\t&lt;input type=&quot;submit&quot; class=&quot;btn btn-success btn-block&quot; value=&quot;\u0417\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f&quot;&gt; \t\t\t\t\t&lt;\/form&gt; \t\t\t\t&lt;\/div&gt; \t\t\t&lt;\/div&gt; \t\t&lt;\/div&gt; \t\t&lt;div class=&quot;col-md-4&quot;&gt;&lt;\/div&gt; \t&lt;\/div&gt; &lt;\/div&gt; <\/code><\/pre>\n<p>  \u0418\u043b\u0438 \u0436\u0435 \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0432 csrf \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Postman. \u0410 \u043f\u043e\u0442\u043e\u043c \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, \u043f\u0443\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438, \u0438 \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f. <\/p>\n<h4>\u0421\u0435\u0441\u0441\u0438\u0438<\/h4>\n<p>  \u0414\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u0432 Sails \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u0435\u0441\u0441\u0438\u0439 \u2014 \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e (\u0435\u0441\u043b\u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0441 cookie) \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0441\u0435\u0441\u0441\u0438\u0439 \u0441\u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0435\u0441\u0441\u0438\u0438 \u0438 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0442\u044c \u0438\u0445. \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. \u0412\u043e\u0442 \u043a\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.  <\/p>\n<pre><code class=\"javascript\">var passwordHash = require('password-hash');  module.exports = {   \t\/\/ @API \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0435\u0441\u0441\u0438\u0438  \tcreate: function (req, res) { \t\t\/** \t\t * \u0417\u0430\u0434\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \t\t * \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043b\u043e\u0433\u0438\u043d \t\t * \u0438 \u043f\u0430\u0440\u043e\u043b\u044c \t\t *\/ \t\tvar username = req.param('username'), \t\t\tpassword = req.param('password');  \t\t\/** \t\t * \u0415\u0441\u043b\u0438 \u043d\u0435\u0442 \u043b\u043e\u0433\u0438\u043d\u0430 \u0438\u043b\u0438 \u043f\u0430\u0440\u043e\u043b\u044f \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \t\t * \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043e\u0448\u0438\u0431\u043a\u0443, \u0438 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \t\t * (\u043f\u0440\u0438\u043c. \u0437\u0434\u0435\u0441\u044c \u043b\u0443\u0447\u0448\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \t\t * \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 flash) \t\t *\/  \t\tif (!username || !password) { \t\t\treturn res.redirect('\/session'); \t\t};  \t\t\/** \t\t * \u041d\u0430\u0439\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u0437 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043b\u043e\u0433\u0438\u043d\u0430 \t\t * (username - req.param('username')) \t\t * \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0430\u0439\u0434\u0435\u043d \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f  \t\t * \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u043e\u043b\u044f \u0441 \u043f\u0430\u0440\u043e\u043b\u0435\u043c \t\t * \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c, \u0435\u0441\u043b\u0438 \u043e\u043d \t\t * \u0432\u0430\u043b\u0438\u0434\u0435\u043d, \u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0441\u0442\u0430\u0442\u0443\u0441 -  \t\t * \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u0438\u043b\u0438 \u043d\u0435\u0442, \u0438 \u0434\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0443\u043f \u043a \t\t * \u0434\u0430\u043d\u043d\u044b\u043c \u0447\u0435\u0440\u0435\u0437 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u0441\u0435\u0441\u0441\u0438\u0438. \u042d\u0442\u043e \t\t * \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443 \t\t * \u0434\u043b\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c  \t\t * \u0440\u0430\u0437\u0434\u0435\u043b\u0430\u043c \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u043b\u043e\u0433\u0430 (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0435\u0441\u0441\u0438\u0438) \t\t *\/ \t\tUser.findOneByUsername(username).exec(function (err, user) { \t\t\tif (!user || err) return res.send(500); \t\t\tif (passwordHash.verify(password, user.encryptPassword)) { \t\t\t\t\/\/ \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0441\u0435\u0441\u0441\u0438\u0438                                 \/\/ \u0414\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e                                  \/\/ \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u0437 \u0441\u0435\u0441\u0441\u0438\u0438 \t\t\t\treq.session.auth = true; \t\t\t\treq.session.User = user; \t\t\t\t \t\t\t\tif (req.session.User.admin) { \t\t\t\t\treturn res.redirect('\/admin'); \t\t\t\t}; \t\t\t}; \t\t}); \t}, \t\/** \t * \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u044b\u0445\u043e\u0434 \u0438\u0437 \u0441\u0435\u0441\u0441\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0439  \t * \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442 \u0435\u0441\u0442\u044c \u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \t * \u0432 \u043e\u043d\u043b\u0430\u0439\u043d\u0435, \u0438 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u0442 \u0441\u0435\u0441\u0441\u0438\u044e \t *\/ \tdestroy: function (req, res) { \t\tUser.findOne(req.session.User.id).exec(function (err, user) { \t\t\tif (user) { \t\t\t\treq.session.destroy(); \t\t\t\tres.redirect('\/'); \t\t\t} else { res.redirect('\/login'); }; \t\t}); \t},  \t\/\/ @MAIN  \tindex: function (req, res) { \t\tres.view(); \t} }; <\/code><\/pre>\n<h5>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043f\u0443\u0442\u0435\u0439<\/h5>\n<p>  <\/p>\n<pre><code class=\"javascript\">  '\/login'    : 'SessionController',   '\/logout'   : {     controller: 'session',     action: 'destroy'   }, <\/code><\/pre>\n<h5>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/h5>\n<p>  \u0418 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0432\u0445\u043e\u0434\u0430  <\/p>\n<pre><code class=\"html\">&lt;div class=&quot;container&quot;&gt; \t&lt;div class=&quot;row&quot;&gt; \t\t&lt;div class=&quot;col-md-4&quot;&gt;&lt;\/div&gt; \t\t&lt;div class=&quot;col-md-4 text-center&quot;&gt; \t\t\t&lt;h2&gt;Sign-in form&lt;\/h2&gt;&lt;hr&gt; \t\t\t&lt;form action=&quot;\/session\/create&quot; method=&quot;POST&quot;&gt; \t\t\t\t&lt;input type=&quot;text&quot; name=&quot;username&quot; placeholder=&quot;Username&quot; class=&quot;form-control&quot; \/&gt;&lt;br&gt; \t\t\t\t&lt;input type=&quot;password&quot; name=&quot;password&quot; placeholder=&quot;password&quot; class=&quot;form-control&quot; \/&gt;&lt;br&gt; \t\t\t\t&lt;input type=&quot;submit&quot; class=&quot;btn btn-default&quot; value=&quot;Log-In&quot; \/&gt; \t\t\t\t&lt;input type=&quot;hidden&quot; name=&quot;_csrf&quot; value=&quot;&lt;%= _csrf %&gt;&quot; \/&gt; \t\t\t&lt;\/form&gt; \t\t&lt;\/div&gt; \t\t&lt;div class=&quot;col-md-4&quot;&gt;&lt;\/div&gt; \t&lt;\/div&gt; &lt;\/div&gt; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0435\u0441\u0441\u0438\u0438 (\u0432\u0445\u043e\u0434\u0438\u0442\u044c \u0441 \u0441\u0438\u0441\u0442\u0435\u043c\u0443), \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0430\u0434\u043c\u0438\u043d \u043f\u0430\u043d\u0435\u043b\u044c\u043a\u0438, \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443 \u0440\u0430\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430. \u0418 \u0442\u0430\u043a \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0438\u0439 \u044d\u0442\u0430\u043f.<\/p>\n<h4>\u0410\u0434\u043c\u0438\u043d \u041f\u0430\u043d\u0435\u043b\u044c \u0438 \u0420\u0430\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u041f\u0440\u0430\u0432<\/h4>\n<p>  \u0423 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u0430\u0434\u043c\u0438\u043d\u043a\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u0441\u0442\u043e\u0432, \u0438 \u0444\u043e\u0440\u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430. \u0410 \u0442\u0430\u043a\u0436\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u0434\u043b\u044f \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043f\u043e\u0441\u0442\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 <i>admin<\/i>. \u0412\u043e\u0442 \u043a\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.  <\/p>\n<pre><code class=\"javascript\">module.exports = { \t \tindex: function (req, res) { \t\tPost.find() \t\t\t.sort('id DESC') \t\t\t.exec(function (err, posts) { \t\t\t\tif (err) return res.send(500); \t\t\t\tres.view({ \t\t\t\t\tposts: posts \t\t\t\t}); \t\t\t}); \t},  \tedit: function (req, res) { \t\tvar Id = req.param('id');  \t\tPost.findOne(Id).exec(function (err, post) { \t\t\tif (!post) return res.send(404); \t\t\tif (err) return res.send(500); \t\t\tres.view({ \t\t\t\tpost: post \t\t\t}); \t\t}); \t} }; <\/code><\/pre>\n<p>  \u0418 2 \u043d\u0430\u0448\u0438\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f. <\/p>\n<h6>views\/admin\/index.ejs<\/h6>\n<p>  <\/p>\n<pre><code class=\"html\">&lt;div class=&quot;container text-center&quot;&gt; \t&lt;h2&gt;CREATE NEW&lt;\/h2&gt;&lt;br&gt; \t&lt;div class=&quot;row&quot;&gt; \t\t&lt;form action=&quot;\/post\/create&quot; method=&quot;POST&quot;&gt; \t\t\t&lt;div class=&quot;col-md-6&quot;&gt; \t\t\t\t&lt;input class=&quot;form-control&quot; type=&quot;text&quot; name=&quot;title&quot; placeholder=&quot;Title Post&quot;&gt;&lt;hr&gt; \t\t\t\t&lt;textarea rows=&quot;3&quot; class=&quot;form-control&quot; name=&quot;description&quot; placeholder=&quot;Description&quot;&gt;&lt;\/textarea&gt; \t\t\t&lt;\/div&gt; \t\t\t&lt;div class=&quot;col-md-6&quot;&gt; \t\t\t\t&lt;textarea rows=&quot;7&quot; class=&quot;form-control&quot; name=&quot;content&quot; placeholder=&quot;Content&quot;&gt;&lt;\/textarea&gt; \t\t\t&lt;\/div&gt; \t\t\t&lt;div class=&quot;col-md-12&quot;&gt; \t\t\t\t&lt;input type=&quot;hidden&quot; name=&quot;_csrf&quot; value=&quot;&lt;%= _csrf %&gt;&quot; \/&gt; \t\t\t\t&lt;br&gt;&lt;input type=&quot;submit&quot; class=&quot;btn btn-success&quot; value=&quot;CREATE&quot; \/&gt; \t\t\t&lt;\/div&gt; \t\t&lt;\/form&gt; \t&lt;\/div&gt;&lt;br&gt; \t&lt;h2&gt;POST LIST&lt;\/h2&gt; \t&lt;table class=&quot;table text-left&quot;&gt; \t\t&lt;tr&gt; \t\t\t&lt;th&gt;ID&lt;\/th&gt; \t\t\t&lt;th&gt;TITLE&lt;\/th&gt; \t\t\t&lt;th&gt;&lt;\/th&gt; \t\t\t&lt;th&gt;&lt;\/th&gt; \t\t\t&lt;th&gt;&lt;\/th&gt; \t\t&lt;\/tr&gt; \t\t&lt;% _.each(posts, function (post) { %&gt; \t\t\t&lt;tr&gt; \t\t\t\t&lt;td&gt;&lt;%= post.id %&gt;&lt;\/td&gt; \t\t\t\t&lt;td&gt;&lt;%= post.title %&gt;&lt;\/td&gt; \t\t\t\t&lt;td&gt;&lt;a href=&quot;\/post\/watch\/&lt;%= post.id %&gt;&quot; class=&quot;btn btn-info&quot;&gt;Look&lt;\/a&gt;&lt;\/td&gt; \t\t\t\t&lt;td&gt;&lt;a href=&quot;\/post\/delete\/&lt;%= post.id %&gt;&quot; class=&quot;btn btn-danger&quot;&gt;Delete&lt;\/a&gt;&lt;\/td&gt; \t\t\t\t&lt;td&gt;&lt;a href=&quot;\/admin\/edit\/&lt;%= post.id %&gt;&quot; class=&quot;btn btn-warning&quot;&gt;Edit&lt;\/a&gt;&lt;\/td&gt; \t\t\t&lt;\/tr&gt;\t\t\t \t\t&lt;% }) %&gt; \t&lt;\/table&gt; &lt;\/div&gt; <\/code><\/pre>\n<h6>views\/admin\/edit.ejs<\/h6>\n<p>  <\/p>\n<pre><code class=\"html\">&lt;div class=&quot;container&quot;&gt; \t&lt;div class=&quot;row&quot;&gt; \t\t&lt;div class=&quot;col-md-2&quot;&gt;&lt;\/div&gt; \t\t&lt;div class=&quot;col-md-8 well text-center&quot;&gt; \t\t\t&lt;form action=&quot;\/post\/update&quot; method=&quot;POST&quot;&gt; \t\t\t\t&lt;h4&gt;Title&lt;\/h4&gt; \t\t\t\t&lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;title&quot; value=&quot;&lt;%= post.title %&gt;&quot;&gt;&lt;br&gt; \t\t\t\t&lt;h4&gt;Description&lt;\/h4&gt; \t\t\t\t&lt;textarea rows=&quot;3&quot; name=&quot;description&quot; class=&quot;form-control&quot; value=&quot;&lt;%= post.description %&gt;&quot;&gt;&lt;\/textarea&gt; \t\t\t\t&lt;h4&gt;Content&lt;\/h4&gt; \t\t\t\t&lt;textarea rows=&quot;7&quot; name=&quot;content&quot; class=&quot;form-control&quot; value=&quot;&lt;%= post.content %&gt;&quot;&gt;&lt;\/textarea&gt; \t\t\t\t&lt;input type=&quot;hidden&quot; name=&quot;_csrf&quot; value=&quot;&lt;%= _csrf %&gt;&quot; \/&gt;&lt;br&gt; \t\t\t\t&lt;input type=&quot;submit&quot; class=&quot;btn btn-success&quot; value=&quot;Update&quot;&gt; \t\t\t&lt;\/form&gt; \t\t&lt;\/div&gt; \t\t&lt;div class=&quot;col-md-2&quot;&gt;&lt;\/div&gt; \t&lt;\/div&gt; &lt;\/div&gt; <\/code><\/pre>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0439\u043c\u0435\u043c\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438.<\/p>\n<h5>\u041f\u043e\u043b\u0438\u0442\u0438\u043a\u0430<\/h5>\n<p>  <a href=\"http:\/\/beta.sailsjs.org\/#\/documentation\/reference\/Policies\">\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u0440\u0430\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f<\/a> \u043f\u0440\u0430\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0432 Sails \u0432\u0435\u0441\u044c\u043c\u0430 \u0443\u0434\u043e\u0431\u043d\u0430 \u0438 \u043f\u0440\u043e\u0441\u0442\u0430 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0438\u0448\u044c \u0441\u0432\u0435\u0440\u0438\u0442\u044c \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c:  <\/p>\n<ul>\n<li>\u0411\u044b\u043b \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d<\/li>\n<li>\u0418 \u044f\u0432\u043b\u044f\u043b\u0441\u044f \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u043e\u043c<\/li>\n<\/ul>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u044c \u044d\u0442\u043e \u0432 \u043a\u043e\u0434\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b \u043d\u0430\u0448\u0435\u0439 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u2014 <i>api\/policies\/admin.js<\/i>. \u0418 \u0432\u043e\u0442 \u043a\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e \u0440\u0430\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u0435\u043b\u044f.  <\/p>\n<pre><code class=\"javascript\">module.exports = function (req, res, ok) { \tif (req.session.auth && req.session.User.admin) { \t\treturn ok(); \t} else { \t\treturn res.redirect('\/login'); \t}; } <\/code><\/pre>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u043b\u043b\u0431\u0435\u043a \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f. \u0435\u0441\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u044b\u0439 \u2014 \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u0442\u044c \u0438 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0432\u0445\u043e\u0434\u0430. \u0414\u043b\u044f \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u043d\u0430\u0448\u0435\u0439 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u2014 \u043e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 \u0444\u0430\u0439\u043b <i>config\/policies.js<\/i> \u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0438\u0442\u0435 \u0435\u0433\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434.  <\/p>\n<pre><code class=\"javascript\"> module.exports.policies = {    \/\/ Default policy for all controllers and actions   \/\/ (`true` allows public access)   '*': true,    \/**    * \u0412\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430    * Admin \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443 admin.js, \u043a\u043e\u0442\u043e\u0440\u0430\u044f    * \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f.    *\/    AdminController: {   \t'*': 'admin'   },    UserController: {   \tcreate: 'admin'   },    PostController: {   \t\/\/ \u0422\u043e \u0447\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0432\u0438\u0434\u0435\u0442\u044c \u0432\u0441\u0435   \tindex  : true,   \tpage   : true,   \twatch  : true,    \t\/\/ \u0422\u043e \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0430\u0434\u043c\u0438\u043d   \tcreate : 'admin',   \tupdate : 'admin',   \tdelete : 'admin',   } }; <\/code><\/pre>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u043c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0431\u043b\u043e\u0433\u0430 \u043d\u0430 Sails, \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0432 \u043d\u0435\u043c \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0438 \u0437\u0430\u0449\u0438\u0442\u044b \u2014 \u043d\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a (\u0434\u0430\u0436\u0435 flash \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439), \u043d\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0439 \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u0430\u0434\u043c\u0438\u043d\u043a\u0438, \u043d\u043e \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0440\u0430\u0441c\u0447\u0438\u0442\u0430\u043d\u0430 \u043a\u0430\u043a \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u0432\u0432\u043e\u0434\u043d\u044b\u0439 \u043a\u0443\u0440\u0441 \u0432 \u044d\u0442\u043e\u0442 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a, \u0434\u0430\u043b\u044c\u0448\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0437\u0443\u0447\u0430\u0442\u044c \u0435\u0433\u043e \u0441\u0430\u043c\u0438. \u0412 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043d\u0430\u0440\u0430\u0441\u0442\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0432\u0430\u043c \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0442\u0440\u0443\u0434\u0430.      \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/224403\/\"> http:\/\/habrahabr.ru\/post\/224403\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">     \t<habracut\/><\/p>\n<h4>\u0421\u0438\u043d\u043e\u043f\u0441\u0438\u0441<\/h4>\n<p>  <\/p>\n<ul>\n<li><a href=\"http:\/\/habrahabr.ru\/post\/224195\/\">\u041f\u0435\u0440\u0432\u0430\u044f \u0427\u0430\u0441\u0442\u044c<\/a><\/li>\n<\/ul>\n<p>  \u0420\u0430\u043d\u0435\u0435 \u043c\u044b \u0438\u0437\u0443\u0447\u0438\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u044b \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u043b\u043e\u0433\u0430, \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043e\u0441\u043d\u043e\u0432\u044b \u043c\u044b \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043b\u0438\u0441\u044c \u0441 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0441\u0442\u0430\u0442\u0438\u043a\u0438, \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u0434\u0430 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u0423\u0437\u043d\u0430\u043b\u0438 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f\u043c\u0438 \u043f\u0443\u0442\u0435\u0439 (<i>routes.js<\/i>), \u0438 \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u0432 SailsJS. \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0431\u043b\u043e\u0433\u0430 \u043d\u0430 SailsJS, \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0443\u043d\u043a\u0442\u044b: \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435. \u0421\u0435\u0441\u0441\u0438\u0438: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 (\u0432\u0445\u043e\u0434), \u0440\u0430\u0437\u0440\u044b\u0432 (\u0432\u044b\u0445\u043e\u0434). \u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0410\u0434\u043c\u0438\u043d \u041f\u0430\u043d\u0435\u043b\u0438, \u0438 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u043e\u0439 \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430.<\/p>\n<h4>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438<\/h4>\n<p>  \u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0441\u0430 API \u0432\u0432\u043e\u0434\u0438\u043c \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u0443\u044e \u043d\u0430\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0432 \u043a\u043e\u0440\u043d\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430.  <\/p>\n<pre><code class=\"bash\">sails generate api user <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043f\u0440\u0438 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u043e\u043b\u044c, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c <i><a href=\"https:\/\/www.npmjs.org\/package\/password-hash\">password-hash<\/a><\/i>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u0427\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u2014 \u0432 \u043a\u043e\u0440\u043d\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432\u0432\u0435\u0434\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443  <\/p>\n<pre><code class=\"bash\">npm install password-hash --save <\/code><\/pre>\n<p>  \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <i>&#8212;save<\/i> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0442\u043e \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u044c \u043a\u0430\u043a \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0432 <i>package.json<\/i>.<\/p>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0443\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043d\u0430\u0432\u044b\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u043c\u0438 \u0432 SailsJS \u2014 \u0433\u0434\u0435 \u043e\u043d\u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f, \u0438 \u043a\u0430\u043a \u0438\u0445 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c, \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u043d\u0430 \u0443\u0436\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0435 \u0432\u0435\u0449\u0438.<\/p>\n<h5>\u041c\u043e\u0434\u0435\u043b\u044c<\/h5>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432:  <\/p>\n<ol>\n<li>\u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f <\/li>\n<li>\u041f\u0430\u0440\u043e\u043b\u044c<\/li>\n<li>\u0410\u0434\u043c\u0438\u043d \u2014 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0434\u043e\u0441\u0442\u0443\u043f\u0430<\/li>\n<\/ol>\n<p>  \u041f\u0440\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0442\u0430\u043a\u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u0440\u043e\u043b\u044f \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 <a href=\"https:\/\/github.com\/balderdashy\/waterline#lifecycle-callbacks\">\u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u043c\u0438 \u0446\u0438\u043a\u043b\u0430\u043c\u0438<\/a> \u043c\u043e\u0434\u0435\u043b\u0435\u0439  <\/p>\n<pre><code class=\"javascript\">var passwordHash = require('password-hash');  var User = {    attributes: {  \tusername: {type: 'string', required: true, unique: true}, \tpassword: {type: 'string', required: true, minLength: 8},      admin: {       type: 'boolean',       defaultsTo: false     },     toJSON: function() {     \tvar element = this.toObject();     \tdelete element.password;     \treturn element;     }    },    beforeCreate: function (values, next) {     \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u043f\u0430\u0440\u043e\u043b\u044f \u0432 \u0411\u0414     var mainPass = passwordHash.generate(values.password);     values.encryptPassword = mainPass;     next();  \t   }  };  module.exports = User;  <\/code><\/pre>\n<p>  \u0414\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u2014 <i>encryptedPassword<\/i>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u043f\u0430\u0440\u043e\u043b\u044f. <\/p>\n<h5>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440<\/h5>\n<p>  \u0412 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443. \u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0430\u043c\u0438 \u043f\u043e \u043f\u043e\u0434\u043e\u0431\u0438\u044e \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u043f\u043e\u0441\u0442\u043e\u0432. \u0412\u043e\u0442 \u043a\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.  <\/p>\n<pre><code class=\"javascript\"> module.exports = {  \t\/\/@API - \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f  \t\/** \t * \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \t * \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \t * \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u0430\u0440\u043e\u043b\u044c, \u0438 \u0431\u0443\u043b\u0435\u0432\u043e\u0435 \t * \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u0434\u043c\u0438\u043d. \u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \t * \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043e\u043d \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f \t * \u0432 \u0441\u0435\u0441\u0441\u0438\u0438. \u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f  \t * \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443 \t * admin (api\/policies\/admin.js) \u0447\u0442\u043e\u0431\u044b \u043a \t * \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043c\u043e\u0433\u043b\u0438 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \t * \u043d\u0435 \u043f\u0440\u0438\u0432\u0435\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \t *\/ \t  \tcreate: function (req, res) { \t\tvar elem = { \t\t\tusername : req.param('username'), \t\t\tpassword : req.param('password'), \t\t\tadmin    : req.param('admin') \t\t};  \t\tUser.create(elem).exec(function (err, user) { \t\t\tif (err) return res.send(500); \t\t\treq.session.auth = true; \t\t\tres.redirect('\/'); \t\t}); \t},  \t\/\/ @MAIN \tindex: function (req, res) { \t\tres.view(); \t} };  <\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043f\u0443\u0442\u0435\u0439 (<i>config\/routes.js<\/i>) \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435.  <\/p>\n<pre><code class=\"javascript\">  '\/register' : 'UserController', <\/code><\/pre>\n<p>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0437\u0430\u0449\u0438\u0442\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u043c \u0437\u0430\u0449\u0438\u0442\u0443 <a href=\"http:\/\/ru.wikipedia.org\/wiki\/CSRF\"><i>CSRF<\/i><\/a> \u0432 \u0444\u0430\u0439\u043b\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 (<i>config\/csrf.js<\/i>) \u043e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c  <\/p>\n<pre><code class=\"javascript\">module.exports.csrf = true; <\/code><\/pre>\n<h5>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 (<i>views\/user\/index.ejs<\/i>)<\/h5>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443.  <\/p>\n<pre><code class=\"html\">&lt;div class=&quot;container&quot;&gt; \t&lt;div class=&quot;row&quot;&gt; \t\t&lt;div class=&quot;col-md-4&quot;&gt;&lt;\/div&gt; \t\t&lt;div class=&quot;col-md-4&quot;&gt; \t\t\t&lt;div class=&quot;panel panel-default&quot;&gt; \t\t\t\t&lt;div class=&quot;panel-body&quot;&gt; \t\t\t\t\t&lt;form action=&quot;\/user\/create&quot; method=&quot;post&quot;&gt; \t\t\t\t\t\t&lt;input type=&quot;text&quot; name=&quot;username&quot; placeholder=&quot;\u0418\u043c\u044f \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f&quot;&gt;&lt;br&gt; \t\t\t\t\t\t&lt;input type=&quot;password&quot; name=&quot;password&quot; placeholder=&quot;\u041f\u0430\u0440\u043e\u043b\u044c&quot;&gt;&lt;br&gt; \t\t\t\t\t\t&lt;input type=&quot;hidden&quot; name=&quot;_csrf&quot; value=&quot;&lt;%= _csrf %&gt;&quot;&gt; \t\t\t\t\t\t&lt;!-- \u041f\u043e\u043b\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 --&gt; \t\t\t\t\t\t&lt;input type=&quot;hidden&quot; name=&quot;admin&quot; value=&quot;true&quot;&gt; \t\t\t\t\t\t \t\t\t\t\t\t&lt;input type=&quot;submit&quot; class=&quot;btn btn-success btn-block&quot; value=&quot;\u0417\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f&quot;&gt; \t\t\t\t\t&lt;\/form&gt; \t\t\t\t&lt;\/div&gt; \t\t\t&lt;\/div&gt; \t\t&lt;\/div&gt; \t\t&lt;div class=&quot;col-md-4&quot;&gt;&lt;\/div&gt; \t&lt;\/div&gt; &lt;\/div&gt; <\/code><\/pre>\n<p>  \u0418\u043b\u0438 \u0436\u0435 \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0432 csrf \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Postman. \u0410 \u043f\u043e\u0442\u043e\u043c \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, \u043f\u0443\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438, \u0438 \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f. <\/p>\n<h4>\u0421\u0435\u0441\u0441\u0438\u0438<\/h4>\n<p>  \u0414\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u0432 Sails \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0441\u0435\u0441\u0441\u0438\u0439 \u2014 \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e (\u0435\u0441\u043b\u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u0441 cookie) \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0441\u0435\u0441\u0441\u0438\u0439 \u0441\u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0435\u0441\u0441\u0438\u0438 \u0438 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0442\u044c \u0438\u0445. \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. \u0412\u043e\u0442 \u043a\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.  <\/p>\n<pre><code class=\"javascript\">var passwordHash = require('password-hash');  module.exports = {   \t\/\/ @API \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0435\u0441\u0441\u0438\u0438  \tcreate: function (req, res) { \t\t\/** \t\t * \u0417\u0430\u0434\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \t\t * \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043b\u043e\u0433\u0438\u043d \t\t * \u0438 \u043f\u0430\u0440\u043e\u043b\u044c \t\t *\/ \t\tvar username = req.param('username'), \t\t\tpassword = req.param('password');  \t\t\/** \t\t * \u0415\u0441\u043b\u0438 \u043d\u0435\u0442 \u043b\u043e\u0433\u0438\u043d\u0430 \u0438\u043b\u0438 \u043f\u0430\u0440\u043e\u043b\u044f \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \t\t * \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043e\u0448\u0438\u0431\u043a\u0443, \u0438 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \t\t * (\u043f\u0440\u0438\u043c. \u0437\u0434\u0435\u0441\u044c \u043b\u0443\u0447\u0448\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \t\t * \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 flash) \t\t *\/  \t\tif (!username || !password) { \t\t\treturn res.redirect('\/session'); \t\t};  \t\t\/** \t\t * \u041d\u0430\u0439\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u0437 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043b\u043e\u0433\u0438\u043d\u0430 \t\t * (username - req.param('username')) \t\t * \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0430\u0439\u0434\u0435\u043d \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f  \t\t * \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u043e\u043b\u044f \u0441 \u043f\u0430\u0440\u043e\u043b\u0435\u043c \t\t * \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c, \u0435\u0441\u043b\u0438 \u043e\u043d \t\t * \u0432\u0430\u043b\u0438\u0434\u0435\u043d, \u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0441\u0442\u0430\u0442\u0443\u0441 -  \t\t * \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u0438\u043b\u0438 \u043d\u0435\u0442, \u0438 \u0434\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0443\u043f \u043a \t\t * \u0434\u0430\u043d\u043d\u044b\u043c \u0447\u0435\u0440\u0435\u0437 \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u0441\u0435\u0441\u0441\u0438\u0438. \u042d\u0442\u043e \t\t * \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443 \t\t * \u0434\u043b\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c  \t\t * \u0440\u0430\u0437\u0434\u0435\u043b\u0430\u043c \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u043b\u043e\u0433\u0430 (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0435\u0441\u0441\u0438\u0438) \t\t *\/ \t\tUser.findOneByUsername(username).exec(function (err, user) { \t\t\tif (!user || err) return res.send(500); \t\t\tif (passwordHash.verify(password, user.encryptPassword)) { \t\t\t\t\/\/ \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0441\u0435\u0441\u0441\u0438\u0438                                 \/\/ \u0414\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e                                  \/\/ \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u0437 \u0441\u0435\u0441\u0441\u0438\u0438 \t\t\t\treq.session.auth = true; \t\t\t\treq.session.User = user; \t\t\t\t \t\t\t\tif (req.session.User.admin) { \t\t\t\t\treturn res.redirect('\/admin'); \t\t\t\t}; \t\t\t}; \t\t}); \t}, \t\/** \t * \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u044b\u0445\u043e\u0434 \u0438\u0437 \u0441\u0435\u0441\u0441\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0439  \t * \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442 \u0435\u0441\u0442\u044c \u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \t * \u0432 \u043e\u043d\u043b\u0430\u0439\u043d\u0435, \u0438 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u0442 \u0441\u0435\u0441\u0441\u0438\u044e \t *\/ \tdestroy: function (req, res) { \t\tUser.findOne(req.session.User.id).exec(function (err, user) { \t\t\tif (user) { \t\t\t\treq.session.destroy(); \t\t\t\tres.redirect('\/'); \t\t\t} else { res.redirect('\/login'); }; \t\t}); \t},  \t\/\/ @MAIN  \tindex: function (req, res) { \t\tres.view(); \t} }; <\/code><\/pre>\n<h5>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043f\u0443\u0442\u0435\u0439<\/h5>\n<p>  <\/p>\n<pre><code class=\"javascript\">  '\/login'    : 'SessionController',   '\/logout'   : {     controller: 'session',     action: 'destroy'   }, <\/code><\/pre>\n<h5>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/h5>\n<p>  \u0418 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0432\u0445\u043e\u0434\u0430  <\/p>\n<pre><code class=\"html\">&lt;div class=&quot;container&quot;&gt; \t&lt;div class=&quot;row&quot;&gt; \t\t&lt;div class=&quot;col-md-4&quot;&gt;&lt;\/div&gt; \t\t&lt;div class=&quot;col-md-4 text-center&quot;&gt; \t\t\t&lt;h2&gt;Sign-in form&lt;\/h2&gt;&lt;hr&gt; \t\t\t&lt;form action=&quot;\/session\/create&quot; method=&quot;POST&quot;&gt; \t\t\t\t&lt;input type=&quot;text&quot; name=&quot;username&quot; placeholder=&quot;Username&quot; class=&quot;form-control&quot; \/&gt;&lt;br&gt; \t\t\t\t&lt;input type=&quot;password&quot; name=&quot;password&quot; placeholder=&quot;password&quot; class=&quot;form-control&quot; \/&gt;&lt;br&gt; \t\t\t\t&lt;input type=&quot;submit&quot; class=&quot;btn btn-default&quot; value=&quot;Log-In&quot; \/&gt; \t\t\t\t&lt;input type=&quot;hidden&quot; name=&quot;_csrf&quot; value=&quot;&lt;%= _csrf %&gt;&quot; \/&gt; \t\t\t&lt;\/form&gt; \t\t&lt;\/div&gt; \t\t&lt;div class=&quot;col-md-4&quot;&gt;&lt;\/div&gt; \t&lt;\/div&gt; &lt;\/div&gt; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0435\u0441\u0441\u0438\u0438 (\u0432\u0445\u043e\u0434\u0438\u0442\u044c \u0441 \u0441\u0438\u0441\u0442\u0435\u043c\u0443), \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0430\u0434\u043c\u0438\u043d \u043f\u0430\u043d\u0435\u043b\u044c\u043a\u0438, \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443 \u0440\u0430\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430. \u0418 \u0442\u0430\u043a \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0438\u0439 \u044d\u0442\u0430\u043f.<\/p>\n<h4>\u0410\u0434\u043c\u0438\u043d \u041f\u0430\u043d\u0435\u043b\u044c \u0438 \u0420\u0430\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u041f\u0440\u0430\u0432<\/h4>\n<p>  \u0423 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u0430\u0434\u043c\u0438\u043d\u043a\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u0441\u0442\u043e\u0432, \u0438 \u0444\u043e\u0440\u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430. \u0410 \u0442\u0430\u043a\u0436\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u0434\u043b\u044f \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043f\u043e\u0441\u0442\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 <i>admin<\/i>. \u0412\u043e\u0442 \u043a\u043e\u0434 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.  <\/p>\n<pre><code class=\"javascript\">module.exports = { \t \tindex: function (req, res) { \t\tPost.find() \t\t\t.sort('id DESC') \t\t\t.exec(function (err, posts) { \t\t\t\tif (err) return res.send(500); \t\t\t\tres.view({ \t\t\t\t\tposts: posts \t\t\t\t}); \t\t\t}); \t},  \tedit: function (req, res) { \t\tvar Id = req.param('id');  \t\tPost.findOne(Id).exec(function (err, post) { \t\t\tif (!post) return res.send(404); \t\t\tif (err) return res.send(500); \t\t\tres.view({ \t\t\t\tpost: post \t\t\t}); \t\t}); \t} }; <\/code><\/pre>\n<p>  \u0418 2 \u043d\u0430\u0448\u0438\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f. <\/p>\n<h6>views\/admin\/index.ejs<\/h6>\n<p>  <\/p>\n<pre><code class=\"html\">&lt;div class=&quot;container text-center&quot;&gt; \t&lt;h2&gt;CREATE NEW&lt;\/h2&gt;&lt;br&gt; \t&lt;div class=&quot;row&quot;&gt; \t\t&lt;form action=&quot;\/post\/create&quot; method=&quot;POST&quot;&gt; \t\t\t&lt;div class=&quot;col-md-6&quot;&gt; \t\t\t\t&lt;input class=&quot;form-control&quot; type=&quot;text&quot; name=&quot;title&quot; placeholder=&quot;Title Post&quot;&gt;&lt;hr&gt; \t\t\t\t&lt;textarea rows=&quot;3&quot; class=&quot;form-control&quot; name=&quot;description&quot; placeholder=&quot;Description&quot;&gt;&lt;\/textarea&gt; \t\t\t&lt;\/div&gt; \t\t\t&lt;div class=&quot;col-md-6&quot;&gt; \t\t\t\t&lt;textarea rows=&quot;7&quot; class=&quot;form-control&quot; name=&quot;content&quot; placeholder=&quot;Content&quot;&gt;&lt;\/textarea&gt; \t\t\t&lt;\/div&gt; \t\t\t&lt;div class=&quot;col-md-12&quot;&gt; \t\t\t\t&lt;input type=&quot;hidden&quot; name=&quot;_csrf&quot; value=&quot;&lt;%= _csrf %&gt;&quot; \/&gt; \t\t\t\t&lt;br&gt;&lt;input type=&quot;submit&quot; class=&quot;btn btn-success&quot; value=&quot;CREATE&quot; \/&gt; \t\t\t&lt;\/div&gt; \t\t&lt;\/form&gt; \t&lt;\/div&gt;&lt;br&gt; \t&lt;h2&gt;POST LIST&lt;\/h2&gt; \t&lt;table class=&quot;table text-left&quot;&gt; \t\t&lt;tr&gt; \t\t\t&lt;th&gt;ID&lt;\/th&gt; \t\t\t&lt;th&gt;TITLE&lt;\/th&gt; \t\t\t&lt;th&gt;&lt;\/th&gt; \t\t\t&lt;th&gt;&lt;\/th&gt; \t\t\t&lt;th&gt;&lt;\/th&gt; \t\t&lt;\/tr&gt; \t\t&lt;% _.each(posts, function (post) { %&gt; \t\t\t&lt;tr&gt; \t\t\t\t&lt;td&gt;&lt;%= post.id %&gt;&lt;\/td&gt; \t\t\t\t&lt;td&gt;&lt;%= post.title %&gt;&lt;\/td&gt; \t\t\t\t&lt;td&gt;&lt;a href=&quot;\/post\/watch\/&lt;%= post.id %&gt;&quot; class=&quot;btn btn-info&quot;&gt;Look&lt;\/a&gt;&lt;\/td&gt; \t\t\t\t&lt;td&gt;&lt;a href=&quot;\/post\/delete\/&lt;%= post.id %&gt;&quot; class=&quot;btn btn-danger&quot;&gt;Delete&lt;\/a&gt;&lt;\/td&gt; \t\t\t\t&lt;td&gt;&lt;a href=&quot;\/admin\/edit\/&lt;%= post.id %&gt;&quot; class=&quot;btn btn-warning&quot;&gt;Edit&lt;\/a&gt;&lt;\/td&gt; \t\t\t&lt;\/tr&gt;\t\t\t \t\t&lt;% }) %&gt; \t&lt;\/<\/code><\/pre>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-224403","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/224403","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=224403"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/224403\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=224403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=224403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=224403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}