README
What is this repository for?
-
This repository is node server to managements users on back-end side
-
This repository has the following APIs
-
sign-up:
- Sending activation link to to (user email that sign up / or to admin if verifyUserBy set to true)
- route: /user/sign-up
- body:username: 'user-email@domain.com'password: 'user-password'
- method: 'POST'
- response:
- json:http-status: 200 OKmessage: 'User create, email verification sent'
-
verify-user
- Verify user by clicking on activation link
- The linked that sent with an email
- route: /user/verify/:actionId
- method: 'GET'
- response: HTML that says if activation succeeded or faild
-
sign-in
- Sign in by user credentials or by thired party like (Facebook / Google) if loginWithThirdParty set to true return token that needs to be send each other api call to identify the user
- route: /user/sign-in
- body:
- a.Or in case sign in via thired party (Facebook/Google)username: 'user-email@domain.com'password: 'user-password'
- b.username: 'third-party-email@domain.com'password: 'thired-party-token-reponse'thireParty: 'FACEBOOK' | 'GOOGLE'
- a.
- method: 'POST'
- response:
- json:http-status: 200 OKtoken: 'generated-token'
** The above response should be send in an header of each other requests (via interceptor or other)
-
forgot-password
- Forgot password will send to the email link (changePasswordUrl + actionId that set in config)
- route: /forgot-password
- body:username: 'user-email@domain.com'
- method: 'POST'
- reaponse:
- json:http-status: 200 OKmessage: 'Password reset link sent to your Email'
- Email will be send to the user with a link to change password, this link will combine actionId as a part of thr URL
-
change-password
- Change password - post to /user/change-password/{actionId} with { password } as payload
- route: /user/change-password/:actionId
- body:password: 'new-password'
- method: 'POST'
- response:
- json:http-status: 200 OKmessage: 'Password successfully changed'
-
get user info /user/info (token needs to be send in header)
- get user info
- route: /user/info
- method: 'GET'
- header:token: 'generated-token'
-
contact-us
- Sending email to that admin user (admin user in config file) (token needs to be send in header)
- route: /user/contact-us
- body:username: 'user-email@domain.com'subject: 'contact-us-subjet'description: 'contact-us-description'
- method: 'POST'
- response: email with the payload will be sen to the adminEmail
-
-
version: 1.0.7
How do I get set up?
- yarn add user-managements-node-server / npm --save user-managements-node-server]
- This module use Sequelize so, it supports the following databases
- Create one of the following database 'postgres'|'mysql'|'sqlite'|'mssql'
- Create database login user
- Database Tables - You can create it manually or use the 'dbcreate' script below :
- Table: ActionVerifications
ActionVerifications: actionId: type: DataTypesUUID allowNull: false primaryKey: true uuid username: type: DataTypesSTRING allowNull: false actionType: type: DataTypesINTEGER allowNull: false deleted: type: DataTypesBOOLEAN allowNull: false defaultValue: false
Tokens: id: type: DataTypesUUID allowNull: false primaryKey: true uuid userId: type: DataTypesUUID allowNull: false primaryKey: true ip: type: DataTypesSTRING allowNull: false unique: true token: type: DataTypesSTRING allowNull: true userAgentIdentity: type: DataTypesSTRING allowNull: false
- Table: Users
Users: id: type: DataTypesUUID allowNull: false primaryKey: true uuid username: type: DataTypesSTRING allowNull: false unique: true password: type: DataTypesTEXT fullName: type: DataTypesSTRING allowNull: true token: type: DataTypesSTRING allowNull: true fbToken: type: DataTypesTEXT allowNull: true googleToken: type: DataTypesTEXT allowNull: true profilePhoto: type: DataTypesSTRING allowNull: true isValid: type: DataTypesBOOLEAN defaultValue: false termsOfUse: type: DataTypesBOOLEAN defaultValue: false
- Table: Audit
Audit: id: type: DataTypesUUID allowNull: false primaryKey: true uuid username: type: DataTypesSTRING allowNull: false actionName: type: DataTypesSTRING allowNull: false requestParams: type: DataTypesTEXT allowNull: true
- Edit the following config with the above settings
- Configuration:
- Setup the following config file: [config.js]
"verifyUserBy": "ADMIN" // "ADMIN" | "AUTO" : "EMAIL" "verify3rdPartyUserBy": "AUTO" // "ADMIN" | "AUTO" : "EMAIL" "useSingleToken": false // true - Multiple tokens for diffrent devices "appName":"<Your application name>" // The appName will be uses when sending emails to user/admin "port": 5000 "database": "name": "user-managements-db" "username": "user-managements-username" "password": "user-managements-password" "settings": // Database location "host": "localhost" // You can use one of the the foolowing databases "dialect": " mysql | mariadb | sqlite | postgres | mssql " // In case you use sqlite storage file path is required "storage": "/tmp/user-managements.sqlite" "pool": "max": 5 "min": 0 "idle": 10000 // To log database queries set the following to true "logging": false // The following email setting are require if you want the system to send emails to users "email": "service": "<Email Service>" "user": "<Email Username>" "pass": "<Email Password>" "from": "<Email From>" "verificationUrl": "http://your-web-site-domain/user/verify/" "changePasswordUrl": "http://your-web-site-domain/change-password/" "loginUrl": "http://your-web-site-domain/login" "tokenHash": "dev-token-key" "adminEmail": "<admin@your-domain>" "log4js": "appenders": "app": "type": "file" "filename": "/var/log/your-app-name/app-name.log" "categories": "default": "appenders": "app" "level": "all" "templates": "activation": "body" : "./email-templates/activation/body.html" "subject" : "./email-templates/activation/subject.html" "approved": "body" : "./email-templates/approved-activation/body.html" "subject" : "./email-templates/approved-activation/subject.html" "notify": "body" : "./email-templates/notify-admin-when-user-created/body.html" "subject" : "./email-templates/notify-admin-when-user-created/subject.html" "activationResponse" : "./email-templates/activation/response.html" "userRoutePrefix": "/user"
-
Run: yarn dbcreate Or npm run dbcreate - This script will create the relevant tables
-
Run the server:
-
Please see example how to run this module: run-user-managements-node-server-exp
-
Templates - any of the following templates can be edited with your own HTML template I've choose to work with dot module. You need to build your custom template with dot syntax. For example the default activationBody look like
`<!doctype html><html><head><meta charset='utf-8'><title>{{=it.appName}}</title><style type='text/css'>body {-webkit-text-size-adjust: 100%;-ms-text-size-adjust: 100%;font-family: sans-serif;}</style></head><body><div><div>Hello, {{=it.username}}</div>Thank you for registration our app,to finish activation please click <a href='{{=it.verificationUrl}}{{=it.actionId}}'>here</a></div></body></html>`
1. activationBody
Exposed fields:
a. appName - appName from config
b. username - current handled username
c. verificationUrl - verificationUrl from config
d. actionId - current handled actionId
2. activationSubject
Exposed fields:
a. appName - appName from config
3. activationResponse
Exposed fields:
a. appName - appName from config
b. error - boolean indicator
c. link - loginUrl from config
4. activationBodyApproved
a. appName - appName from config
b. username - current handled username
c. loginUrl - loginUrl from config
5. activationSubjectApproved
a. appName - appName from config
6. notifyBodyAdminWhenUserCreated
a. appName - appName from config
b. admin - adminEmail from config
c. username - current handled username
d. fullName - current handled user's fullName
7. notifySubjectAdminWhenUserCreated
a. appName - appName from config
b. username - current handled username
* Haim Rubin
* haim.rubin@gmail.com
- Please let me know on any issue