commit
b913d67327
@ -1,104 +0,0 @@
|
||||
{
|
||||
"projectName": "OhMyForm",
|
||||
"projectOwner": "ohmyform",
|
||||
"files": [
|
||||
"README.md"
|
||||
],
|
||||
"imageSize": 100,
|
||||
"commit": true,
|
||||
"contributors": [
|
||||
{
|
||||
"login": "whitef0x0",
|
||||
"name": "David Baldwynn",
|
||||
"avatar_url": "https://avatars2.githubusercontent.com/u/1160417?v=3",
|
||||
"profile": "http://baldwynn.me",
|
||||
"contributions": [
|
||||
"code",
|
||||
"tool",
|
||||
"infra",
|
||||
"doc",
|
||||
"example",
|
||||
"design",
|
||||
"fundingFinding",
|
||||
"review",
|
||||
"test"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "lalop",
|
||||
"name": "Samuel Laulhau",
|
||||
"avatar_url": "https://avatars2.githubusercontent.com/u/313117?v=3",
|
||||
"profile": "https://samuellaulhau.fr",
|
||||
"contributions": [
|
||||
"code",
|
||||
"translation"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "arunpattnaik",
|
||||
"name": "Arun Pattnaik",
|
||||
"avatar_url": "https://avatars0.githubusercontent.com/u/313507?v=3",
|
||||
"profile": "http://arun.co",
|
||||
"contributions": [
|
||||
"design"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "toanalien",
|
||||
"name": "Thiên Toán",
|
||||
"avatar_url": "https://avatars0.githubusercontent.com/u/5405744?v=3",
|
||||
"profile": "https://toanalien.com",
|
||||
"contributions": [
|
||||
"bug",
|
||||
"code",
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "AdrianP-",
|
||||
"name": "Adrian Portabales",
|
||||
"avatar_url": "https://avatars2.githubusercontent.com/u/8615608?v=3",
|
||||
"profile": "https://github.com/AdrianP-",
|
||||
"contributions": [
|
||||
"bug",
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "spekulatius",
|
||||
"name": "Peter Thaleikis",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/8433587?v=3",
|
||||
"profile": "https://github.com/spekulatius",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "mickaelandrieu",
|
||||
"name": "Mickaël Andrieu",
|
||||
"avatar_url": "https://avatars1.githubusercontent.com/u/1247388?v=3",
|
||||
"profile": "http://www.mickael-andrieu.com",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "ahmad-luqman",
|
||||
"name": "Ahmad Luqman",
|
||||
"avatar_url": "https://avatars1.githubusercontent.com/u/1522464?v=3",
|
||||
"profile": "https://github.com/ahmad-luqman",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "PeterDaveHello",
|
||||
"name": "Peter Dave Hello",
|
||||
"avatar_url": "https://avatars0.githubusercontent.com/u/3691490?v=3",
|
||||
"profile": "https://www.peterdavehello.org/",
|
||||
"contributions": [
|
||||
"doc"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
5
.bowerrc
5
.bowerrc
@ -1,5 +0,0 @@
|
||||
{
|
||||
"directory": "public/lib",
|
||||
"analytics": false,
|
||||
"registry": "https://registry.bower.io"
|
||||
}
|
||||
15
.csslintrc
15
.csslintrc
@ -1,15 +0,0 @@
|
||||
{
|
||||
"adjoining-classes": false,
|
||||
"box-model": false,
|
||||
"box-sizing": false,
|
||||
"floats": false,
|
||||
"font-sizes": false,
|
||||
"important": false,
|
||||
"known-properties": false,
|
||||
"overqualified-elements": false,
|
||||
"qualified-headings": false,
|
||||
"regex-selectors": false,
|
||||
"unique-headings": false,
|
||||
"universal-selector": false,
|
||||
"unqualified-attributes": false
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
# EditorConfig is awesome: http://EditorConfig.org
|
||||
|
||||
# How-to with your editor: http://editorconfig.org/#download
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# Unix-style newlines with a newline ending every file
|
||||
[*]
|
||||
end_of_line = lf
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
|
||||
[{Dockerfile,Procfile}]
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# Standard at: https://github.com/felixge/node-style-guide
|
||||
[{*.js,*.json}]
|
||||
trim_trailing_whitespace = true
|
||||
quote_type = single
|
||||
curly_bracket_next_line = false
|
||||
spaces_around_operators = true
|
||||
space_after_control_statements = true
|
||||
space_after_anonymous_functions = false
|
||||
spaces_in_brackets = false
|
||||
125
.env.example
125
.env.example
@ -1,125 +0,0 @@
|
||||
# OhMyForm Configuration File
|
||||
## TODO: Have commented out examples that would work.
|
||||
|
||||
###################################
|
||||
# Common configuration variables
|
||||
###################################
|
||||
|
||||
# Set this to the path where Mailu data and configuration is stored
|
||||
# Mac users: Change to a Docker accessible folder
|
||||
ROOT=/opt/ohmyform_data
|
||||
|
||||
# Set to what environment you will be running OhMyForm in (production or development)
|
||||
NODE_ENV=development
|
||||
|
||||
# Set to a randomly generated 16 bytes string
|
||||
SECRET_KEY=ChangeMeChangeMe
|
||||
|
||||
# URI of Mongo database that OhMyForm will connect to
|
||||
#DO NOT CHANGE
|
||||
MONGODB_URI=mongodb://mongo/ohmyform
|
||||
|
||||
# URL Redis server that OhMyForm will connect to
|
||||
#DO NOT CHANGE
|
||||
REDIS_URL=redis://redis:6379
|
||||
|
||||
# Port that the OhMyForm Node app will listen on
|
||||
PORT=5000
|
||||
|
||||
# Domain that OhMyForm's admin panel will be hosted at
|
||||
BASE_URL=ohmyform.dev
|
||||
|
||||
# Port that SocketIO server (for analytics) will listen on
|
||||
SOCKET_PORT=20523
|
||||
|
||||
#Choose what kind of TLS you want.
|
||||
#Can be either 'cert' (supply your certificates in ./cert/), 'notls' (no https at all) or 'letsencrypt' that autoconfigures your instance with letsencrypt
|
||||
TLS_FLAVOR=notls
|
||||
|
||||
###################################
|
||||
# Optional features
|
||||
###################################
|
||||
|
||||
# Set this to enable coveralls.io support
|
||||
COVERALLS_REPO_TOKEN=
|
||||
|
||||
# Disable signups for your OhMyForm instance
|
||||
SIGNUP_DISABLED=FALSE
|
||||
|
||||
# Disable per-user custom subdomains
|
||||
SUBDOMAINS_DISABLED=FALSE
|
||||
|
||||
# Url that subdomains will be hosted at (has to have domain name as ADMIN_URL)
|
||||
# Only used when SUBDOMAINS_DISABLED=FALSE
|
||||
SUBDOMAIN_URL=*.ohmyform.dev
|
||||
|
||||
# Enable running OhMyForm in pm2's 'cluster' mode
|
||||
ENABLE_CLUSTER_MODE=FALSE
|
||||
|
||||
###################################
|
||||
# Mail settings
|
||||
# IMPORTANT: These settings need to be set
|
||||
# to be set in order for your instance to work
|
||||
###################################
|
||||
|
||||
|
||||
|
||||
# Set this to set the username credential of your SMTP service
|
||||
MAILER_EMAIL_ID=
|
||||
|
||||
# Set this to set the password credential of your SMTP service
|
||||
MAILER_PASSWORD=
|
||||
|
||||
# Set this to set the email address that all email should be sent from for signup/verification emails
|
||||
MAILER_FROM=
|
||||
|
||||
# Set this to any services from https://nodemailer.com/smtp/well-known/ to use a 'well-known' email provider
|
||||
MAILER_SERVICE_PROVIDER=
|
||||
|
||||
# Set these if you are not using a 'MAILER_SERVICE_PROVIDER' and want to specify your SMTP server's address and port
|
||||
MAILER_SMTP_HOST=
|
||||
MAILER_SMTP_PORT=
|
||||
|
||||
# Set this if you are using a custom SMTP server that supports SSL
|
||||
MAILER_SMTP_SECURE
|
||||
|
||||
###################################
|
||||
# Automatic Admin Creation Settings
|
||||
###################################
|
||||
|
||||
# Set this to "TRUE" if you wish to automatically create an admin user on startup
|
||||
CREATE_ADMIN=FALSE
|
||||
|
||||
# Set this to set the email used by your default admin account
|
||||
ADMIN_EMAIL=admin@admin.com
|
||||
|
||||
# Set this to set the username of your default admin acconut
|
||||
ADMIN_USERNAME=root
|
||||
|
||||
# Set this to set the password of your default admin account
|
||||
ADMIN_PASSWORD=root
|
||||
|
||||
###################################
|
||||
# Advanced settings
|
||||
###################################
|
||||
|
||||
# Set this to server your websockets server on a seperate URL
|
||||
SOCKETS_URL=
|
||||
|
||||
# Set this to change the port that OhMyForm will listen on
|
||||
PORT=5000
|
||||
|
||||
# Set this to your Google Analytics ID to enable tracking with GA
|
||||
GOOGLE_ANALYTICS_ID=
|
||||
|
||||
# Set this to your Sentry.io DSN code to enable front-end JS error tracking with Sentry.io
|
||||
RAVEN_DSN
|
||||
|
||||
# Set this to set the 'name' meta property in the HTML <head>
|
||||
APP_NAME=
|
||||
|
||||
# Set this to set the 'keywords' meta property in the HTML <head>
|
||||
APP_KEYWORDS=
|
||||
|
||||
# Set this to set the 'description' meta property in the HTML head
|
||||
APP_DESC=
|
||||
7
.gitmodules
vendored
Normal file
7
.gitmodules
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
[submodule "ui"]
|
||||
path = ui
|
||||
url = https://github.com/ohmyform/ui
|
||||
|
||||
[submodule "api"]
|
||||
path = api
|
||||
url = https://github.com/ohmyform/api
|
||||
54
.jshintrc
54
.jshintrc
@ -1,54 +0,0 @@
|
||||
{
|
||||
"loopfunc": true,
|
||||
"node": true, // Enable globals available when code is running inside of the NodeJS runtime environment.
|
||||
"browser": true, // Standard browser globals e.g. `window`, `document`.
|
||||
"esnext": true, // Allow ES.next specific features such as `const` and `let`.
|
||||
"bitwise": false, // Prohibit bitwise operators (&, |, ^, etc.).
|
||||
"camelcase": false, // Permit only camelcase for `var` and `object indexes`.
|
||||
"curly": false, // Require {} for every new block or scope.
|
||||
"eqeqeq": true, // Require triple equals i.e. `===`.
|
||||
"immed": true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
|
||||
"latedef": false, // Prohibit variable use before definition.
|
||||
"newcap": false, // Require capitalization of all constructor functions e.g. `new F()`.
|
||||
"noarg": true, // Prohibit use of `arguments.caller` and `arguments.callee`.
|
||||
"quotmark": "single", // Define quotes to string values.
|
||||
"regexp": true, // Prohibit `.` and `[^...]` in regular expressions.
|
||||
"undef": true, // Require all non-global variables be declared before they are used.
|
||||
"unused": false, // Warn unused variables.
|
||||
"strict": true, // Require `use strict` pragma in every file.
|
||||
"trailing": true, // Prohibit trailing whitespaces.
|
||||
"smarttabs": false, // Suppresses warnings about mixed tabs and spaces
|
||||
"globals": { // Globals variables.
|
||||
"jasmine": true,
|
||||
"angular": true,
|
||||
"devel": false,
|
||||
"_": true,
|
||||
"saveAs": true,
|
||||
"ApplicationConfiguration": true,
|
||||
"Session": true,
|
||||
"$": true,
|
||||
"$window": true,
|
||||
"io": true,
|
||||
"jsep": true,
|
||||
"MobileDetect": true
|
||||
},
|
||||
"predef": [ // Extra globals.
|
||||
"define",
|
||||
"require",
|
||||
"exports",
|
||||
"module",
|
||||
"describe",
|
||||
"before",
|
||||
"beforeEach",
|
||||
"after",
|
||||
"afterEach",
|
||||
"it",
|
||||
"inject",
|
||||
"expect",
|
||||
"_",
|
||||
"spyOn"
|
||||
],
|
||||
"indent": 4, // Specify indentation spacing
|
||||
"devel": true, // Allow development statements e.g. `console.log();`.
|
||||
"noempty": true // Prohibit use of empty blocks.
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
/app/tests
|
||||
67
Dockerfile
67
Dockerfile
@ -1,58 +1,29 @@
|
||||
FROM node:10-alpine
|
||||
FROM node:12 as builder
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY ui/ .
|
||||
|
||||
RUN yarn install --frozen-lockfile
|
||||
RUN yarn export
|
||||
|
||||
FROM node:12
|
||||
LABEL maintainer="OhMyForm <admin@ohmyform.com>"
|
||||
|
||||
# Create a group and a user with name "ohmyform".
|
||||
RUN addgroup --gid 9999 ohmyform && adduser -D --uid 9999 -G ohmyform ohmyform
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Install some needed packages
|
||||
RUN apk add --no-cache git python \
|
||||
&& rm -rf /tmp/* \
|
||||
&& npm install --quiet -g grunt@1.0.4 bower@1.8.8 pm2@3.5.1 \
|
||||
&& npm cache clean --force \
|
||||
&& mkdir -p /opt/app/public/lib
|
||||
COPY api/ .
|
||||
|
||||
# to expose the public folder to other containers
|
||||
# VOLUME /opt/app
|
||||
RUN yarn install --frozen-lockfile
|
||||
RUN yarn build
|
||||
|
||||
WORKDIR /opt/app
|
||||
|
||||
## TODO: Find a method that's better than this for passing ENV's if possible.
|
||||
# Set default ENV
|
||||
ENV NODE_ENV=development \
|
||||
SECRET_KEY=ChangeMeChangeMe \
|
||||
PORT=5000 \
|
||||
BASE_URL=localhost \
|
||||
SOCKET_PORT=20523 \
|
||||
SIGNUP_DISABLED=FALSE \
|
||||
SUBDOMAINS_DISABLED=TRUE \
|
||||
ENABLE_CLUSTER_MODE=FALSE \
|
||||
MAILER_EMAIL_ID=ohmyform@localhost \
|
||||
MAILER_PASSWORD="" \
|
||||
MAILER_FROM=ohmyform@localhost \
|
||||
MAILER_SERVICE_PROVIDER="" \
|
||||
MAILER_SMTP_HOST="" \
|
||||
MAILER_SMTP_PORT="" \
|
||||
MAILER_SMTP_SECURE="" \
|
||||
ENV PORT=3000 \
|
||||
SECRET_KEY=ChangeMe \
|
||||
CREATE_ADMIN=FALSE \
|
||||
ADMIN_EMAIL=admin@ohmyform.com \
|
||||
ADMIN_USERNAME=root \
|
||||
ADMIN_PASSWORD=root \
|
||||
APP_NAME=OhMyForm \
|
||||
APP_KEYWORDS="" \
|
||||
APP_DESC="" \
|
||||
COVERALLS_REPO_TOKEN="" \
|
||||
GOOGLE_ANALYTICS_ID="" \
|
||||
RAVEN_DSN=""
|
||||
ADMIN_PASSWORD=root
|
||||
|
||||
# keep .dockerignore up to date
|
||||
COPY . .
|
||||
EXPOSE 3000
|
||||
|
||||
RUN npm install --only=production \
|
||||
&& bower install --allow-root -f \
|
||||
&& grunt build
|
||||
|
||||
# Change to non-root privilege
|
||||
USER ohmyform
|
||||
|
||||
# Run OhMyForm server
|
||||
CMD ["node", "server.js"]
|
||||
CMD [ "yarn", "start:prod" ]
|
||||
|
||||
676
LICENSE.md
676
LICENSE.md
@ -1,21 +1,661 @@
|
||||
## License
|
||||
(The MIT License)
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
Preamble
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
@ -57,6 +57,7 @@ Moving over to Discord so that I can manage things without hassle.
|
||||
- Add Custom Background and Dropdown Field Images
|
||||
- Add File Upload Form Field
|
||||
- Deployable with Heroku and DockerHub
|
||||
- Ditch MongoDB for a drop in replacement with better licensing.
|
||||
|
||||
|
||||
|
||||
|
||||
661
SUBLICENSE.md
661
SUBLICENSE.md
@ -1,661 +0,0 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
1
api
Submodule
1
api
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 91e5c333400733ae0e7a8d98b7b5cd15ccf74378
|
||||
2
api/.gitignore
vendored
2
api/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
/node_modules
|
||||
/yarn.lock
|
||||
@ -1,4 +0,0 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
FROM node:10 AS builder
|
||||
MAINTAINER OhMyForm <admin@ohmyform.com>
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# just copy everhing
|
||||
COPY . .
|
||||
|
||||
RUN yarn install --frozen-lockfile
|
||||
RUN yarn build
|
||||
|
||||
FROM node:10-alpine
|
||||
|
||||
COPY --from=builder /usr/src/app /usr/src/app
|
||||
|
||||
EXPOSE 3000
|
||||
CMD [ "yarn", "start:prod" ]
|
||||
@ -1,55 +0,0 @@
|
||||
<p align="center">
|
||||
<a href="http://ohmyform.com/" target="blank"><img src="https://ohmyform.com/img/logo_text.svg" width="320" alt="OhMyForm Logo" /></a>
|
||||
</p>
|
||||
|
||||
## Description
|
||||
|
||||
[OhMyForm](https://github.com/ohmyforn) api backend
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ yarn install
|
||||
```
|
||||
|
||||
## Running the app
|
||||
|
||||
```bash
|
||||
# development
|
||||
$ npm run start
|
||||
|
||||
# watch mode
|
||||
$ npm run start:dev
|
||||
|
||||
# incremental rebuild (webpack)
|
||||
$ npm run webpack
|
||||
$ npm run start:hmr
|
||||
|
||||
# production mode
|
||||
$ npm run start:prod
|
||||
```
|
||||
|
||||
## Test
|
||||
|
||||
```bash
|
||||
# unit tests
|
||||
$ npm run test
|
||||
|
||||
# e2e tests
|
||||
$ npm run test:e2e
|
||||
|
||||
# test coverage
|
||||
$ npm run test:cov
|
||||
```
|
||||
|
||||
## Support
|
||||
|
||||
TODO
|
||||
|
||||
## Stay in touch
|
||||
|
||||
- Website - [https://ohmyform.com](https://ohmyform.com/)
|
||||
|
||||
## License
|
||||
|
||||
TODO
|
||||
@ -1,5 +0,0 @@
|
||||
{
|
||||
"language": "ts",
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src"
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
{
|
||||
"watch": ["src"],
|
||||
"ext": "ts",
|
||||
"ignore": ["src/**/*.spec.ts"],
|
||||
"exec": "node --inspect-brk -r ts-node/register src/main.ts"
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
{
|
||||
"watch": ["src"],
|
||||
"ext": "ts",
|
||||
"ignore": ["src/**/*.spec.ts"],
|
||||
"exec": "ts-node -r tsconfig-paths/register src/main.ts"
|
||||
}
|
||||
@ -1,79 +0,0 @@
|
||||
{
|
||||
"name": "ohmyform",
|
||||
"version": "0.1.0",
|
||||
"description": "Opensource alternative to TypeForm",
|
||||
"author": "multiple",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "rimraf dist && tsc -p tsconfig.build.json",
|
||||
"format": "prettier --write \"src/**/*.ts\"",
|
||||
"start": "ts-node -r tsconfig-paths/register src/main.ts",
|
||||
"start:dev": "tsc-watch -p tsconfig.build.json --onSuccess \"node dist/main.js\"",
|
||||
"start:debug": "tsc-watch -p tsconfig.build.json --onSuccess \"node --inspect-brk dist/main.js\"",
|
||||
"start:prod": "node dist/main.js",
|
||||
"lint": "tslint -p tsconfig.json -c tslint.json",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@godaddy/terminus": "^4.1.2",
|
||||
"@nest-modules/mailer": "^1.1.3",
|
||||
"@nestjs/common": "^6.5.2",
|
||||
"@nestjs/core": "^6.5.2",
|
||||
"@nestjs/jwt": "^6.1.1",
|
||||
"@nestjs/mongoose": "^6.1.2",
|
||||
"@nestjs/passport": "^6.1.0",
|
||||
"@nestjs/platform-express": "^6.5.2",
|
||||
"@nestjs/swagger": "^3.1.0",
|
||||
"@nestjs/terminus": "^6.5.0",
|
||||
"@types/bcrypt": "^3.0.0",
|
||||
"@types/mongoose": "^5.5.11",
|
||||
"bcrypt": "^3.0.6",
|
||||
"class-transformer": "^0.2.3",
|
||||
"class-validator": "^0.9.1",
|
||||
"handlebars": "^4.1.2",
|
||||
"mongoose": "^5.6.7",
|
||||
"nestjs-typegoose": "^5.2.1",
|
||||
"passport": "^0.4.0",
|
||||
"passport-jwt": "^4.0.0",
|
||||
"passport-local": "^1.0.0",
|
||||
"reflect-metadata": "^0.1.12",
|
||||
"rimraf": "^2.6.2",
|
||||
"rxjs": "^6.3.3",
|
||||
"swagger-ui-express": "^4.0.7",
|
||||
"typegoose": "^5.9.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/testing": "6.1.1",
|
||||
"@types/express": "4.16.1",
|
||||
"@types/jest": "24.0.11",
|
||||
"@types/node": "11.13.4",
|
||||
"@types/supertest": "2.0.7",
|
||||
"jest": "24.7.1",
|
||||
"prettier": "1.17.0",
|
||||
"supertest": "4.0.2",
|
||||
"ts-jest": "24.0.2",
|
||||
"ts-node": "8.1.0",
|
||||
"tsc-watch": "2.2.1",
|
||||
"tsconfig-paths": "3.8.0",
|
||||
"tslint": "5.16.0",
|
||||
"typescript": "3.4.3"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"ts"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"testRegex": ".spec.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
},
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
}
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { AppService } from './app.service';
|
||||
import {ApiExcludeEndpoint} from "@nestjs/swagger"
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
|
||||
@ApiExcludeEndpoint()
|
||||
@Get()
|
||||
getIndex(): object {
|
||||
return {
|
||||
message: 'hello humanoid',
|
||||
_links: {
|
||||
doc: '/doc',
|
||||
health: '/health'
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TerminusModule } from '@nestjs/terminus';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { TypegooseModule } from 'nestjs-typegoose';
|
||||
import { TerminusOptionsService } from './terminus-options.service';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { UserModule } from "./user/user.module"
|
||||
import { FormModule } from "./form/form.module"
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
import { MailModule } from "./mail/mail.module"
|
||||
import { MailerModule } from "@nest-modules/mailer"
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypegooseModule.forRoot('mongodb://localhost/ohmyform', { useNewUrlParser: true }),
|
||||
MongooseModule.forRoot('mongodb://localhost/ohmyform'),
|
||||
TerminusModule.forRootAsync({
|
||||
useClass: TerminusOptionsService,
|
||||
}),
|
||||
MailerModule.forRoot({
|
||||
transport: 'smtp://localhost:1025',
|
||||
defaults: {
|
||||
from:'"OhMyForm" <noreply@ohmyform.com>',
|
||||
}
|
||||
}),
|
||||
UserModule,
|
||||
FormModule,
|
||||
AuthModule,
|
||||
MailModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
export class AppModule {}
|
||||
@ -1,8 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
import {AuthController} from "./controllers/auth.controller"
|
||||
import {RecoverController} from "./controllers/recover.controller"
|
||||
import {RegisterController} from "./controllers/register.controller"
|
||||
|
||||
export default [
|
||||
AuthController,
|
||||
RecoverController,
|
||||
RegisterController,
|
||||
]
|
||||
@ -1,23 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { UserModule } from '../user/user.module';
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
import { jwtConstants } from "./constants"
|
||||
import { JwtModule } from "@nestjs/jwt"
|
||||
import controllers from './auth.controllers'
|
||||
import providers from './auth.providers'
|
||||
import { MailModule } from "../mail/mail.module"
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
UserModule,
|
||||
PassportModule,
|
||||
MailModule,
|
||||
JwtModule.register({
|
||||
secret: jwtConstants.secret,
|
||||
signOptions: { expiresIn: '12h' },
|
||||
}),
|
||||
],
|
||||
controllers,
|
||||
providers
|
||||
})
|
||||
export class AuthModule {}
|
||||
@ -1,15 +0,0 @@
|
||||
import { AuthService } from "./services/auth.service"
|
||||
import { PasswordService } from "./services/password.service"
|
||||
import { PasswordStrategy } from "./strategies/password.strategy"
|
||||
import { JwtStrategy } from "./strategies/jwt.strategy"
|
||||
import { JwtRefreshStrategy } from "./strategies/jwt.refresh.strategy"
|
||||
import { RegisterService } from "./services/register.service"
|
||||
|
||||
export default [
|
||||
AuthService,
|
||||
PasswordService,
|
||||
PasswordStrategy,
|
||||
JwtStrategy,
|
||||
JwtRefreshStrategy,
|
||||
RegisterService,
|
||||
]
|
||||
@ -1,3 +0,0 @@
|
||||
export const jwtConstants = {
|
||||
secret: 'secretKey',
|
||||
};
|
||||
@ -1,30 +0,0 @@
|
||||
import { Controller, Request, Post, UseGuards } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { AuthService } from "../services/auth.service"
|
||||
import { AuthJwtDto } from "../dto/auth.jwt.dto"
|
||||
import {ApiBearerAuth, ApiImplicitBody, ApiImplicitQuery, ApiResponse, ApiUseTags} from "@nestjs/swagger"
|
||||
|
||||
@ApiUseTags('authentication')
|
||||
@Controller('auth')
|
||||
export class AuthController {
|
||||
constructor(private readonly authService: AuthService) {}
|
||||
|
||||
@ApiResponse({ status: 201, description: 'Successful login.', type: AuthJwtDto})
|
||||
@ApiResponse({ status: 401, description: 'Invalid Credentials.'})
|
||||
@ApiImplicitQuery({name: 'username', type: String})
|
||||
@ApiImplicitQuery({name: 'password', type: String})
|
||||
@UseGuards(AuthGuard('password'))
|
||||
@Post('login')
|
||||
async login(@Request() req): Promise<AuthJwtDto> {
|
||||
return this.authService.createToken(req.user);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@ApiResponse({ status: 201, description: 'Consumed Refresh Token.', type: AuthJwtDto})
|
||||
@ApiResponse({ status: 401, description: 'Invalid Token.'})
|
||||
@UseGuards(AuthGuard('jwt.refresh'))
|
||||
@Post('refresh')
|
||||
async refresh(@Request() req): Promise<AuthJwtDto> {
|
||||
return this.authService.createToken(req.user);
|
||||
}
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
import { Controller, Request, Post, UseGuards } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { AuthService } from "../services/auth.service"
|
||||
import { AuthJwtDto } from "../dto/auth.jwt.dto"
|
||||
import {ApiBearerAuth, ApiImplicitBody, ApiImplicitQuery, ApiResponse, ApiUseTags} from "@nestjs/swagger"
|
||||
|
||||
@ApiUseTags('authentication')
|
||||
@Controller('auth/recover')
|
||||
export class RecoverController {
|
||||
constructor(private readonly authService: AuthService) {}
|
||||
|
||||
@ApiResponse({ status: 201, description: 'Successful registration.', type: AuthJwtDto})
|
||||
@ApiImplicitQuery({name: 'email', type: String})
|
||||
@ApiImplicitQuery({name: 'username', type: String})
|
||||
@Post('request')
|
||||
async request(@Request() req): Promise<AuthJwtDto> {
|
||||
// TODO
|
||||
return null
|
||||
}
|
||||
|
||||
@ApiResponse({ status: 201, description: 'Successful registration.', type: AuthJwtDto})
|
||||
@ApiImplicitQuery({name: 'token', type: String})
|
||||
@ApiImplicitQuery({name: 'password', type: String})
|
||||
@Post('finish')
|
||||
async finish(@Request() req): Promise<AuthJwtDto> {
|
||||
// TODO
|
||||
return null
|
||||
}
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
import { Controller, Post, Body } from '@nestjs/common';
|
||||
import { AuthService } from "../services/auth.service"
|
||||
import { ApiBadRequestResponse, ApiCreatedResponse, ApiUseTags } from "@nestjs/swagger"
|
||||
import { RegisterDto } from "../dto/register.dto"
|
||||
import {RegisterService} from "../services/register.service"
|
||||
|
||||
@ApiUseTags('authentication')
|
||||
@Controller('auth')
|
||||
export class RegisterController {
|
||||
constructor(private readonly registerService: RegisterService) {}
|
||||
|
||||
@ApiCreatedResponse({ description: 'Successful registration.'})
|
||||
@ApiBadRequestResponse({})
|
||||
@Post('register')
|
||||
async register(@Body() params: RegisterDto): Promise<void> {
|
||||
await this.registerService.register(params.username, params.email, params.password)
|
||||
}
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
import { ApiModelProperty } from '@nestjs/swagger';
|
||||
|
||||
export class AuthJwtDto {
|
||||
@ApiModelProperty()
|
||||
accessToken: string;
|
||||
|
||||
@ApiModelProperty()
|
||||
refreshToken: string;
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
import { ApiModelProperty } from "@nestjs/swagger"
|
||||
import { IsEmail, IsNotEmpty, Validate } from "class-validator"
|
||||
import { UsernameAlreadyInUse } from "../../user/validators/UsernameAlreadyInUse"
|
||||
import { EmailAlreadyInUse } from "../../user/validators/EmailAlreadyInUse"
|
||||
|
||||
export class RegisterDto {
|
||||
@ApiModelProperty()
|
||||
@IsNotEmpty()
|
||||
@Validate(UsernameAlreadyInUse)
|
||||
readonly username: string;
|
||||
|
||||
@ApiModelProperty()
|
||||
@IsNotEmpty()
|
||||
readonly password: string;
|
||||
|
||||
@ApiModelProperty()
|
||||
@Validate(EmailAlreadyInUse)
|
||||
@IsEmail()
|
||||
readonly email: string;
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
export interface AuthUser {
|
||||
id: string;
|
||||
username: string;
|
||||
email: string;
|
||||
roles: [string];
|
||||
created: Date;
|
||||
lastUpdated: Date;
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AuthService } from './auth.service';
|
||||
|
||||
describe('AuthService', () => {
|
||||
let service: AuthService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [AuthService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<AuthService>(AuthService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@ -1,70 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { UserService } from '../../user/services/user.service';
|
||||
import { PasswordService } from "./password.service"
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { AuthUser } from "../interfaces/auth.user.interface"
|
||||
import { User } from "../../user/models/user.model"
|
||||
import { AuthJwtDto } from "../dto/auth.jwt.dto"
|
||||
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
constructor(
|
||||
private readonly usersService: UserService,
|
||||
private readonly passwordService: PasswordService,
|
||||
private readonly jwtService: JwtService
|
||||
) {}
|
||||
|
||||
async verifyForLogin(identifier: string, pass: string): Promise<AuthUser | null> {
|
||||
try {
|
||||
const user = await this.usersService.findOneByIdentifier(identifier);
|
||||
|
||||
if (await this.passwordService.verify(pass, user.passwordHash, user.salt)) {
|
||||
return AuthService.setupAuthUser(user)
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async validate(identifier: string): Promise<AuthUser | null> {
|
||||
try {
|
||||
return AuthService.setupAuthUser(
|
||||
await this.usersService.findOneByIdentifier(identifier)
|
||||
)
|
||||
} catch (e) {}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static setupAuthUser(user:User):AuthUser {
|
||||
return {
|
||||
id: user._id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
roles: user.roles,
|
||||
created: user.created,
|
||||
lastUpdated: user.lastModified
|
||||
};
|
||||
}
|
||||
|
||||
async createToken(user: AuthUser): Promise<AuthJwtDto> {
|
||||
const payload = {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
scope: user.roles,
|
||||
};
|
||||
return {
|
||||
accessToken: this.jwtService.sign(payload),
|
||||
// TODO add refresh token invalidation uppon usage! They should only work once
|
||||
refreshToken: this.jwtService.sign(
|
||||
{
|
||||
...payload,
|
||||
refresh: true
|
||||
},
|
||||
{
|
||||
expiresIn: '30days',
|
||||
}
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
import { Injectable } from "@nestjs/common"
|
||||
import * as crypto from 'crypto'
|
||||
import * as bcrypt from 'bcrypt'
|
||||
|
||||
@Injectable()
|
||||
export class PasswordService {
|
||||
async verify (password: string, hash: string, salt?: string): Promise<boolean> {
|
||||
console.log('try to verify password', password)
|
||||
if (password[0] === '$') {
|
||||
return await bcrypt.compare(password, hash)
|
||||
}
|
||||
|
||||
//Generate salt if it doesn't exist yet
|
||||
if(!salt){
|
||||
salt = crypto.randomBytes(64).toString('base64');
|
||||
}
|
||||
|
||||
return hash === crypto.pbkdf2Sync(
|
||||
password,
|
||||
new Buffer(salt, 'base64'),
|
||||
10000,
|
||||
128,
|
||||
'SHA1'
|
||||
).toString('base64');
|
||||
}
|
||||
|
||||
hash (password): Promise<string> {
|
||||
return bcrypt.hash(password, 4)
|
||||
}
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
import { Injectable } from "@nestjs/common"
|
||||
import { MailService } from "../../mail/services/mail.service"
|
||||
import { User } from "../../user/models/user.model"
|
||||
import { PasswordService } from "./password.service"
|
||||
import { UserService } from "../../user/services/user.service"
|
||||
|
||||
@Injectable()
|
||||
export class RegisterService {
|
||||
constructor(
|
||||
private readonly mailService: MailService,
|
||||
private readonly passwordService: PasswordService,
|
||||
private readonly userService: UserService
|
||||
) {}
|
||||
|
||||
async register (username: string, email: string, password: string): Promise<void> {
|
||||
let user = new User()
|
||||
user.email = email
|
||||
user.username = username
|
||||
user.passwordHash = await this.passwordService.hash(password)
|
||||
|
||||
await this.userService.save(user)
|
||||
|
||||
await this.mailService.sendEmail(
|
||||
{
|
||||
template: 'auth/register',
|
||||
to: email
|
||||
},
|
||||
{
|
||||
confirm: 'some url'
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { jwtConstants } from '../constants';
|
||||
import { AuthService } from "../services/auth.service"
|
||||
import { AuthUser } from "../interfaces/auth.user.interface"
|
||||
|
||||
@Injectable()
|
||||
export class JwtRefreshStrategy extends PassportStrategy(Strategy, 'jwt.refresh') {
|
||||
constructor(private readonly authService: AuthService) {
|
||||
super({
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
ignoreExpiration: false,
|
||||
secretOrKey: jwtConstants.secret,
|
||||
});
|
||||
}
|
||||
|
||||
async validate(payload: any): Promise<AuthUser | null> {
|
||||
if (!payload.refresh) {
|
||||
return null
|
||||
}
|
||||
|
||||
// TODO add refresh token invalidation uppon usage! They should only work once
|
||||
return this.authService.validate(payload.username);
|
||||
}
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { jwtConstants } from '../constants';
|
||||
import { AuthService } from "../services/auth.service"
|
||||
import {AuthUser} from "../interfaces/auth.user.interface"
|
||||
|
||||
@Injectable()
|
||||
export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||
constructor(private readonly authService: AuthService) {
|
||||
super({
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
ignoreExpiration: false,
|
||||
secretOrKey: jwtConstants.secret,
|
||||
});
|
||||
}
|
||||
|
||||
async validate(payload: any): Promise<AuthUser | null> {
|
||||
return this.authService.validate(payload.username);
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
import { Strategy } from 'passport-local';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
import {AuthUser} from "../interfaces/auth.user.interface"
|
||||
|
||||
@Injectable()
|
||||
export class PasswordStrategy extends PassportStrategy(Strategy, 'password') {
|
||||
constructor(private readonly authService: AuthService) {
|
||||
super();
|
||||
}
|
||||
|
||||
validate(username: string, password: string): Promise<AuthUser | null> {
|
||||
return this.authService.verifyForLogin(username, password);
|
||||
}
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
import { IsMongoId } from 'class-validator';
|
||||
|
||||
export class FindOneDto {
|
||||
@IsMongoId()
|
||||
id: string;
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
import {Controller, Request, Get, Post, Put, Delete, UseGuards, Param, NotImplementedException} from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { ApiBearerAuth, ApiImplicitQuery, ApiResponse, ApiUseTags } from "@nestjs/swagger"
|
||||
import { FormService } from "../services/form.service"
|
||||
import { FormDto } from "../dto/form.dto"
|
||||
import { FindOneDto } from "../../core/dto/find.one.dto"
|
||||
|
||||
@ApiUseTags('forms')
|
||||
@ApiBearerAuth()
|
||||
@Controller('forms')
|
||||
export class FormController {
|
||||
constructor(private readonly formService: FormService) {}
|
||||
|
||||
@Get()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
async list(@Request() req): Promise<FormDto[]> {
|
||||
// TODO calculate total forms, add for pagination
|
||||
const results = await this.formService.findBy({})
|
||||
return results.map(form => new FormDto(form))
|
||||
}
|
||||
|
||||
@Post()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
async create(@Request() req): Promise<FormDto> {
|
||||
throw new NotImplementedException()
|
||||
}
|
||||
|
||||
@ApiResponse({ status: 200, description: 'Form Object', type: FormDto})
|
||||
@ApiImplicitQuery({name: 'id', type: String})
|
||||
@Get(':id')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
async read(@Param() params: FindOneDto): Promise<FormDto> {
|
||||
return new FormDto(await this.formService.findById(params.id));
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
async update(@Param() params: FindOneDto, @Request() req): Promise<FormDto> {
|
||||
throw new NotImplementedException()
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
async delete(@Param() params: FindOneDto): Promise<void> {
|
||||
throw new NotImplementedException()
|
||||
}
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
import { Controller, Get, Param, NotFoundException } from '@nestjs/common';
|
||||
import { ApiImplicitQuery, ApiResponse, ApiUseTags } from "@nestjs/swagger"
|
||||
import { FormService } from "../services/form.service"
|
||||
import { Form } from "../models/form.model"
|
||||
import { PublicFormDto } from "../dto/public.form.dto"
|
||||
import { FindOneDto } from "../../core/dto/find.one.dto"
|
||||
|
||||
@ApiUseTags('forms')
|
||||
@Controller('public')
|
||||
export class PublicController {
|
||||
constructor(private readonly formService: FormService) {}
|
||||
|
||||
@ApiResponse({ status: 200, description: 'Form Object', type: PublicFormDto})
|
||||
@ApiImplicitQuery({name: 'id', type: String})
|
||||
@Get(':id')
|
||||
async read(@Param() params: FindOneDto): Promise<PublicFormDto> {
|
||||
const form:Form = await this.formService.findById(params.id)
|
||||
|
||||
if (!form.isLive) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
return new PublicFormDto(form);
|
||||
}
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
import { ApiModelProperty } from '@nestjs/swagger';
|
||||
import { Form } from "../models/form.model"
|
||||
|
||||
export class FormDto {
|
||||
@ApiModelProperty()
|
||||
id: string;
|
||||
|
||||
@ApiModelProperty()
|
||||
title: string;
|
||||
|
||||
@ApiModelProperty()
|
||||
live: boolean;
|
||||
|
||||
@ApiModelProperty()
|
||||
created: Date;
|
||||
|
||||
@ApiModelProperty()
|
||||
lastModified: Date;
|
||||
|
||||
@ApiModelProperty()
|
||||
fields: any;
|
||||
|
||||
@ApiModelProperty()
|
||||
info: {
|
||||
responses: number;
|
||||
}
|
||||
|
||||
constructor(partial: Partial<Form>) {
|
||||
this.id = partial._id.toString()
|
||||
this.title = partial.title
|
||||
this.live = partial.isLive
|
||||
this.created = partial.created
|
||||
this.lastModified = partial.lastModified
|
||||
this.fields = partial.form_fields
|
||||
this.info = {
|
||||
responses: 0 // TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
import { ApiModelProperty } from '@nestjs/swagger';
|
||||
import { Form } from "../models/form.model"
|
||||
|
||||
export class PublicFormDto {
|
||||
@ApiModelProperty()
|
||||
id: string;
|
||||
|
||||
@ApiModelProperty()
|
||||
title: string;
|
||||
|
||||
fields: [];
|
||||
|
||||
constructor(partial: Partial<Form>) {
|
||||
this.id = partial._id.toString();
|
||||
this.title = partial.title
|
||||
}
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
import { FormController } from "./controllers/form.controller"
|
||||
import { PublicController } from "./controllers/public.controller"
|
||||
|
||||
export default [
|
||||
FormController,
|
||||
PublicController,
|
||||
]
|
||||
@ -1,15 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import controllers from './form.controllers';
|
||||
import providers from './form.providers'
|
||||
import {TypegooseModule} from "nestjs-typegoose"
|
||||
import {Form} from "./models/form.model"
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypegooseModule.forFeature([Form]),
|
||||
],
|
||||
exports: [],
|
||||
controllers,
|
||||
providers,
|
||||
})
|
||||
export class FormModule {}
|
||||
@ -1,5 +0,0 @@
|
||||
import { FormService } from "./services/form.service"
|
||||
|
||||
export default [
|
||||
FormService
|
||||
]
|
||||
@ -1,5 +0,0 @@
|
||||
import { Document } from 'mongoose';
|
||||
|
||||
export interface Button extends Document{
|
||||
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
import { Document } from 'mongoose';
|
||||
|
||||
export interface Field extends Document{
|
||||
|
||||
}
|
||||
@ -1,51 +0,0 @@
|
||||
import { Document } from 'mongoose';
|
||||
import { Field } from "./field.interface"
|
||||
import { Button } from "./button.interface"
|
||||
|
||||
export class Form extends Document{
|
||||
readonly firstName: string;
|
||||
readonly language: string;
|
||||
readonly analytics: string;
|
||||
readonly form_fields: Field[];
|
||||
readonly admin: any;
|
||||
readonly startPage: {
|
||||
readonly showStart: boolean;
|
||||
readonly introTitle: string;
|
||||
readonly introParagraph: string;
|
||||
readonly introButtonText: string;
|
||||
readonly buttons: Button[];
|
||||
};
|
||||
readonly endPage: {
|
||||
readonly showEnd: boolean;
|
||||
readonly title: string;
|
||||
readonly paragraph: string;
|
||||
readonly buttonText: string;
|
||||
readonly buttons: Button[];
|
||||
};
|
||||
readonly selfNotifications: {
|
||||
readonly fromField: string;
|
||||
readonly toEmails: string;
|
||||
readonly subject: string;
|
||||
readonly htmlTemplate: string;
|
||||
readonly enabled: boolean;
|
||||
};
|
||||
readonly respondentNotifications: {
|
||||
readonly toField: string;
|
||||
readonly fromEmails: string;
|
||||
readonly subject: string;
|
||||
readonly htmlTemplate: string;
|
||||
readonly enabled: boolean;
|
||||
};
|
||||
readonly showFooter: boolean;
|
||||
readonly isLive: boolean;
|
||||
readonly design: {
|
||||
readonly colors: {
|
||||
readonly backgroundColor: string;
|
||||
readonly questionColor: string;
|
||||
readonly answerColor: string;
|
||||
readonly buttonColor: string;
|
||||
readonly buttonTextColor: string;
|
||||
};
|
||||
readonly font: string;
|
||||
};
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
import {prop} from "typegoose"
|
||||
import {VisitorData} from "./visitor.data"
|
||||
import {Exclude} from "class-transformer"
|
||||
|
||||
export class Analytics {
|
||||
@Exclude()
|
||||
readonly _id: string;
|
||||
|
||||
@prop()
|
||||
gaCode: string;
|
||||
|
||||
@prop()
|
||||
visitors: VisitorData[]
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
import {Exclude} from "class-transformer"
|
||||
import {prop} from "typegoose"
|
||||
|
||||
export class Button {
|
||||
@Exclude()
|
||||
readonly _id: string;
|
||||
|
||||
@prop({
|
||||
match: /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/
|
||||
})
|
||||
url: string;
|
||||
|
||||
@prop()
|
||||
action: string;
|
||||
|
||||
@prop()
|
||||
text: string;
|
||||
|
||||
@prop({
|
||||
match: [/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/],
|
||||
default: '#5bc0de'
|
||||
})
|
||||
bgColor: string;
|
||||
|
||||
@prop({
|
||||
match: [/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/],
|
||||
default: '#ffffff'
|
||||
})
|
||||
color: string;
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
import {prop, Ref, Typegoose} from "typegoose"
|
||||
import {Exclude} from "class-transformer"
|
||||
|
||||
export class Colors {
|
||||
@Exclude()
|
||||
readonly _id: string;
|
||||
|
||||
@prop({
|
||||
match: [/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/],
|
||||
default: '#fff'
|
||||
})
|
||||
readonly backgroundColor: string;
|
||||
|
||||
@prop({
|
||||
match: [/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/],
|
||||
default: '#333'
|
||||
})
|
||||
readonly questionColor: string;
|
||||
|
||||
@prop({
|
||||
match: [/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/],
|
||||
default: '#333'
|
||||
})
|
||||
readonly answerColor: string;
|
||||
|
||||
@prop({
|
||||
match: [/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/],
|
||||
default: '#fff'
|
||||
})
|
||||
readonly buttonColor: string;
|
||||
|
||||
@prop({
|
||||
match: [/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/],
|
||||
default: '#333'
|
||||
})
|
||||
readonly buttonTextColor: string;
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
import {prop} from "typegoose"
|
||||
import {Colors} from "./colors"
|
||||
import {Exclude} from "class-transformer"
|
||||
|
||||
export class Design {
|
||||
@Exclude()
|
||||
readonly _id: string;
|
||||
|
||||
@prop()
|
||||
readonly colors: Colors;
|
||||
|
||||
@prop()
|
||||
readonly font: string;
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
import {prop} from "typegoose"
|
||||
import {Button} from "./button"
|
||||
import {Exclude} from "class-transformer"
|
||||
|
||||
export class EndPage {
|
||||
@Exclude()
|
||||
readonly _id: string;
|
||||
|
||||
@prop({
|
||||
default: false
|
||||
})
|
||||
readonly showEnd: boolean;
|
||||
|
||||
@prop({
|
||||
default: 'Thank you for filling out the form'
|
||||
})
|
||||
readonly title: string;
|
||||
|
||||
@prop()
|
||||
readonly paragraph: string;
|
||||
|
||||
@prop({
|
||||
default: 'Go back to Form'
|
||||
})
|
||||
readonly buttonText: string;
|
||||
|
||||
@prop()
|
||||
readonly buttons: Button[];
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
import {prop} from "typegoose"
|
||||
import {VisitorData} from "./visitor.data"
|
||||
import {Exclude} from "class-transformer"
|
||||
|
||||
export class FieldOption {
|
||||
@Exclude()
|
||||
readonly _id: string;
|
||||
|
||||
@prop()
|
||||
option_id: number;
|
||||
|
||||
@prop()
|
||||
option_title: string;
|
||||
|
||||
@prop({
|
||||
trim: true
|
||||
})
|
||||
option_value: string;
|
||||
}
|
||||
@ -1,83 +0,0 @@
|
||||
import {arrayProp, prop} from "typegoose"
|
||||
import {LogicJump} from "./logic.jump"
|
||||
import {RatingField} from "./rating.field"
|
||||
import {FieldOption} from "./field.option"
|
||||
import {Exclude} from "class-transformer"
|
||||
|
||||
export class Field {
|
||||
@Exclude()
|
||||
readonly _id: string;
|
||||
|
||||
@prop({
|
||||
default: false
|
||||
})
|
||||
isSubmission: boolean;
|
||||
|
||||
@prop()
|
||||
submissionId: string;
|
||||
|
||||
@prop({
|
||||
trim: true
|
||||
})
|
||||
title: string;
|
||||
|
||||
@prop({
|
||||
default: ''
|
||||
})
|
||||
description: string;
|
||||
|
||||
@prop()
|
||||
logicJump: LogicJump;
|
||||
|
||||
@prop()
|
||||
ratingOptions: RatingField;
|
||||
|
||||
@arrayProp({
|
||||
items: FieldOption
|
||||
})
|
||||
fieldOptions: FieldOption[];
|
||||
|
||||
@prop({
|
||||
default: true
|
||||
})
|
||||
required: boolean;
|
||||
|
||||
@prop({
|
||||
default: false
|
||||
})
|
||||
disabled: boolean;
|
||||
|
||||
@prop({
|
||||
default: false
|
||||
})
|
||||
deletePreserved: boolean;
|
||||
|
||||
@arrayProp({
|
||||
items: String
|
||||
})
|
||||
validFieldTypes: boolean;
|
||||
|
||||
@prop({
|
||||
enum: [
|
||||
'textfield',
|
||||
'date',
|
||||
'email',
|
||||
'legal',
|
||||
'textarea',
|
||||
'link',
|
||||
'statement',
|
||||
'dropdown',
|
||||
'rating',
|
||||
'radio',
|
||||
'hidden',
|
||||
'yes_no',
|
||||
'number'
|
||||
]
|
||||
})
|
||||
fieldType: string;
|
||||
|
||||
@prop({
|
||||
default: ''
|
||||
})
|
||||
fieldValue: any;
|
||||
}
|
||||
@ -1,45 +0,0 @@
|
||||
import {prop, Ref} from "typegoose"
|
||||
import {VisitorData} from "./visitor.data"
|
||||
import {Exclude} from "class-transformer"
|
||||
import {Field} from "./field"
|
||||
|
||||
export class LogicJump {
|
||||
@Exclude()
|
||||
readonly _id: string;
|
||||
|
||||
@prop({
|
||||
enum: [
|
||||
'field == static',
|
||||
'field != static',
|
||||
'field > static',
|
||||
'field >= static',
|
||||
'field <= static',
|
||||
'field < static',
|
||||
'field contains static',
|
||||
'field !contains static',
|
||||
'field begins static',
|
||||
'field !begins static',
|
||||
'field ends static',
|
||||
'field !ends static'
|
||||
]
|
||||
})
|
||||
expressionString: string;
|
||||
|
||||
@prop({
|
||||
ref: Field
|
||||
})
|
||||
fieldA: Ref<Field>;
|
||||
|
||||
@prop()
|
||||
valueB: string;
|
||||
|
||||
@prop({
|
||||
ref: Field
|
||||
})
|
||||
jumpTo: Ref<Field>;
|
||||
|
||||
@prop({
|
||||
default: false
|
||||
})
|
||||
enabled: boolean;
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
import {arrayProp, prop} from "typegoose"
|
||||
import {VisitorData} from "./visitor.data"
|
||||
import {Exclude} from "class-transformer"
|
||||
|
||||
export class RatingField {
|
||||
@Exclude()
|
||||
readonly _id: string;
|
||||
|
||||
@prop({
|
||||
min: 1,
|
||||
max: 10
|
||||
})
|
||||
steps: number;
|
||||
|
||||
@prop({
|
||||
enum: [
|
||||
'Heart',
|
||||
'Star',
|
||||
'thumbs-up',
|
||||
'thumbs-down',
|
||||
'Circle',
|
||||
'Square',
|
||||
'Check Circle',
|
||||
'Smile Outlined',
|
||||
'Hourglass',
|
||||
'bell',
|
||||
'Paper Plane',
|
||||
'Comment',
|
||||
'Trash'
|
||||
]
|
||||
})
|
||||
shape: string;
|
||||
|
||||
@arrayProp({
|
||||
items: String
|
||||
})
|
||||
validShapes: [string];
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
import {prop} from "typegoose"
|
||||
import {Exclude} from "class-transformer"
|
||||
|
||||
export class RespondentNotifications {
|
||||
@Exclude()
|
||||
readonly _id: string;
|
||||
|
||||
@prop()
|
||||
readonly toField: string;
|
||||
|
||||
@prop({
|
||||
match: [/.+\@.+\..+/, 'Please fill a valid email address']
|
||||
})
|
||||
readonly fromEmails: string;
|
||||
|
||||
@prop({
|
||||
default: 'OhMyForm: Thank you for filling out this OhMyForm'
|
||||
})
|
||||
readonly subject: string;
|
||||
|
||||
@prop({
|
||||
default: 'Hello, <br><br> We’ve received your submission. <br><br> Thank you & have a nice day!',
|
||||
})
|
||||
readonly htmlTemplate: string;
|
||||
|
||||
@prop({
|
||||
default: false
|
||||
})
|
||||
readonly enabled: boolean;
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
import {prop} from "typegoose"
|
||||
import {Exclude} from "class-transformer"
|
||||
|
||||
export class SelfNotifications {
|
||||
@Exclude()
|
||||
readonly _id: string;
|
||||
|
||||
@prop()
|
||||
readonly fromField: string;
|
||||
|
||||
@prop()
|
||||
readonly toEmails: string;
|
||||
|
||||
@prop()
|
||||
readonly subject: string;
|
||||
|
||||
@prop()
|
||||
readonly htmlTemplate: string;
|
||||
|
||||
@prop({
|
||||
default: false
|
||||
})
|
||||
readonly enabled: boolean;
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
import {prop} from "typegoose"
|
||||
import {Button} from "./button"
|
||||
import {Exclude} from "class-transformer"
|
||||
|
||||
export class StartPage {
|
||||
@Exclude()
|
||||
readonly _id: string;
|
||||
|
||||
@prop({
|
||||
default: false
|
||||
})
|
||||
readonly showStart: boolean;
|
||||
|
||||
@prop({
|
||||
default: 'Welcome to Form'
|
||||
})
|
||||
readonly introTitle: string;
|
||||
|
||||
@prop()
|
||||
readonly introParagraph: string;
|
||||
|
||||
@prop({
|
||||
default: 'Start'
|
||||
})
|
||||
readonly introButtonText: string;
|
||||
|
||||
@prop()
|
||||
readonly buttons: Button[];
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
import {Exclude} from "class-transformer"
|
||||
import {arrayProp, prop} from "typegoose"
|
||||
import {Field} from "./field"
|
||||
import {Ref} from "typegoose/lib/prop"
|
||||
|
||||
export class VisitorData {
|
||||
@Exclude()
|
||||
readonly _id: string;
|
||||
|
||||
@prop()
|
||||
readonly introParagraph: string;
|
||||
|
||||
@prop()
|
||||
readonly referrer: string;
|
||||
|
||||
@arrayProp({
|
||||
itemsRef: Field
|
||||
})
|
||||
readonly filledOutFields: Ref<Field>[];
|
||||
|
||||
@prop()
|
||||
readonly timeElapsed: number;
|
||||
|
||||
@prop()
|
||||
readonly isSubmitted: boolean;
|
||||
|
||||
@prop({
|
||||
enum: ['en', 'fr', 'es', 'it', 'de'],
|
||||
default: 'en',
|
||||
})
|
||||
readonly language: string;
|
||||
|
||||
@prop()
|
||||
readonly ipAddr: string;
|
||||
|
||||
@prop({
|
||||
enum: ['desktop', 'phone', 'tablet', 'other'],
|
||||
default: 'other'
|
||||
})
|
||||
readonly deviceType: string;
|
||||
|
||||
@prop()
|
||||
readonly userAgent: string;
|
||||
}
|
||||
@ -1,72 +0,0 @@
|
||||
import {arrayProp, prop, Ref, Typegoose} from "typegoose"
|
||||
import {Analytics} from "./embedded/analytics"
|
||||
import {Field} from "./embedded/field"
|
||||
import {StartPage} from "./embedded/start.page"
|
||||
import {EndPage} from "./embedded/end.page"
|
||||
import {SelfNotifications} from "./embedded/self.notifications"
|
||||
import {RespondentNotifications} from "./embedded/respondent.notifications"
|
||||
import {Design} from "./embedded/design"
|
||||
import {User} from "../../user/models/user.model"
|
||||
|
||||
export class Form extends Typegoose {
|
||||
readonly _id: any;
|
||||
|
||||
@prop({
|
||||
trim: true,
|
||||
required: 'Form Title cannot be blank'
|
||||
})
|
||||
readonly title: string;
|
||||
|
||||
@prop()
|
||||
readonly created: any;
|
||||
|
||||
@prop()
|
||||
readonly lastModified: any;
|
||||
|
||||
@prop({
|
||||
enum: ['en', 'fr', 'es', 'it', 'de'],
|
||||
default: 'en',
|
||||
required: 'Form must have a language'
|
||||
})
|
||||
readonly language: string;
|
||||
|
||||
@prop()
|
||||
readonly analytics: Analytics;
|
||||
|
||||
@arrayProp({
|
||||
items: Field,
|
||||
default: []
|
||||
})
|
||||
readonly form_fields: Field[];
|
||||
|
||||
@prop({
|
||||
ref: User,
|
||||
required: 'Form must have an Admin'
|
||||
})
|
||||
readonly admin: Ref<User>;
|
||||
|
||||
@prop()
|
||||
readonly startPage: StartPage;
|
||||
|
||||
@prop()
|
||||
readonly endPage: EndPage;
|
||||
|
||||
@prop()
|
||||
readonly selfNotifications: SelfNotifications;
|
||||
|
||||
@prop()
|
||||
readonly respondentNotifications: RespondentNotifications;
|
||||
|
||||
@prop({
|
||||
default: true
|
||||
})
|
||||
readonly showFooter: boolean;
|
||||
|
||||
@prop({
|
||||
default: true
|
||||
})
|
||||
readonly isLive: boolean;
|
||||
|
||||
@prop()
|
||||
readonly design: Design;
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
import {Injectable} from '@nestjs/common';
|
||||
import { InjectModel } from 'nestjs-typegoose';
|
||||
import { ModelType } from 'typegoose';
|
||||
import {Form} from "../models/form.model"
|
||||
import {User} from "../../user/models/user.model"
|
||||
|
||||
@Injectable()
|
||||
export class FormService {
|
||||
constructor(@InjectModel(Form) private readonly formModel: ModelType<Form>) {}
|
||||
|
||||
async findById(id: string): Promise<Form> {
|
||||
return await this.formModel.findById(id).exec()
|
||||
}
|
||||
|
||||
async findBy(conditions): Promise<Form[]> {
|
||||
return await this.formModel.find(conditions).exec()
|
||||
}
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
|
||||
export class OptionsDto {
|
||||
template: string;
|
||||
|
||||
language?: string;
|
||||
|
||||
to: string;
|
||||
|
||||
cc?: string[];
|
||||
|
||||
bcc?: string[];
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
import { MailService } from "./services/mail.service"
|
||||
|
||||
export default [
|
||||
MailService
|
||||
]
|
||||
@ -1,12 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import providers from './mail.providers'
|
||||
import exportList from './mail.exports'
|
||||
import { HandlebarsAdapter, MailerModule } from "@nest-modules/mailer"
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
],
|
||||
providers,
|
||||
exports: exportList,
|
||||
})
|
||||
export class MailModule {}
|
||||
@ -1,5 +0,0 @@
|
||||
import { MailService } from "./services/mail.service"
|
||||
|
||||
export default [
|
||||
MailService
|
||||
]
|
||||
@ -1,35 +0,0 @@
|
||||
import {Inject, Injectable, NotFoundException} from '@nestjs/common';
|
||||
import { OptionsDto } from "../dto/options.dto"
|
||||
import { MailerService } from '@nest-modules/mailer';
|
||||
import * as Handlebars from 'handlebars'
|
||||
import * as fs from 'fs';
|
||||
|
||||
@Injectable()
|
||||
export class MailService {
|
||||
constructor(
|
||||
private readonly nodeMailer: MailerService
|
||||
) {}
|
||||
|
||||
async sendEmail(options:OptionsDto, placeholders:any): Promise<boolean> {
|
||||
const template = fs.readFileSync(`${__dirname}/../../../views/en/mail/${options.template}.hbs`, 'UTF-8');
|
||||
|
||||
const parts = Handlebars
|
||||
.compile(template)
|
||||
(placeholders)
|
||||
.split('---')
|
||||
|
||||
const mail:any = {
|
||||
to: options.to,
|
||||
subject: parts[0],
|
||||
text: parts[1],
|
||||
}
|
||||
|
||||
if (parts.length > 2) {
|
||||
mail.html = parts[2]
|
||||
}
|
||||
|
||||
await this.nodeMailer.sendMail(mail)
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
import {NestFactory, Reflector} from '@nestjs/core';
|
||||
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
||||
import { AppModule } from './app.module';
|
||||
import { ClassSerializerInterceptor, ValidationPipe } from '@nestjs/common';
|
||||
import { useContainer } from "class-validator"
|
||||
const pkg = require('../package.json')
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule, { cors: true });
|
||||
|
||||
useContainer(app.select(AppModule), { fallbackOnErrors: true });
|
||||
|
||||
app.useGlobalPipes(new ValidationPipe({
|
||||
disableErrorMessages: false,
|
||||
transform: true,
|
||||
}));
|
||||
|
||||
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)))
|
||||
|
||||
const options = new DocumentBuilder()
|
||||
.setTitle('OhMyForm')
|
||||
.setDescription('API documentation')
|
||||
.setVersion(pkg.version)
|
||||
.addBearerAuth()
|
||||
.build();
|
||||
|
||||
const document = SwaggerModule.createDocument(app, options);
|
||||
SwaggerModule.setup('doc', app, document);
|
||||
|
||||
await app.listen(3000);
|
||||
}
|
||||
|
||||
bootstrap();
|
||||
@ -1,29 +0,0 @@
|
||||
import {
|
||||
TerminusEndpoint,
|
||||
TerminusOptionsFactory,
|
||||
DNSHealthIndicator,
|
||||
MongooseHealthIndicator,
|
||||
TerminusModuleOptions
|
||||
} from '@nestjs/terminus';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class TerminusOptionsService implements TerminusOptionsFactory {
|
||||
constructor(
|
||||
private readonly dns: DNSHealthIndicator,
|
||||
private readonly mongoose: MongooseHealthIndicator
|
||||
) {}
|
||||
|
||||
createTerminusOptions(): TerminusModuleOptions {
|
||||
const healthEndpoint: TerminusEndpoint = {
|
||||
url: '/health',
|
||||
healthIndicators: [
|
||||
async () => this.dns.pingCheck('mail', 'https://google.com'),
|
||||
async () => this.mongoose.pingCheck('mongo')
|
||||
],
|
||||
};
|
||||
return {
|
||||
endpoints: [healthEndpoint],
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
import {Controller, Request, Get, Post, Put, Delete, UseGuards, Param, NotImplementedException} from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { ApiBearerAuth, ApiImplicitQuery, ApiResponse, ApiUseTags } from "@nestjs/swagger"
|
||||
import { UserService } from "../services/user.service"
|
||||
import { UserDto } from "../dto/user.dto"
|
||||
import { FindOneDto } from "../../core/dto/find.one.dto"
|
||||
|
||||
@ApiUseTags('users')
|
||||
@ApiBearerAuth()
|
||||
@Controller('users')
|
||||
export class UserController {
|
||||
constructor(private readonly userService: UserService) {}
|
||||
|
||||
@Get()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
async list(@Request() req): Promise<UserDto[]> {
|
||||
// TODO calculate total forms, add for pagination
|
||||
const results = await this.userService.findBy({})
|
||||
return results.map(form => new UserDto(form))
|
||||
}
|
||||
|
||||
@ApiResponse({ status: 200, description: 'User Object', type: UserDto})
|
||||
@Post()
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
async create(@Request() req): Promise<UserDto> {
|
||||
throw new NotImplementedException()
|
||||
}
|
||||
|
||||
@ApiResponse({ status: 200, description: 'User Object', type: UserDto})
|
||||
@ApiImplicitQuery({name: 'id', type: String})
|
||||
@Get(':id')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
async read(@Param() params: FindOneDto): Promise<UserDto> {
|
||||
return new UserDto(await this.userService.findById(params.id));
|
||||
}
|
||||
|
||||
@ApiResponse({ status: 200, description: 'User Object', type: UserDto})
|
||||
@ApiImplicitQuery({name: 'id', type: String})
|
||||
@Put(':id')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
async update(@Param() params: FindOneDto, @Request() req): Promise<UserDto> {
|
||||
throw new NotImplementedException()
|
||||
}
|
||||
|
||||
|
||||
@ApiResponse({ status: 200, description: 'User Object', type: UserDto})
|
||||
@ApiImplicitQuery({name: 'id', type: String})
|
||||
@Delete(':id')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
async delete(@Param() params: FindOneDto): Promise<void> {
|
||||
throw new NotImplementedException()
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
import { ApiModelProperty } from '@nestjs/swagger';
|
||||
import {User} from "../models/user.model"
|
||||
|
||||
export class UserDto {
|
||||
@ApiModelProperty()
|
||||
id: string;
|
||||
|
||||
@ApiModelProperty()
|
||||
username: string;
|
||||
|
||||
@ApiModelProperty()
|
||||
email: string;
|
||||
|
||||
@ApiModelProperty()
|
||||
roles: string[];
|
||||
|
||||
@ApiModelProperty()
|
||||
created: Date;
|
||||
|
||||
constructor(partial: Partial<User>) {
|
||||
this.id = partial._id.toString()
|
||||
this.username = partial.username
|
||||
this.email = partial.email
|
||||
this.roles = partial.roles
|
||||
this.created = partial.created
|
||||
}
|
||||
}
|
||||
@ -1,97 +0,0 @@
|
||||
import {arrayProp, pre, prop, Typegoose} from 'typegoose';
|
||||
import { IsString } from 'class-validator';
|
||||
import {Exclude} from "class-transformer"
|
||||
|
||||
@pre<User>('save', (next) => {
|
||||
this.lastModified = new Date()
|
||||
next()
|
||||
})
|
||||
export class User extends Typegoose {
|
||||
@Exclude()
|
||||
readonly _id: string;
|
||||
|
||||
@prop({
|
||||
trim: true,
|
||||
default: ''
|
||||
})
|
||||
firstName: string;
|
||||
|
||||
@prop({
|
||||
trim: true,
|
||||
default: ''
|
||||
})
|
||||
lastName: string;
|
||||
|
||||
@prop({
|
||||
trim: true,
|
||||
lowercase: true,
|
||||
unique: true, // 'Account already exists with this email',
|
||||
match: [
|
||||
/^(([^<>()\[\]\\.,;:\s@']+(\.[^<>()\[\]\\.,;:\s@']+)*)|('.+'))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
||||
'Please fill a valid email address'
|
||||
],
|
||||
required: [true, 'Email is required']
|
||||
})
|
||||
email: string;
|
||||
|
||||
@prop({
|
||||
unique: true,
|
||||
lowercase: true,
|
||||
match: [
|
||||
/^[a-zA-Z0-9\-]+$/,
|
||||
'Username can only contain alphanumeric characters and \'-\''
|
||||
],
|
||||
required: [true, 'Username is required']
|
||||
})
|
||||
username: string;
|
||||
|
||||
@prop({
|
||||
default: ''
|
||||
})
|
||||
passwordHash: string;
|
||||
|
||||
@prop()
|
||||
salt: string;
|
||||
|
||||
@prop({
|
||||
default: 'local'
|
||||
})
|
||||
provider: string;
|
||||
|
||||
@arrayProp({
|
||||
items: String,
|
||||
enum: ['user', 'admin', 'superuser'],
|
||||
default: ['user']
|
||||
})
|
||||
roles: [string];
|
||||
|
||||
@prop({
|
||||
enum: ['en', 'fr', 'es', 'it', 'de'],
|
||||
default: 'en',
|
||||
})
|
||||
language: string;
|
||||
|
||||
@prop({
|
||||
default: Date.now
|
||||
})
|
||||
readonly created: Date;
|
||||
|
||||
@prop()
|
||||
readonly lastModified: Date;
|
||||
|
||||
@prop()
|
||||
resetPasswordToken: string;
|
||||
|
||||
@prop()
|
||||
resetPasswordExpires: Date;
|
||||
|
||||
@prop()
|
||||
token: string;
|
||||
|
||||
@prop({
|
||||
unique: true,
|
||||
index: true,
|
||||
sparse: true
|
||||
})
|
||||
apiKey: string;
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { UserService } from './users.service';
|
||||
|
||||
describe('UsersService', () => {
|
||||
let service: UserService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [UserService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<UserService>(UserService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@ -1,44 +0,0 @@
|
||||
import {Injectable, NotFoundException} from '@nestjs/common';
|
||||
import { InjectModel } from 'nestjs-typegoose';
|
||||
import { ModelType } from 'typegoose';
|
||||
import { User } from "../models/user.model"
|
||||
import {Form} from "../../form/models/form.model"
|
||||
|
||||
@Injectable()
|
||||
export class UserService {
|
||||
constructor(@InjectModel(User) private readonly userModel: ModelType<User>) {}
|
||||
|
||||
async findOneByIdentifier(identifier: string): Promise<User> {
|
||||
const results = await this.userModel.find().or([
|
||||
{
|
||||
username: identifier
|
||||
},
|
||||
{
|
||||
email: identifier
|
||||
}
|
||||
]).exec();
|
||||
|
||||
if (results.length !== 1) {
|
||||
throw new NotFoundException()
|
||||
}
|
||||
|
||||
return results[0]
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<User> {
|
||||
return await this.userModel.findById(id).exec()
|
||||
}
|
||||
|
||||
async findOneBy(conditions): Promise<User> {
|
||||
return await this.userModel.findOne(conditions).exec()
|
||||
}
|
||||
|
||||
async findBy(conditions): Promise<User[]> {
|
||||
return await this.userModel.find(conditions).exec()
|
||||
}
|
||||
|
||||
async save(user: User): Promise<User> {
|
||||
let model = new this.userModel(user)
|
||||
return await model.save()
|
||||
}
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
import { UserController } from "./controllers/user.controller"
|
||||
|
||||
export default [
|
||||
UserController,
|
||||
]
|
||||
@ -1,9 +0,0 @@
|
||||
import { UserService } from "./services/user.service"
|
||||
import { UsernameAlreadyInUse } from "./validators/UsernameAlreadyInUse"
|
||||
import { EmailAlreadyInUse } from "./validators/EmailAlreadyInUse"
|
||||
|
||||
export default [
|
||||
UserService,
|
||||
UsernameAlreadyInUse,
|
||||
EmailAlreadyInUse,
|
||||
]
|
||||
@ -1,16 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypegooseModule } from 'nestjs-typegoose';
|
||||
import providers from './user.providers'
|
||||
import exportList from './user.exports'
|
||||
import { User } from "./models/user.model"
|
||||
import controllers from './user.controllers'
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypegooseModule.forFeature([User]),
|
||||
],
|
||||
controllers,
|
||||
providers,
|
||||
exports: exportList,
|
||||
})
|
||||
export class UserModule {}
|
||||
@ -1,9 +0,0 @@
|
||||
import { UserService } from "./services/user.service"
|
||||
import { UsernameAlreadyInUse } from "./validators/UsernameAlreadyInUse"
|
||||
import { EmailAlreadyInUse } from "./validators/EmailAlreadyInUse"
|
||||
|
||||
export default [
|
||||
UserService,
|
||||
UsernameAlreadyInUse,
|
||||
EmailAlreadyInUse,
|
||||
]
|
||||
@ -1,20 +0,0 @@
|
||||
import { ValidationArguments, ValidatorConstraint } from "class-validator"
|
||||
import { Inject, Injectable } from "@nestjs/common"
|
||||
import { UserService } from "../services/user.service"
|
||||
|
||||
@ValidatorConstraint({ name: 'EmailAlreadyInUse', async: true })
|
||||
@Injectable()
|
||||
export class EmailAlreadyInUse {
|
||||
constructor(
|
||||
@Inject('UserService') private readonly userService: UserService,
|
||||
) {}
|
||||
|
||||
async validate(text: string) {
|
||||
const user = await this.userService.findOneBy({email: text});
|
||||
return !user;
|
||||
}
|
||||
|
||||
defaultMessage(args: ValidationArguments) {
|
||||
return 'User with this email already exists.';
|
||||
}
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
import { ValidationArguments, ValidatorConstraint } from "class-validator"
|
||||
import { Inject, Injectable } from "@nestjs/common"
|
||||
import { UserService } from "../services/user.service"
|
||||
|
||||
@ValidatorConstraint({ name: 'UsernameAlreadyInUse', async: true })
|
||||
@Injectable()
|
||||
export class UsernameAlreadyInUse {
|
||||
constructor(
|
||||
@Inject('UserService') private readonly userService: UserService,
|
||||
) {}
|
||||
|
||||
async validate(text: string) {
|
||||
const user = await this.userService.findOneBy({username: text});
|
||||
return !user;
|
||||
}
|
||||
|
||||
defaultMessage(args: ValidationArguments) {
|
||||
return 'User with this username already exists.';
|
||||
}
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"removeComments": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"target": "es2017",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./",
|
||||
"incremental": true
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
@ -1,59 +0,0 @@
|
||||
{
|
||||
"defaultSeverity": "error",
|
||||
"extends": [
|
||||
"tslint:recommended"
|
||||
],
|
||||
"jsRules": {
|
||||
"no-unused-expression": true
|
||||
},
|
||||
"rules": {
|
||||
"eofline": false,
|
||||
"quotemark": [
|
||||
true,
|
||||
"single"
|
||||
],
|
||||
"indent": false,
|
||||
"member-access": [
|
||||
false
|
||||
],
|
||||
"ordered-imports": [
|
||||
false
|
||||
],
|
||||
"max-line-length": [
|
||||
true,
|
||||
150
|
||||
],
|
||||
"member-ordering": [
|
||||
false
|
||||
],
|
||||
"curly": false,
|
||||
"interface-name": [
|
||||
false
|
||||
],
|
||||
"array-type": [
|
||||
false
|
||||
],
|
||||
"no-empty-interface": false,
|
||||
"no-empty": false,
|
||||
"arrow-parens": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"no-unused-expression": false,
|
||||
"max-classes-per-file": [
|
||||
false
|
||||
],
|
||||
"variable-name": [
|
||||
false
|
||||
],
|
||||
"one-line": [
|
||||
false
|
||||
],
|
||||
"one-variable-per-declaration": [
|
||||
false
|
||||
],
|
||||
"whitespace": [
|
||||
true,
|
||||
"check-postbrace"
|
||||
]
|
||||
},
|
||||
"rulesDirectory": []
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
Password Reset Request
|
||||
---
|
||||
Hi,
|
||||
|
||||
if you have not requested a new password you can ignore this email. To set a new password for your account
|
||||
just follow this link: {{ recover }}
|
||||
|
||||
See you soon
|
||||
---
|
||||
<h1>Hi, </h1>
|
||||
|
||||
<p>
|
||||
if you have not requested a new password you can ignore this email. To set a new password for your account
|
||||
just follow this link: <a href="{{ recover }}">{{ recover }}</a>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
See you soon
|
||||
</p>
|
||||
@ -1,14 +0,0 @@
|
||||
Welcome to OhMyForm
|
||||
---
|
||||
Welcome to OhMyForm!
|
||||
|
||||
please confirm your account by following the following link: {{ confirm }}
|
||||
|
||||
enjoy!
|
||||
---
|
||||
<h1>Welcome to OhMyForm!</h1>
|
||||
<p>
|
||||
please confirm your account by following the following link: <a href="{{ confirm }}">{{ confirm }}</a>
|
||||
</p>
|
||||
|
||||
<p>enjoy!</p>
|
||||
@ -1,32 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
var config = require('../../config/config');
|
||||
|
||||
/**cd
|
||||
* Module dependencies.
|
||||
*/
|
||||
exports.index = function(req, res) {
|
||||
res.render('index', {
|
||||
user: req.user || null,
|
||||
request: req
|
||||
});
|
||||
};
|
||||
|
||||
exports.form = function(req, res) {
|
||||
|
||||
//Allow form to be embedded
|
||||
res.removeHeader('X-Frame-Options');
|
||||
|
||||
res.render('form', {
|
||||
user: req.user || null,
|
||||
request: req
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
exports.redoc = function(req, res) {
|
||||
res.render('redoc', {
|
||||
request: req
|
||||
});
|
||||
};
|
||||
|
||||
@ -1,46 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Get unique error field name
|
||||
*/
|
||||
var getUniqueErrorMessage = function(err) {
|
||||
var output;
|
||||
|
||||
try {
|
||||
var fieldName = err.err.substring(err.err.lastIndexOf('.$') + 2, err.err.lastIndexOf('_1'));
|
||||
output = fieldName.charAt(0).toUpperCase() + fieldName.slice(1) + ' already exists';
|
||||
|
||||
} catch (ex) {
|
||||
output = 'Unique field already exists';
|
||||
}
|
||||
|
||||
return output;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the error message from error object
|
||||
*/
|
||||
exports.getErrorMessage = function(err) {
|
||||
var message = '';
|
||||
|
||||
if(!err) {
|
||||
return 'Unknown Error';
|
||||
} else if(typeof err === 'string'){
|
||||
message = err;
|
||||
} else if (err.code) {
|
||||
switch (err.code) {
|
||||
case 11000:
|
||||
case 11001:
|
||||
message = getUniqueErrorMessage(err);
|
||||
break;
|
||||
default:
|
||||
message = 'Something went wrong';
|
||||
}
|
||||
} else {
|
||||
for (var errName in err.errors) {
|
||||
if (err.errors[errName].message) message = err.errors[errName].message;
|
||||
}
|
||||
}
|
||||
|
||||
return message;
|
||||
};
|
||||
@ -1,561 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var mongoose = require('mongoose'),
|
||||
errorHandler = require('./errors.server.controller'),
|
||||
Form = mongoose.model('Form'),
|
||||
FormSubmission = mongoose.model('FormSubmission'),
|
||||
config = require('../../config/config'),
|
||||
diff = require('deep-diff'),
|
||||
_ = require('lodash'),
|
||||
nodemailer = require('nodemailer'),
|
||||
emailNotifications = require('../libs/send-email-notifications'),
|
||||
constants = require('../libs/constants'),
|
||||
helpers = require('./helpers.server.controller'),
|
||||
async = require('async');
|
||||
|
||||
var smtpTransport = nodemailer.createTransport(config.mailer.options);
|
||||
|
||||
/**
|
||||
* Delete a forms submissions
|
||||
*/
|
||||
exports.deleteSubmissions = function(req, res) {
|
||||
|
||||
var submission_id_list = req.body.deleted_submissions;
|
||||
|
||||
FormSubmission.remove({ form: req.form, _id: {$in: submission_id_list} }, function(err){
|
||||
|
||||
if(err){
|
||||
res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
res.status(200).send('Form submissions successfully deleted');
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Submit a form entry
|
||||
*/
|
||||
exports.createSubmission = function(req, res) {
|
||||
|
||||
var timeElapsed = 0;
|
||||
|
||||
if(typeof req.body.timeElapsed === 'number'){
|
||||
timeElapsed = req.body.timeElapsed;
|
||||
}
|
||||
var submission = new FormSubmission({
|
||||
form: req.body._id,
|
||||
form_fields: req.body.form_fields,
|
||||
timeElapsed: timeElapsed,
|
||||
percentageComplete: req.body.percentageComplete,
|
||||
ipAddr: req.body.ipAddr,
|
||||
geoLocation: req.body.geoLocation,
|
||||
device: req.body.device
|
||||
});
|
||||
|
||||
submission.save(function(err, submission){
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return res.status(500).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
}
|
||||
var form = req.body;
|
||||
var formFieldDict = emailNotifications.createFieldDict(form.form_fields);
|
||||
|
||||
async.waterfall([
|
||||
function(callback) {
|
||||
if (form.selfNotifications && form.selfNotifications.enabled) {
|
||||
if(form.selfNotifications.fromField){
|
||||
form.selfNotifications.fromEmails = formFieldDict[form.selfNotifications.fromField];
|
||||
} else {
|
||||
form.selfNotifications.fromEmails = config.mailer.options.from;
|
||||
}
|
||||
|
||||
emailNotifications.send(form.selfNotifications, formFieldDict, smtpTransport, function(err){
|
||||
if(err){
|
||||
return callback({
|
||||
message: 'Failure sending submission self-notification email'
|
||||
});
|
||||
}
|
||||
|
||||
callback();
|
||||
});
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
},
|
||||
function(callback) {
|
||||
if (form.respondentNotifications && form.respondentNotifications.enabled && form.respondentNotifications.toField) {
|
||||
|
||||
form.respondentNotifications.toEmails = formFieldDict[form.respondentNotifications.toField];
|
||||
emailNotifications.send(form.respondentNotifications, formFieldDict, smtpTransport, function(err){
|
||||
if(err){
|
||||
return callback({
|
||||
message: 'Failure sending submission respondent-notification email'
|
||||
});
|
||||
}
|
||||
|
||||
callback();
|
||||
});
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
], function (err) {
|
||||
if(err){
|
||||
return res.status(400).send(err);
|
||||
}
|
||||
res.status(200).send('Form submission successfully saved');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Get List of Submissions for a given Form
|
||||
*/
|
||||
exports.listSubmissions = function(req, res) {
|
||||
FormSubmission.find({ form: req.form._id }).sort('created').lean().exec(function(err, _submissions) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return res.status(500).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
}
|
||||
res.json(_submissions);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Visitor Analytics Data for a given Form
|
||||
*/
|
||||
exports.getVisitorData = function(req, res) {
|
||||
var results = [];
|
||||
|
||||
Form.aggregate([
|
||||
{
|
||||
$match: {
|
||||
_id: mongoose.Types.ObjectId(req.form.id),
|
||||
admin: mongoose.Types.ObjectId(req.user.id)
|
||||
}
|
||||
},
|
||||
{
|
||||
$facet: {
|
||||
'deviceStatistics': [
|
||||
{
|
||||
$unwind: '$analytics.visitors'
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
_id: 0,
|
||||
deviceType: '$analytics.visitors.deviceType',
|
||||
SubmittedTimeElapsed: {
|
||||
$cond: [
|
||||
{
|
||||
$eq: ['$analytics.visitors.isSubmitted', true]
|
||||
},
|
||||
'$analytics.visitors.timeElapsed',
|
||||
0
|
||||
]
|
||||
},
|
||||
SubmittedResponses: {
|
||||
$cond: [
|
||||
{
|
||||
$eq: ['$analytics.visitors.isSubmitted', true]
|
||||
},
|
||||
1,
|
||||
0
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: '$deviceType',
|
||||
total_time: { $sum: '$SubmittedTimeElapsed' },
|
||||
responses: { $sum: '$SubmittedResponses' },
|
||||
visits: { $sum: 1 }
|
||||
}
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
total_time: '$total_time',
|
||||
responses: '$responses',
|
||||
visits: '$visits',
|
||||
average_time: {
|
||||
$cond: [
|
||||
{ $eq: [ '$responses', 0 ] },
|
||||
0,
|
||||
{ $divide: ['$total_time', '$responses'] }
|
||||
]
|
||||
},
|
||||
conversion_rate: {
|
||||
$multiply: [
|
||||
100,
|
||||
{
|
||||
$cond: [
|
||||
{ $eq: [ '$visits', 0 ] },
|
||||
0,
|
||||
{ $divide: ['$responses', '$visits'] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
'globalStatistics': [
|
||||
{
|
||||
$unwind: '$analytics.visitors'
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
_id: 0,
|
||||
deviceType: '$analytics.visitors.deviceType',
|
||||
SubmittedTimeElapsed: {
|
||||
$cond: [
|
||||
{
|
||||
$eq: ['$analytics.visitors.isSubmitted', true]
|
||||
},
|
||||
'$analytics.visitors.timeElapsed',
|
||||
0
|
||||
]
|
||||
},
|
||||
SubmittedResponses: {
|
||||
$cond: [
|
||||
{
|
||||
$eq: ['$analytics.visitors.isSubmitted', true]
|
||||
},
|
||||
1,
|
||||
0
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
total_time: { $sum: '$SubmittedTimeElapsed' },
|
||||
responses: { $sum: '$SubmittedResponses' },
|
||||
visits: { $sum: 1 }
|
||||
}
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
_id: 0,
|
||||
total_time: '$total_time',
|
||||
responses: '$responses',
|
||||
visits: '$visits',
|
||||
average_time: {
|
||||
$cond: [
|
||||
{ $eq: [ '$responses', 0 ] },
|
||||
0,
|
||||
{ $divide: ['$total_time', '$responses'] }
|
||||
]
|
||||
},
|
||||
conversion_rate: {
|
||||
$multiply: [
|
||||
100,
|
||||
{
|
||||
$cond: [
|
||||
{ $eq: [ '$visits', 0 ] },
|
||||
0,
|
||||
{ $divide: ['$responses', '$visits'] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
}
|
||||
}
|
||||
])
|
||||
.cursor()
|
||||
.exec()
|
||||
.on('end', function() {
|
||||
res.json(results);
|
||||
})
|
||||
.on('data', function(entry){
|
||||
results.push(entry);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new form
|
||||
*/
|
||||
exports.create = function(req, res) {
|
||||
if(!req.body.form){
|
||||
return res.status(400).send({
|
||||
message: 'Invalid Input'
|
||||
});
|
||||
}
|
||||
|
||||
var form = new Form(req.body.form);
|
||||
form.admin = req.user._id;
|
||||
|
||||
form.save(function(err, createdForm) {
|
||||
if (err) {
|
||||
return res.status(500).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
}
|
||||
|
||||
createdForm = helpers.removeSensitiveModelData('private_form', createdForm.toJSON());
|
||||
return res.json(createdForm);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the current form
|
||||
*/
|
||||
exports.read = function(req, res) {
|
||||
if(!req.user || (req.form.admin.id !== req.user.id) ){
|
||||
readForRender(req, res);
|
||||
} else {
|
||||
if(!req.form){
|
||||
return res.status(404).send({
|
||||
message: 'Form Does Not Exist'
|
||||
});
|
||||
}
|
||||
|
||||
var newForm = helpers.removeSensitiveModelData('private_form', req.form.toJSON());
|
||||
|
||||
return res.json(newForm);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the current form for rendering form live
|
||||
*/
|
||||
var readForRender = exports.readForRender = function(req, res) {
|
||||
var newForm = req.form;
|
||||
if (!newForm.isLive && !req.user) {
|
||||
return res.status(401).send({
|
||||
message: 'Form is Not Public'
|
||||
});
|
||||
}
|
||||
|
||||
newForm = helpers.removeSensitiveModelData('public_form', newForm);
|
||||
|
||||
if(newForm.startPage && !newForm.startPage.showStart){
|
||||
delete newForm.startPage;
|
||||
}
|
||||
|
||||
return res.json(newForm);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update a form
|
||||
*/
|
||||
exports.update = function(req, res) {
|
||||
var form = req.form;
|
||||
var updatedForm = req.body.form;
|
||||
|
||||
if(!form.analytics){
|
||||
form.analytics = {
|
||||
visitors: [],
|
||||
gaCode: ''
|
||||
};
|
||||
}
|
||||
|
||||
if (req.body.changes) {
|
||||
var formChanges = req.body.changes;
|
||||
|
||||
formChanges.forEach(function (change) {
|
||||
diff.applyChange(form._doc, true, change);
|
||||
});
|
||||
} else {
|
||||
if(!updatedForm){
|
||||
return res.status(400).send({
|
||||
message: 'Updated Form is empty'
|
||||
});
|
||||
}
|
||||
|
||||
delete updatedForm.lastModified;
|
||||
delete updatedForm.created;
|
||||
delete updatedForm.id;
|
||||
delete updatedForm._id;
|
||||
delete updatedForm.__v;
|
||||
|
||||
//Unless we have 'admin' privileges, updating the form's admin is disabled
|
||||
if(updatedForm && req.user.roles.indexOf('admin') === -1) {
|
||||
delete updatedForm.admin;
|
||||
}
|
||||
|
||||
//Do this so we can create duplicate fields
|
||||
var checkForValidId = new RegExp('^[0-9a-fA-F]{24}$');
|
||||
for(var i=0; i < req.body.form.form_fields.length; i++){
|
||||
var field = req.body.form.form_fields[i];
|
||||
if(!checkForValidId.exec(field._id+'')){
|
||||
delete field._id;
|
||||
}
|
||||
}
|
||||
form = _.extend(form, updatedForm);
|
||||
}
|
||||
|
||||
form.save(function(err, savedForm) {
|
||||
if (err) {
|
||||
res.status(500).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
} else {
|
||||
savedForm = helpers.removeSensitiveModelData('private_form', savedForm.toJSON());
|
||||
res.json(savedForm);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete a form
|
||||
*/
|
||||
exports.delete = function(req, res) {
|
||||
var form = req.form;
|
||||
Form.remove({_id: form._id}, function(err) {
|
||||
if (err) {
|
||||
res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
} else {
|
||||
res.json(
|
||||
helpers.removeSensitiveModelData('private_form', form)
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Get All of Users' Forms
|
||||
*/
|
||||
exports.list = function(req, res) {
|
||||
//Allow 'admin' user to view all forms
|
||||
var searchObj = {admin: req.user};
|
||||
if(req.user.isAdmin()) searchObj = {};
|
||||
|
||||
Form.find(searchObj)
|
||||
.sort('-created')
|
||||
.select('title language isLive')
|
||||
.lean()
|
||||
.exec(function(err, forms) {
|
||||
if (err) {
|
||||
return res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
}
|
||||
|
||||
var form_ids = forms.map(function(form){
|
||||
return form._id;
|
||||
});
|
||||
|
||||
//Get number of submissions for each form
|
||||
FormSubmission
|
||||
.aggregate()
|
||||
.match({
|
||||
form: {
|
||||
$in: form_ids
|
||||
}
|
||||
})
|
||||
.group({
|
||||
_id: '$form',
|
||||
responses: { $sum: 1 }
|
||||
})
|
||||
.cursor()
|
||||
.exec()
|
||||
.on('end', function() {
|
||||
forms = forms.map(function (form) {
|
||||
if (!form.submissionNum) {
|
||||
form.submissionNum = 0;
|
||||
}
|
||||
|
||||
return helpers.removeSensitiveModelData('private_form', form);
|
||||
});
|
||||
|
||||
res.json(forms);
|
||||
})
|
||||
.on('data', function(result){
|
||||
forms = forms.map(function (form) {
|
||||
if (_.isEqual(form._id, result._id)) {
|
||||
form.submissionNum = result.responses;
|
||||
}
|
||||
|
||||
return form;
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Form middleware
|
||||
*/
|
||||
exports.formByID = function(req, res, next, id) {
|
||||
if (!mongoose.Types.ObjectId.isValid(id)) {
|
||||
return res.status(400).send({
|
||||
message: 'Form is invalid'
|
||||
});
|
||||
}
|
||||
|
||||
Form.findById(id)
|
||||
.select('admin title language form_fields startPage endPage showFooter isLive design analytics.gaCode respondentNotifications selfNotifications')
|
||||
.populate('admin')
|
||||
.exec(function(err, form) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
} else if (!form || form === null) {
|
||||
res.status(404).send({
|
||||
message: 'Form not found'
|
||||
});
|
||||
}
|
||||
else {
|
||||
req.form = form;
|
||||
return next();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* FastForm middleware
|
||||
*/
|
||||
exports.formByIDFast = function(req, res, next, id) {
|
||||
if (!mongoose.Types.ObjectId.isValid(id)) {
|
||||
return res.status(400).send({
|
||||
message: 'Form is invalid'
|
||||
});
|
||||
}
|
||||
Form.findById(id)
|
||||
.lean()
|
||||
.select('title language form_fields startPage endPage showFooter isLive design analytics.gaCode selfNotifications respondentNotifications')
|
||||
.exec(function(err, form) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
} else if (!form || form === null) {
|
||||
res.status(404).send({
|
||||
message: 'Form not found'
|
||||
});
|
||||
}
|
||||
else {
|
||||
//Remove sensitive information from User object
|
||||
req.form = form;
|
||||
return next();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Form authorization middleware
|
||||
*
|
||||
* reject access if the owner of the form is not the current user and the user is not an admin
|
||||
*/
|
||||
exports.hasAuthorization = function(req, res, next) {
|
||||
var form = req.form;
|
||||
if (!req.form.admin || req.form.admin.id !== req.user.id && req.user.roles.indexOf('admin') < 0) {
|
||||
return res.status(403).send({
|
||||
message: 'User '+req.user.username+' is not authorized to edit Form: '+form.title
|
||||
});
|
||||
}
|
||||
return next();
|
||||
};
|
||||
@ -1,33 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const constants = require('../libs/constants');
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = {
|
||||
removeKeysFromDict: function(dict, keys){
|
||||
for(var i=0; i<keys.length; i++){
|
||||
var curr_key = keys[i];
|
||||
if( dict.hasOwnProperty(curr_key) ){
|
||||
delete dict[curr_key];
|
||||
}
|
||||
}
|
||||
return dict;
|
||||
},
|
||||
removeSensitiveModelData: function(type, actual_object){
|
||||
if (typeof actual_object.toJSON === 'function') {
|
||||
actual_object = actual_object.toJSON();
|
||||
}
|
||||
|
||||
var object = _.cloneDeep(actual_object);
|
||||
|
||||
if(constants.privateFields.hasOwnProperty(type)) {
|
||||
object = this.removeKeysFromDict(object, constants.privateFields[type]);
|
||||
}
|
||||
if(object.admin){
|
||||
object.admin = this.removeKeysFromDict(object.admin, constants.privateFields.private_user);
|
||||
}
|
||||
debugger;
|
||||
|
||||
return object;
|
||||
}
|
||||
};
|
||||
@ -1,16 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
let _ = require('lodash');
|
||||
|
||||
/**
|
||||
* Extend user's controller
|
||||
*/
|
||||
module.exports = _.extend(
|
||||
require('./users/users.authentication.server.controller'),
|
||||
require('./users/users.authorization.server.controller'),
|
||||
require('./users/users.password.server.controller'),
|
||||
require('./users/users.profile.server.controller')
|
||||
);
|
||||
@ -1,238 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var errorHandler = require('../errors.server.controller'),
|
||||
mongoose = require('mongoose'),
|
||||
passport = require('passport'),
|
||||
config = require('../../../config/config'),
|
||||
User = mongoose.model('User'),
|
||||
tokgen = require('../../libs/tokenGenerator'),
|
||||
fs = require('fs'),
|
||||
i18n = require('i18n'),
|
||||
async = require('async'),
|
||||
pug = require('pug'),
|
||||
helpers = require('../helpers.server.controller');
|
||||
|
||||
var nev = require('email-verification')(mongoose);
|
||||
|
||||
// NEV setup and configuration ================
|
||||
var config_nev = function () {
|
||||
nev.configure({
|
||||
|
||||
verifyMailOptions: {
|
||||
from: config.mailer.from
|
||||
},
|
||||
|
||||
confirmMailOptions: {
|
||||
from: config.mailer.from
|
||||
},
|
||||
|
||||
persistentUserModel: User,
|
||||
tempUserCollection: config.tempUserCollection,
|
||||
emailAndUsernameUnique: true,
|
||||
expirationTime: 86400, // 24 hours
|
||||
|
||||
verificationURL: config.baseUrl+'/#!/verify/${URL}',
|
||||
transportOptions: config.mailer.options,
|
||||
|
||||
verifySendMailCallback: function(err, info) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
}, function(err, options){
|
||||
if(err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
nev.generateTempUserModel(User, function(err){
|
||||
if(err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
config_nev();
|
||||
|
||||
exports.validateVerificationToken = function(req, res){
|
||||
|
||||
const fn = pug.compileFile(__dirname + '/../../views/welcome.email.view.pug');
|
||||
var renderedHtml = fn(res.locals);
|
||||
|
||||
var emailTemplate = {
|
||||
subject: i18n.__('WELCOME_EMAIL_SUBJECT', config.app.title),
|
||||
html: renderedHtml,
|
||||
text: i18n.__('WELCOME_EMAIL_TEXT')
|
||||
};
|
||||
|
||||
nev.confirmTempUser(req.params.token, emailTemplate, function(err, user) {
|
||||
if(err) {
|
||||
return res.status(500).send( {message: err } );
|
||||
} else if (user){
|
||||
return res.status(200).send('User successfully verified');
|
||||
}
|
||||
// redirect to resend verification email
|
||||
else {
|
||||
return res.status(400).send( {message: 'Verification token is invalid or has expired'} );
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
exports.resendVerificationEmail = function(req, res, next){
|
||||
const fn = pug.compileFile(__dirname + '/../../views/verification.email.view.pug');
|
||||
var renderedHtml = fn(res.locals);
|
||||
|
||||
var emailTemplate = {
|
||||
subject: i18n.__('VERIFICATION_EMAIL_SUBJECT'),
|
||||
html: renderedHtml,
|
||||
text: i18n.__('VERIFICATION_EMAIL_TEXT')
|
||||
};
|
||||
|
||||
nev.resendVerificationEmail(req.body.email, emailTemplate, function(err, userFound) {
|
||||
if(err) {
|
||||
return res.status(500).send( {message: errorHandler.getErrorMessage(err) } );
|
||||
}
|
||||
|
||||
if (userFound){
|
||||
res.status(200).send('Verification email successfully Re-Sent');
|
||||
}else {
|
||||
// user hasn't been found yet
|
||||
res.status(400).send( {message: 'Error: User has not been registered yet'} );
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Signup
|
||||
*/
|
||||
exports.signup = function(req, res) {
|
||||
// For security measures we remove the roles from the req.body object
|
||||
delete req.body.roles;
|
||||
|
||||
// Init Variables
|
||||
var user = new User(req.body);
|
||||
|
||||
// Set language to visitor's language
|
||||
user.language = req.cookies.userLang;
|
||||
|
||||
// Add missing user fields
|
||||
user.provider = 'local';
|
||||
|
||||
// Then save the temporary user
|
||||
nev.createTempUser(user, function (err, existingPersistentUser, newTempUser) {
|
||||
if (err) {
|
||||
console.error('failed to register user', err)
|
||||
return res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
}
|
||||
|
||||
// new user created
|
||||
if (newTempUser) {
|
||||
let renderedHtml;
|
||||
try {
|
||||
let fn = pug.compileFile(__dirname + '/../../views/verification.email.view.pug', {});
|
||||
renderedHtml = fn(res.locals);
|
||||
} catch (e) {
|
||||
console.error('failed to compile mail template', e);
|
||||
renderedHtml = 'welcome!';
|
||||
}
|
||||
|
||||
let URL = newTempUser[nev.options.URLFieldName];
|
||||
let emailTemplate = {
|
||||
subject: i18n.__('VERIFICATION_EMAIL_SUBJECT'),
|
||||
html: renderedHtml,
|
||||
text: i18n.__('VERIFICATION_EMAIL_TEXT')
|
||||
};
|
||||
|
||||
nev.sendVerificationEmail(user.email, URL, emailTemplate, function (sendEmailErr, info) {
|
||||
if (sendEmailErr) {
|
||||
console.error('failed to send verification email', sendEmailErr)
|
||||
return res.status(400).send({
|
||||
message: 'Could not send Verification Email'
|
||||
});
|
||||
}
|
||||
return res.status(200).send({message: 'An email has been sent to you. Please check it to verify your account.'});
|
||||
});
|
||||
} else {
|
||||
return res.status(400).send({message: 'User with username/email already exists!'});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Signin after passport authentication
|
||||
*/
|
||||
exports.signin = function(req, res, next) {
|
||||
passport.authenticate('local', function(err, user, info) {
|
||||
if (err || !user) {
|
||||
res.status(400).send(info);
|
||||
} else {
|
||||
// Remove sensitive data before login
|
||||
user.password = null;
|
||||
user.salt = null;
|
||||
user.provider = null;
|
||||
|
||||
req.login(user, function(loginErr) {
|
||||
if (loginErr) {
|
||||
return res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(loginErr)
|
||||
});
|
||||
}
|
||||
|
||||
res.cookie('langCookie', user.language, { maxAge: 90000, httpOnly: true });
|
||||
|
||||
user = helpers.removeSensitiveModelData('private_user', user.toJSON());
|
||||
return res.json(user);
|
||||
});
|
||||
}
|
||||
})(req, res, next);
|
||||
};
|
||||
|
||||
/**
|
||||
* Signout
|
||||
*/
|
||||
exports.signout = function(req, res) {
|
||||
if(req.cookies.hasOwnProperty('userLang')){
|
||||
res.clearCookie('userLang');
|
||||
}
|
||||
req.logout();
|
||||
return res.status(200).send('You have successfully logged out.');
|
||||
};
|
||||
|
||||
/* Generate API Key for User */
|
||||
exports.generateAPIKey = function(req, res) {
|
||||
User.findById(req.user.id)
|
||||
.exec( function(err, user) {
|
||||
if (err) {
|
||||
return res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
return res.status(400).send({
|
||||
message: 'User does not Exist'
|
||||
});
|
||||
}
|
||||
|
||||
user.apiKey = tokgen();
|
||||
|
||||
user.save(function(userSaveErr, _user) {
|
||||
if (userSaveErr) {
|
||||
return res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(userSaveErr)
|
||||
});
|
||||
}
|
||||
|
||||
var newUser = _user.toObject();
|
||||
|
||||
return res.json({ id: newUser._id, apiKey: newUser.apiKey });
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
@ -1,18 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var auth = require('../../../config/passport_helpers');
|
||||
/**
|
||||
* Require login routing middleware
|
||||
*/
|
||||
exports.requiresLogin = function(req, res, next) {
|
||||
if (!req.isAuthenticated()) {
|
||||
return res.status(401).send({
|
||||
message: 'User is not logged in'
|
||||
});
|
||||
} else {
|
||||
return next();
|
||||
}
|
||||
};
|
||||
@ -1,287 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var _ = require('lodash'),
|
||||
errorHandler = require('../errors.server.controller'),
|
||||
mongoose = require('mongoose'),
|
||||
passport = require('passport'),
|
||||
User = mongoose.model('User'),
|
||||
config = require('../../../config/config'),
|
||||
nodemailer = require('nodemailer'),
|
||||
async = require('async'),
|
||||
crypto = require('crypto'),
|
||||
pug = require('pug');
|
||||
|
||||
var smtpTransport = nodemailer.createTransport(config.mailer.options);
|
||||
|
||||
/**
|
||||
* Forgot for reset password (forgot POST)
|
||||
*/
|
||||
exports.forgot = function(req, res) {
|
||||
async.waterfall([
|
||||
// Generate random token
|
||||
function(done) {
|
||||
crypto.randomBytes(20, function(err, buffer) {
|
||||
var token = buffer.toString('hex');
|
||||
done(err, token);
|
||||
});
|
||||
},
|
||||
// Lookup user by username
|
||||
function(token, done) {
|
||||
if (req.body.username) {
|
||||
User.findOne({
|
||||
$or: [
|
||||
{'username': req.body.username.toLowerCase()},
|
||||
{'email': req.body.username}
|
||||
]
|
||||
}, '-salt -password', function(err, user) {
|
||||
if(err){
|
||||
return res.status(500).send({
|
||||
message: err.message
|
||||
});
|
||||
}
|
||||
if (!user) {
|
||||
var tempUserModel = mongoose.model(config.tempUserCollection);
|
||||
tempUserModel.findOne({
|
||||
$or: [
|
||||
{'username': req.body.username.toLowerCase()},
|
||||
{'email': req.body.username}
|
||||
]
|
||||
}).lean().exec(function(err, user) {
|
||||
if(err){
|
||||
return res.status(500).send({
|
||||
message: err.message
|
||||
});
|
||||
}
|
||||
if(!user){
|
||||
return res.status(400).send({
|
||||
message: 'No account with that username or email has been found'
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(400).send({
|
||||
message: 'The account associated with this email has not been activated yet'
|
||||
});
|
||||
});
|
||||
} else {
|
||||
user.resetPasswordToken = token;
|
||||
user.resetPasswordExpires = Date.now() + 3600000; // 1 hour
|
||||
|
||||
user.save(function(err) {
|
||||
done(err, token, user);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return res.status(400).send({
|
||||
message: 'Username field must not be blank'
|
||||
});
|
||||
}
|
||||
},
|
||||
function(token, user, done) {
|
||||
const fn = pug.compileFile(__dirname + '/../../views/templates/reset-password-email.server.view.pug');
|
||||
res.locals.url = 'http://' + req.headers.host + '/auth/reset/' + token;
|
||||
|
||||
var renderedHtml = fn(res.locals);
|
||||
done(null, renderedHtml, user);
|
||||
},
|
||||
// If valid email, send reset email using service
|
||||
function(emailHTML, user, done) {
|
||||
var mailOptions = {
|
||||
to: user.email,
|
||||
from: config.mailer.from,
|
||||
subject: 'Password Reset',
|
||||
html: emailHTML
|
||||
};
|
||||
|
||||
var userEmail = user.email;
|
||||
var emailUsername = userEmail.split('@')[0];
|
||||
var domain = userEmail.split('@')[1];
|
||||
|
||||
var obfuscatedUser = emailUsername.substring(0, 1) + emailUsername.substring(1).replace(/./g, '*');
|
||||
var domainName = domain.split('.')[0];
|
||||
var tld = domain.split('.')[1];
|
||||
|
||||
var obfuscatedDomainName = domainName.replace(/./g, '*');
|
||||
var obfuscatedEmail = obfuscatedUser + '@' + obfuscatedDomainName + '.' + tld;
|
||||
|
||||
smtpTransport.sendMail(mailOptions, function(err) {
|
||||
done(err, obfuscatedEmail);
|
||||
});
|
||||
}
|
||||
], function(err, obfuscatedEmail) {
|
||||
if (err) {
|
||||
return res.status(400).send({
|
||||
message: 'Couldn\'t send reset password email due to internal server errors. Please contact support at team@ohmyform.com.'
|
||||
});
|
||||
} else {
|
||||
return res.send({
|
||||
message: 'An email has been sent to ' + obfuscatedEmail + ' with further instructions.'
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset password GET from email token
|
||||
*/
|
||||
exports.validateResetToken = function(req, res) {
|
||||
User.findOne({
|
||||
resetPasswordToken: req.params.token,
|
||||
resetPasswordExpires: {
|
||||
$gt: Date.now()
|
||||
}
|
||||
}, function(err, user) {
|
||||
if(err){
|
||||
return res.status(500).send({
|
||||
message: err.message
|
||||
});
|
||||
}
|
||||
if (!user) {
|
||||
return res.redirect(400, '/#!/password/reset/invalid');
|
||||
}
|
||||
|
||||
res.redirect('/#!/password/reset/' + req.params.token);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset password POST from email token
|
||||
*/
|
||||
exports.reset = function(req, res, next) {
|
||||
if(req.body.newPassword.length < 4){
|
||||
return res.status(400).send({
|
||||
message: 'Password must be at least 4 characters long'
|
||||
});
|
||||
}
|
||||
|
||||
if(req.body.newPassword !== req.body.verifyPassword){
|
||||
return res.status(400).send({
|
||||
message: 'Passwords do not match'
|
||||
});
|
||||
}
|
||||
|
||||
// Init Variables
|
||||
var passwordDetails = req.body;
|
||||
async.waterfall([
|
||||
function(done) {
|
||||
User.findOne({
|
||||
resetPasswordToken: req.params.token,
|
||||
resetPasswordExpires: {
|
||||
$gt: Date.now()
|
||||
}
|
||||
}, function(err, user) {
|
||||
if (!err && user) {
|
||||
user.password = passwordDetails.newPassword;
|
||||
user.resetPasswordToken = null;
|
||||
user.resetPasswordExpires = null;
|
||||
|
||||
user.save(function(err, savedUser) {
|
||||
if (err) {
|
||||
done(err, null);
|
||||
}
|
||||
done(null, savedUser);
|
||||
});
|
||||
} else {
|
||||
done('invalid_reset_token', null);
|
||||
}
|
||||
});
|
||||
},
|
||||
function(user, done) {
|
||||
const fn = pug.compileFile(__dirname + '/../../views/templates/reset-password-confirm-email.server.view.pug');
|
||||
const renderedHtml = fn(res.locals);
|
||||
done(null, renderedHtml, user);
|
||||
},
|
||||
// If valid email, send reset email using service
|
||||
function(emailHTML, user, done) {
|
||||
var mailOptions = {
|
||||
to: user.email,
|
||||
from: config.mailer.from,
|
||||
subject: 'Your password has been changed',
|
||||
html: emailHTML
|
||||
};
|
||||
|
||||
smtpTransport.sendMail(mailOptions, function(err) {
|
||||
done(err);
|
||||
});
|
||||
}
|
||||
], function(err) {
|
||||
if (err) {
|
||||
if(err === 'invalid_reset_token'){
|
||||
return res.status(400).send({
|
||||
message: 'Password reset token is invalid or has expired.'
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(500).send({
|
||||
message: err.message || err
|
||||
});
|
||||
}
|
||||
|
||||
res.json({
|
||||
message: 'Successfully changed your password!'
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Change Password
|
||||
*/
|
||||
exports.changePassword = function(req, res) {
|
||||
// Init Variables
|
||||
var passwordDetails = req.body;
|
||||
|
||||
if (req.user) {
|
||||
if (passwordDetails.newPassword) {
|
||||
User.findById(req.user.id, function(err, user) {
|
||||
if (!err && user) {
|
||||
if (user.authenticate(passwordDetails.currentPassword)) {
|
||||
if (passwordDetails.newPassword === passwordDetails.verifyPassword) {
|
||||
user.password = passwordDetails.newPassword;
|
||||
|
||||
user.save(function(err) {
|
||||
if (err) {
|
||||
return res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
} else {
|
||||
req.login(user, function(err) {
|
||||
if (err) {
|
||||
res.status(400).send(err);
|
||||
} else {
|
||||
res.send({
|
||||
message: 'Password changed successfully'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
res.status(400).send({
|
||||
message: 'Passwords do not match'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
res.status(400).send({
|
||||
message: 'Current password is incorrect'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
res.status(400).send({
|
||||
message: 'User is not found'
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
res.status(400).send({
|
||||
message: 'Please provide a new password'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
res.status(400).send({
|
||||
message: 'User is not signed in'
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -1,52 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var _ = require('lodash'),
|
||||
errorHandler = require('../errors.server.controller.js'),
|
||||
mongoose = require('mongoose'),
|
||||
helpers = require('../helpers.server.controller');
|
||||
|
||||
/**
|
||||
* Update user details
|
||||
*/
|
||||
exports.update = function(req, res) {
|
||||
// Init Variables
|
||||
var user = req.user;
|
||||
|
||||
// To improve security we remove the roles from the req.body object
|
||||
delete req.body.roles;
|
||||
|
||||
debugger;
|
||||
|
||||
// Merge existing user
|
||||
user = _.extend(user, req.body);
|
||||
user.updated = Date.now();
|
||||
|
||||
user.save(function(err) {
|
||||
if (err) {
|
||||
return res.status(500).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
}
|
||||
req.login(user, function(loginErr) {
|
||||
if (err) {
|
||||
res.status(500).send(loginErr);
|
||||
} else {
|
||||
user = helpers.removeSensitiveModelData('private_user', user.toJSON());
|
||||
res.json(user);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Send User
|
||||
*/
|
||||
exports.getUser = function(req, res) {
|
||||
var user = helpers.removeSensitiveModelData('private_user', req.user.toJSON());
|
||||
|
||||
return res.json(user);
|
||||
};
|
||||
@ -1,99 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
var constants = module.exports = {
|
||||
|
||||
extraneousFormFieldProps: [
|
||||
'validFieldTypes',
|
||||
'disabled',
|
||||
'required',
|
||||
'isSubmission',
|
||||
'title',
|
||||
'fieldOptions',
|
||||
'ratingOptions',
|
||||
'logicJump',
|
||||
'description',
|
||||
'created',
|
||||
'lastModified',
|
||||
'deletePreserved'
|
||||
],
|
||||
|
||||
fieldTypes: [
|
||||
'textfield',
|
||||
'date',
|
||||
'email',
|
||||
'legal',
|
||||
'textarea',
|
||||
'link',
|
||||
'statement',
|
||||
'dropdown',
|
||||
'rating',
|
||||
'radio',
|
||||
'hidden',
|
||||
'yes_no',
|
||||
'number'
|
||||
],
|
||||
|
||||
ratingShapeTypes: [
|
||||
'Heart',
|
||||
'Star',
|
||||
'thumbs-up',
|
||||
'thumbs-down',
|
||||
'Circle',
|
||||
'Square',
|
||||
'Check Circle',
|
||||
'Smile Outlined',
|
||||
'Hourglass',
|
||||
'bell',
|
||||
'Paper Plane',
|
||||
'Comment',
|
||||
'Trash'
|
||||
],
|
||||
|
||||
deviceTypes: ['desktop', 'phone', 'tablet', 'other'],
|
||||
languageTypes: ['en', 'fr', 'es', 'it', 'de'],
|
||||
|
||||
langCodeToWord: {
|
||||
'en': 'English',
|
||||
'fr': 'Français',
|
||||
'es': 'Español',
|
||||
'it': 'Italiàno',
|
||||
'de': 'Deutsch'
|
||||
},
|
||||
|
||||
wordToLangCode: {
|
||||
'English': 'en',
|
||||
'Français': 'fr',
|
||||
'Español': 'es',
|
||||
'Italiàno': 'it',
|
||||
'Deutsch': 'de'
|
||||
},
|
||||
|
||||
privateFields: {
|
||||
'public_form': ['__v', 'analytics.visitors', 'analytics.views', 'analytics.conversionRate', 'analytics.fields', 'lastModified', 'created'],
|
||||
'private_form': ['__v'],
|
||||
'public_user': ['passwordHash', 'password', 'provider', 'salt', 'lastModified', 'created', 'resetPasswordToken', 'resetPasswordExpires', 'token', 'apiKey', '__v'],
|
||||
'private_user': ['passwordHash', 'password', 'provider', 'salt', 'resetPasswordToken', 'resetPasswordExpires', 'token', '__v']
|
||||
},
|
||||
|
||||
expressionStringTypes: ['field == static',
|
||||
'field != static',
|
||||
'field > static',
|
||||
'field >= static',
|
||||
'field <= static',
|
||||
'field < static',
|
||||
'field contains static',
|
||||
'field !contains static',
|
||||
'field begins static',
|
||||
'field !begins static',
|
||||
'field ends static',
|
||||
'field !ends static'],
|
||||
|
||||
userRoleTypes: ['user', 'admin', 'superuser'],
|
||||
|
||||
regex: {
|
||||
username: /^[a-zA-Z0-9\-]+$/,
|
||||
url: /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/,
|
||||
hexCode: /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,
|
||||
email: /^(([^<>()\[\]\\.,;:\s@']+(\.[^<>()\[\]\\.,;:\s@']+)*)|('.+'))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
||||
}
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user