ngx-form
v2.0.7
Published
ngx-Form with file upload to file system, image path stored to Mongo. Project is built using the MEA2N/MEAN2 stack. This project could be used as an angular2-seed.
Downloads
17
Maintainers
Readme
ngx-Form with file upload to file system, image path stored to Mongo. Project is built using the MEA2N/MEAN2 stack. This project could be used as an angular2-seed.
Live Demo: ngx-Form Admin panel is disabled, please register using your own credentials
TODO
- Fix some small bugs in backend file deletion
- Fix form deletion from table (fix forms.splice)
ngx-Form
This project was generated with angular-cli version 1.1.2.
The goal of this project is to submit a form with one file upload and two text fields. The form is submitted to back end, the file is stored in the uploads/forms/:userID
and then the file name (string) is stored in MongoDB among the two text fields. At the end, the form ID is assinged to the signed in user ID (via Ref) for later viewing all the form fields and file in the front end. User profile image is stored at uploads/profiles/:userID
.
Prerequisites
- MongoDB installed and running (http://mongodb.org)
- Node.js and NPM installed (http://nodejs.org)
- ImageMagick or GraphicsMagick installed, more info in gm page on how to install depending your Operating System. If installing ImageMagick on Windows, please check "Install Legacy Utitities (e.g. convert") during installation otherwise node will report errors.
Specs
- User login/signup using JSON Web Token (jwt) with Passport.
- User password reset via email (nodemailer & SendGrid) using HTML templates (welcome email included upon user registration).
- Toastr Notifications (& Error Handling).
- Multipart form submission with image preview before upload (some of the upload logic is taken from primeng ui).
- Storing images to file system.
- Storing image path to MongoDB among text fields.
- Triple check if image is actually a file by checking it's mime type in both back end and in front end (
gm
in back end checks if file is an image too by reading first bytes of the file, need to fix this to not allow form to be submitted at all). - Double check for the image size in both back end and front end, file limit now is 5.000.000 bytes (5MB).
- Image resize server side using GraphicsMagick.
- Form deletion among the file from filesystem, user forms array is updated too.
- Edit form, user can edit the text inputs and the image or update only the image or update only the text fields.
- Admin area, admin can edit or delete all forms in database.
- User Profile area, user can upload a profile picture, change his password, view profile info like email, user id, role and joined date.
- Cron job to delete images from
uploads/tmp
folder when image age is greater than 1 hour. Cron runs every 1 hour, in order to enable cron you have to runnode cron.js
.
Packages Used
Angular-cli v1.1.2
Angular v4.2.3
Webpack
Node used in development v8.1.2
MongoDB used in development v3.4.1
Mongoose v4.10.7
Express v4.15.3
angular2-jwt v0.1.27
(for checking the expiration date of the jwt token, user role (admin or user)) and for using AuthHttp wrapper.
jsonwebtoken v7.4.1
Multer v1.3.0
ng2-toastr v4.1.0
gm v1.23.0
Passport v0.3.2
Passport-jwt v2.2.1
Bcrypt v1.0.2
Node-schedule v1.2.3
Find-remove v1.0.1
BootStrap 3
(css is included in assets
folder)
Font Awesome
(css is included in assets
folder)
Glyphicons
(found in fonts
folder under assets
)
Installing Dependecies
- Clone this repo from Git
- Run
npm install
in your command line. - Edit
config.js
in/server/config
folder. - Run
node seed.js
to insert the admin user into database and create uploads folder. Admin email is[email protected]
and password istestpass
. Make sure mongod is running. - After login navigate to
localhost:3000/#/admin
to access admin panel.
Building the Angular app
Run ng build
A new dist
folder will be created with all files needed to run the Angular 2 app in front end.
If you want to make changes on the Angular app and auto-refresh the dist
folder then run the following command in your terminal:
ng build --watch
Running the server
Run npm start
If you want to make changes on the Server and auto refresh the back end code then run: nodemon npm start
. If you don't have nodemon installed, run npm install nodemon -g
.
If you want to execute the cron job in order to clean up /uploads/tmp
folder every 1 hour for files that their age is greater than 1 hour, run node cron.js
.
Viewing the App
Open your favourite web browser and point to http://localhost:3000
Enjoy!
Help with angular-cli
To get more help on the angular-cli
use ng --help
or go check out the Angular-CLI README.