{"_id":"@aytacworld/express-module-login","_rev":"1-11911169742557859a6ba818e023ac98","name":"@aytacworld/express-module-login","dist-tags":{"latest":"2.0.0"},"versions":{"2.0.0":{"name":"@aytacworld/express-module-login","version":"2.0.0","description":"Adding login feature to express server","main":"index.js","repository":{"type":"git","url":"https://git.aytacworld.com/aytacworld/express"},"author":{"name":"Adem Aytaç","email":"adem@aytacworld.com","url":"https://aytacworld.com"},"license":"MIT","dependencies":{"express":"^4.17.0"},"_id":"@aytacworld/express-module-login@2.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.15.3","_npmUser":{"name":"aytacworld","email":"adem@aytacworld.com"},"dist":{"integrity":"sha512-7SIDSMu2GOia9En7yTeCDJIdzkdXMraIn7O4PFVyCkqK+6XGdILk6j0Mqtw4mBDLA/O7aiK5ziCGec3zno9dkQ==","shasum":"893212668db6c8c0a4601bc1a9a375ec5689485a","tarball":"https://registry.npmjs.org/@aytacworld/express-module-login/-/express-module-login-2.0.0.tgz","fileCount":4,"unpackedSize":8100,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc4tcyCRA9TVsSAnZWagAAxJ8P/R86DP+nzf2ZU5NLo8js\nGN6WEiDkrHmysIZNSAAUojnDWbfxvyZtpFcMrWdopNTZSWezz5+Uv6yvsJmw\npDtlyFofIiFHr5F2erMzusi2+CapTAMG+BwxH4sPpKEjnJuFjWzizPSScMK0\n75Zu/GomAYpzyZ6kXu5d1zWtpsWrx8NtwN20QIpoLHLzajlzCA2wXWUfLSg5\nsiYtsqhP7foHEk3pMKpk8uBNCyMtjQiwAXhRwXCD5HyVGHGLY67455Lcw7rb\nx5zbeYfdfaZjYCdnb397uPhFsiW02l11xV5DMiimifLhO66YMmNHbdwZsfyM\nKMDm8qYBCQFoZZIn4MB/JctSTC4dzBO4xtacbdZM5DjlT6TYLqgmUp30gWpI\nVW9k8PGYeizu66r47Af1kH+p28KLd3TNlKBf2ArAJlRKAZD0FQfIhnVmeRQ9\n5hnt7IenGZ0LKdwS7giz+1vi32h5Qzi4ZSwWva53MwhEPMjm8TQO4OrwwHS9\nOYvkFKPqXWx/DCO1+tqvfoU592YnYFKR10fpuRdFfu+eyZdh1UoerxzXcY5p\nIsGl/UzbV7VZ/0kqRSxbO69gPT8+Jko8w8IL00ndgdMl4TJbSLm0Qg0RfzBq\nIKk8kjgZXDT+Yj7riiE5HtT7zvFCgyw6phXZTmt3vBm9Y0x66a831iCr6rrf\nqQT/\r\n=eCI7\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDi/lnKIrY1bD4Q/dPqaoZRaLVRr0pGmE0gf12f8Nk01gIgZ6serK4AcgfJ9rIAW5GaiIIUToA+ryLqIjNe/RJVO+k="}]},"maintainers":[{"name":"aytacworld","email":"adem@aytacworld.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/express-module-login_2.0.0_1558370097939_0.2901657802617865"},"_hasShrinkwrap":false}},"time":{"created":"2019-05-20T16:34:57.912Z","2.0.0":"2019-05-20T16:34:58.054Z","modified":"2022-04-04T17:15:02.016Z"},"maintainers":[{"name":"aytacworld","email":"adem@aytacworld.com"}],"description":"Adding login feature to express server","repository":{"type":"git","url":"https://git.aytacworld.com/aytacworld/express"},"author":{"name":"Adem Aytaç","email":"adem@aytacworld.com","url":"https://aytacworld.com"},"license":"MIT","readme":"# @aytacworld/express-module-login\n\nThis module is ment to be used with @aytacworld/express.\n\nIt will add login routes and login services to the application.\n\n## Needed modules\n\nFor this module you need authDb module to be loaded before loading this module.\n\nThe needed modules needs to be loaded before loading login module.\n\nThere are already 2 modules for that purpose.\n\n- [@aytacworld/express-module-memory](https://www.npmjs.com/package/@aytacworld/express-module-memory) uses in-memory database\n- [@aytacworld/express-module-mongo](https://www.npmjs.com/package/@aytacworld/express-module-mongo) uses mongodb\n- or you can create your own. (follow the database structure below)\n\n## Installation\n\nusing npm\n\n`npm i @aytacworld/express-module-login`\n\nusing yarn\n\n`yarn add @aytacworld/express-module-login`\n\n## Usage\n\napp.js\n```javascript\nconst Express = require('@aytacworld/express');\nconst ExpressMongo = require('@aytacworld/express-module-mongo');\nconst ExpressLogin = require('@aytacworld/express-module-login');\nconst myOtherRoutes = require('./routes');\n\nconst app = new Express({});\n\napp.module(ExpressMongo, ExpressLogin);\napp.route('/', myOtherRoutes);\n\napp.listen();\n```\n\nThe following routes will be added.\n\n1. GET /login\n2. POST /login\n3. GET /login/logout\n\nIf you need to check if the user is logged in, you can use the helper module(which is built-in in @aytacworld/express).\n\nroutes.js\n```javascript\nconst path = require('path');\nconst router = require('express').Router();\n\n// login module is added.\nconst Router = (config, { helper, db }) => {\n  helper.addPathToViewEngine(path.resolve(__dirname, 'views'));\n\n  router.get('/', async (req, res) => {\n    res.render('homepage', { user: req.user }); // req.user can be undefined\n  });\n\n  router.get('/profile',\n    helper.isAuthenticated(), // checks whether the user is filled in or not\n    async (req, res) => {\n      res.render('profile', { user: req.user }); // req.user is always filled in\n    });\n\n  return router;\n};\n\nmodule.exports = Router;\n```\n\n## Config\n\n```json\n{\n  \"EXPRESS_MODULE_LOGIN_DISABLE_VIEW\": true, // Boolean, default: undefined, this will don't add default pug files in your project, so you need to create your own login page\n  \"EXPRESS_MODULE_LOGIN_VIEW_NAME\": \"my-custom-login-view\", // String, default: 'aytacworld-express-module-login'\n  \"EXPRESS_MODULE_LOGIN_CSS\": \"/public/login.css\", // String, default: undefined\n}\n```\n\n## Updating login page\n\nThere are 3 ways of updating the login view-page:\n\n1. set `EXPRESS_MODULE_LOGIN_DISABLE_VIEW` to true in your config file and create a `aytacworld-express-module-login.pug` in your views folder.\n\n2. set `EXPRESS_MODULE_LOGIN_VIEW_NAME` to another view name and create a view with the name you provide.\n\n3. set `EXPRESS_MODULE_LOGIN_CSS` to point to your css file, then you can use classes.\n\nThis is the login.pug template, so you can find the class you need.\n\nlogin.pug\n```pug\nh1.module-login-h1 Please sign in\nform(method='POST' action='/login').module-login-form\n  input(type='hidden' name=\"redirectUrl\" value=`${redirectUrl || ''}`)\n  .module-login-form-control\n    label.module-login-label Username\n      input(type='text' placeholder='Username' name='username' required).module-login-input.module-login-input-username\n  .module-login-form-control\n    label.module-login-label Password\n      input(type='password' placeholder='Password' name='password' required).module-login-input.module-login-input-password\n  .module-login-form-control\n    button(type='submit').module-login-button Login\n```\n\n## Database structure\n\n```javascript\n{\n  users: {\n    static findById(id): Promise<user>;\n    static comparePassword(username, password): Promise<user|false>;\n  },\n}\n```\n\nUser model\n```typescript\nclass User {\n  id: any;\n  username: string;\n  password: string;\n}\n```\n_INFO: don't forget to hash the password before saving in database!_\n\n## MIT License\n\nCopyright (c) 2019 Adem Aytaç\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","readmeFilename":"README.md"}