├── client
├── static
│ └── .gitkeep
├── .eslintignore
├── config
│ ├── prod.env.js
│ ├── test.env.js
│ ├── dev.env.js
│ └── index.js
├── build
│ ├── logo.png
│ ├── vue-loader.conf.js
│ ├── webpack.test.conf.js
│ ├── build.js
│ ├── check-versions.js
│ ├── webpack.base.conf.js
│ ├── utils.js
│ ├── webpack.dev.conf.js
│ └── webpack.prod.conf.js
├── src
│ ├── assets
│ │ └── logo.png
│ ├── views
│ │ ├── Home.vue
│ │ ├── About.vue
│ │ ├── Lost.vue
│ │ ├── Login.vue
│ │ ├── VerifyEmail.vue
│ │ ├── PasswordResetConfirm.vue
│ │ ├── PasswordReset.vue
│ │ └── Register.vue
│ ├── api
│ │ ├── session.js
│ │ └── auth.js
│ ├── main.js
│ ├── store
│ │ ├── index.js
│ │ ├── types.js
│ │ ├── auth.js
│ │ ├── password.js
│ │ └── signup.js
│ ├── App.vue
│ ├── components
│ │ └── Navbar.vue
│ └── router
│ │ └── index.js
├── test
│ ├── unit
│ │ ├── .eslintrc
│ │ ├── specs
│ │ │ └── Login.spec.js
│ │ ├── index.js
│ │ └── karma.conf.js
│ └── e2e
│ │ ├── specs
│ │ └── test.js
│ │ ├── custom-assertions
│ │ └── elementCount.js
│ │ ├── nightwatch.conf.js
│ │ └── runner.js
├── .editorconfig
├── .postcssrc.js
├── .gitignore
├── index.html
├── .babelrc
├── README.md
├── .eslintrc.js
└── package.json
├── server
├── server
│ ├── __init__.py
│ ├── api
│ │ ├── __init__.py
│ │ ├── fixtures
│ │ │ ├── __init__.py
│ │ │ └── factories.py
│ │ ├── management
│ │ │ ├── __init__.py
│ │ │ └── commands
│ │ │ │ └── create_fixtures.py
│ │ ├── migrations
│ │ │ ├── __init__.py
│ │ │ └── 0001_initial.py
│ │ ├── admin.py
│ │ ├── urls.py
│ │ ├── models.py
│ │ ├── permissions.py
│ │ ├── serializers.py
│ │ └── views.py
│ ├── __pycache__
│ │ ├── __init__.cpython-310.pyc
│ │ └── settings.cpython-310.pyc
│ ├── wsgi.py
│ ├── urls.py
│ ├── auth.py
│ └── settings.py
├── manage.py
├── templates
│ ├── registration
│ │ └── password_reset_email.html
│ └── account
│ │ └── email
│ │ └── email_confirmation_message.txt
├── Pipfile
├── README.md
└── Pipfile.lock
├── README.md
└── Makefile
/client/static/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/server/server/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/server/server/api/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/server/server/api/fixtures/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/server/server/api/management/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/server/server/api/migrations/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/client/.eslintignore:
--------------------------------------------------------------------------------
1 | /build/
2 | /config/
3 | /dist/
4 | /*.js
5 | /test/unit/coverage/
6 |
--------------------------------------------------------------------------------
/client/config/prod.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | module.exports = {
3 | NODE_ENV: '"production"'
4 | }
5 |
--------------------------------------------------------------------------------
/client/build/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cupidbow20000/Cupid-Vue-Django-Project/HEAD/client/build/logo.png
--------------------------------------------------------------------------------
/client/src/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cupidbow20000/Cupid-Vue-Django-Project/HEAD/client/src/assets/logo.png
--------------------------------------------------------------------------------
/client/test/unit/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "mocha": true
4 | },
5 | "globals": {
6 | "expect": true,
7 | "sinon": true
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/server/server/__pycache__/__init__.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cupidbow20000/Cupid-Vue-Django-Project/HEAD/server/server/__pycache__/__init__.cpython-310.pyc
--------------------------------------------------------------------------------
/server/server/__pycache__/settings.cpython-310.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cupidbow20000/Cupid-Vue-Django-Project/HEAD/server/server/__pycache__/settings.cpython-310.pyc
--------------------------------------------------------------------------------
/client/config/test.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const merge = require('webpack-merge')
3 | const devEnv = require('./dev.env')
4 |
5 | module.exports = merge(devEnv, {
6 | NODE_ENV: '"testing"'
7 | })
8 |
--------------------------------------------------------------------------------
/server/server/api/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 |
3 | from .models import (
4 | User,
5 | Post,
6 | )
7 |
8 | admin.site.register(User)
9 | admin.site.register(Post)
10 |
--------------------------------------------------------------------------------
/client/config/dev.env.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const merge = require('webpack-merge')
3 | const prodEnv = require('./prod.env')
4 |
5 | module.exports = merge(prodEnv, {
6 | NODE_ENV: '"development"'
7 | })
8 |
--------------------------------------------------------------------------------
/server/server/wsgi.py:
--------------------------------------------------------------------------------
1 | import os
2 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings")
3 |
4 | from django.core.wsgi import get_wsgi_application
5 |
6 | application = get_wsgi_application()
7 |
--------------------------------------------------------------------------------
/client/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
--------------------------------------------------------------------------------
/client/src/views/Home.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Home
4 |
5 |
6 |
7 |
12 |
--------------------------------------------------------------------------------
/client/src/views/About.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
About
4 |
5 |
6 |
7 |
12 |
--------------------------------------------------------------------------------
/client/.postcssrc.js:
--------------------------------------------------------------------------------
1 | // https://github.com/michael-ciniawsky/postcss-load-config
2 |
3 | module.exports = {
4 | "plugins": {
5 | "postcss-import": {},
6 | "postcss-url": {},
7 | // to edit target browsers: use "browserslist" field in package.json
8 | "autoprefixer": {}
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/client/src/views/Lost.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Page Not Found
4 | One of us is lost.
5 | Take me home.
6 |
7 |
8 |
9 |
14 |
--------------------------------------------------------------------------------
/server/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | import os
3 | import sys
4 |
5 | if __name__ == "__main__":
6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings")
7 |
8 | from django.core.management import execute_from_command_line
9 |
10 | execute_from_command_line(sys.argv)
11 |
--------------------------------------------------------------------------------
/client/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | /dist/
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | /test/unit/coverage/
8 | /test/e2e/reports/
9 | selenium-debug.log
10 |
11 | # Editor directories and files
12 | .idea
13 | .vscode
14 | *.suo
15 | *.ntvs*
16 | *.njsproj
17 | *.sln
18 |
--------------------------------------------------------------------------------
/client/src/api/session.js:
--------------------------------------------------------------------------------
1 | import axios from 'axios';
2 |
3 | const CSRF_COOKIE_NAME = 'csrftoken';
4 | const CSRF_HEADER_NAME = 'X-CSRFToken';
5 |
6 | const session = axios.create({
7 | xsrfCookieName: CSRF_COOKIE_NAME,
8 | xsrfHeaderName: CSRF_HEADER_NAME,
9 | });
10 |
11 | export default session;
12 |
--------------------------------------------------------------------------------
/server/server/api/urls.py:
--------------------------------------------------------------------------------
1 | from rest_framework.routers import DefaultRouter
2 |
3 | from .views import (
4 | UserViewSet,
5 | PostViewSet,
6 | )
7 |
8 | router = DefaultRouter()
9 |
10 | router.register(r'users', UserViewSet)
11 | router.register(r'posts', PostViewSet)
12 |
13 | urlpatterns = router.urls
14 |
--------------------------------------------------------------------------------
/client/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | example
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/client/src/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 |
3 | import App from './App';
4 | import router from './router';
5 | import store from './store';
6 |
7 | Vue.config.productionTip = false;
8 |
9 | export default new Vue({
10 | router,
11 | store,
12 | el: '#app',
13 | template: '',
14 | components: { App },
15 | });
16 |
--------------------------------------------------------------------------------
/server/templates/registration/password_reset_email.html:
--------------------------------------------------------------------------------
1 | Hello,
2 |
3 | To reset the password for your {{ domain }} account, use this link:
4 |
5 | {{ protocol }}://{{ domain }}/#/password_reset/{{ uid }}/{{ token }}
6 |
7 | If you didn't request a password reset, ignore this email.
8 |
9 | Sincerely,
10 |
11 | The {{ domain }} team
12 |
--------------------------------------------------------------------------------
/server/Pipfile:
--------------------------------------------------------------------------------
1 | [[source]]
2 | url = "https://pypi.python.org/simple"
3 | verify_ssl = true
4 | name = "pypi"
5 |
6 | [packages]
7 | django-rest-auth = "==0.9.2"
8 | djangorestframework = ">=3.7.0"
9 | django-allauth = ">=0.24.1"
10 | six = "==1.9.0"
11 | Django = ">=1.9.0"
12 |
13 | [dev-packages]
14 | factory-boy = "*"
15 | faker = "*"
16 |
17 | [requires]
18 | python_version = "3"
19 |
--------------------------------------------------------------------------------
/client/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | ["env", {
4 | "modules": false,
5 | "targets": {
6 | "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
7 | }
8 | }],
9 | "stage-2"
10 | ],
11 | "plugins": ["transform-vue-jsx", "transform-runtime"],
12 | "env": {
13 | "test": {
14 | "presets": ["env", "stage-2"],
15 | "plugins": ["transform-vue-jsx", "istanbul"]
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/server/server/urls.py:
--------------------------------------------------------------------------------
1 | from django.conf.urls import include, url
2 | from django.contrib import admin
3 | from django.views.generic import TemplateView
4 |
5 | urlpatterns = [
6 | url(r'^api/', include('server.api.urls')),
7 | url(r'^auth/', include('rest_auth.urls')),
8 | url(r'^registration/', include('rest_auth.registration.urls')),
9 | url(r'^admin/', admin.site.urls),
10 | url(r'^$', TemplateView.as_view(template_name="index.html"), name='index'),
11 | ]
12 |
--------------------------------------------------------------------------------
/client/test/unit/specs/Login.spec.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import Router from 'vue-router';
3 |
4 | import Login from '@/views/Login';
5 |
6 | describe('Login.vue', () => {
7 | it('should render expected contents', () => {
8 | const Constructor = Vue.extend(Login);
9 | const router = new Router();
10 | const vm = new Constructor({ router }).$mount();
11 | expect(vm.$el.querySelector('#login-view h1').textContent)
12 | .to.equal('Login');
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/server/templates/account/email/email_confirmation_message.txt:
--------------------------------------------------------------------------------
1 | {% load account %}{% user_display user as username %}{% load i18n %}{% blocktrans with domain=current_site.domain %}Hello,
2 |
3 | To activate your {{ domain }} account for user {{ username }}, use this link:
4 |
5 | {% endblocktrans %}{% if request.is_secure %}https{% else %}http{% endif %}{% blocktrans with domain=current_site.domain %}://{{ domain }}/#/register/{{ key }}
6 |
7 | Sincerely,
8 |
9 | The {{ domain }} team
10 | {% endblocktrans %}
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Vue.js and django-rest-auth
2 | ========================================================================
3 | An example [Vue.js](https://github.com/vuejs/vue) project featuring an unstyled auth and registration flow using endpoints from [django-rest-auth](https://github.com/Tivix/django-rest-auth).
4 | ------------------------------------------------------------------------
5 | * [client](client)
6 | * [server](server)
7 |
8 | #### Dependencies
9 | - python 3.6
10 | - pipenv 11.10.0
11 | - node 8.9.0
12 | - yarn 1.6.0+
13 |
--------------------------------------------------------------------------------
/client/src/store/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import Vuex from 'vuex';
3 | import createLogger from 'vuex/dist/logger';
4 |
5 | import auth from './auth';
6 | import password from './password';
7 | import signup from './signup';
8 |
9 | const debug = process.env.NODE_ENV !== 'production';
10 |
11 | Vue.use(Vuex);
12 |
13 | export default new Vuex.Store({
14 | modules: {
15 | auth,
16 | password,
17 | signup,
18 | },
19 | strict: debug,
20 | plugins: debug ? [createLogger()] : [],
21 | });
22 |
--------------------------------------------------------------------------------
/server/server/auth.py:
--------------------------------------------------------------------------------
1 | from django.contrib.auth import get_user_model
2 |
3 |
4 | class AlwaysRootBackend(object):
5 | """This is a backend for short-circuiting authentication across the
6 | application. For development and demonstration purposes only.
7 | """
8 | def authenticate(self, *args, **kwargs):
9 | """Always return the 'root' user."""
10 | return get_user_model().objects.get(username='root')
11 |
12 | def get_user(self, user_id):
13 | return get_user_model().objects.get(username='root')
14 |
--------------------------------------------------------------------------------
/client/test/unit/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 |
3 | Vue.config.productionTip = false;
4 |
5 | // require all test files (files that ends with .spec.js)
6 | const testsContext = require.context('./specs', true, /\.spec$/);
7 | testsContext.keys().forEach(testsContext);
8 |
9 | // require all src files except main.js for coverage.
10 | // you can also change this to match only the subset of files that
11 | // you want coverage for.
12 | const srcContext = require.context('../../src', true, /^\.\/(?!main(\.js)?$)/);
13 | srcContext.keys().forEach(srcContext);
14 |
--------------------------------------------------------------------------------
/server/README.md:
--------------------------------------------------------------------------------
1 | # server development
2 |
3 | ``` bash
4 | # install dependencies
5 | pipenv install --dev
6 | pipenv shell
7 |
8 | # setup development database
9 | ./manage.py makemigrations api --noinput
10 | ./manage.py migrate --noinput
11 |
12 | # load data
13 | ./manage.py createsuperuser --username=root --email=root@example.com --noinput
14 | ./manage.py create_fixtures
15 |
16 | # run development server
17 | ./manage.py runserver --settings=server.settings
18 | ```
19 |
20 | **Note:** You should install [pipenv](https://pipenv.pypa.io/en/latest/) before installing any python dependencies.
21 |
--------------------------------------------------------------------------------
/client/test/e2e/specs/test.js:
--------------------------------------------------------------------------------
1 | // For authoring Nightwatch tests, see
2 | // http://nightwatchjs.org/guide#usage
3 |
4 | module.exports = {
5 | 'default e2e tests': function test(browser) {
6 | // automatically uses dev Server port from /config.index.js
7 | // default: http://localhost:8080
8 | // see nightwatch.conf.js
9 | const devServer = browser.globals.devServerURL;
10 |
11 | browser
12 | .url(devServer)
13 | .waitForElementVisible('#login-view', 10000)
14 | .assert.elementPresent('h1')
15 | .assert.containsText('h1', 'Login')
16 | .end();
17 | },
18 | };
19 |
--------------------------------------------------------------------------------
/client/README.md:
--------------------------------------------------------------------------------
1 | # client development
2 |
3 | ``` bash
4 | # install dependencies
5 | yarn install
6 |
7 | # serve with auto-reload at localhost:8080
8 | yarn run dev
9 |
10 | # build for production with minification
11 | yarn run build
12 |
13 | # build for production and view the bundle analyzer report
14 | yarn run build --report
15 |
16 | # run unit tests
17 | yarn run unit
18 |
19 | # run e2e tests
20 | yarn run e2e
21 |
22 | # run all tests
23 | yarn test
24 | ```
25 |
26 | For more details on the build setup see [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
27 |
--------------------------------------------------------------------------------
/client/build/vue-loader.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const utils = require('./utils')
3 | const config = require('../config')
4 | const isProduction = process.env.NODE_ENV === 'production'
5 | const sourceMapEnabled = isProduction
6 | ? config.build.productionSourceMap
7 | : config.dev.cssSourceMap
8 |
9 | module.exports = {
10 | loaders: utils.cssLoaders({
11 | sourceMap: sourceMapEnabled,
12 | extract: isProduction
13 | }),
14 | cssSourceMap: sourceMapEnabled,
15 | cacheBusting: config.dev.cacheBusting,
16 | transformToRequire: {
17 | video: ['src', 'poster'],
18 | source: 'src',
19 | img: 'src',
20 | image: 'xlink:href'
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/client/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
23 |
24 |
32 |
--------------------------------------------------------------------------------
/server/server/api/management/commands/create_fixtures.py:
--------------------------------------------------------------------------------
1 | from django.core.management.base import BaseCommand
2 |
3 | from server.api.fixtures.factories import (
4 | UserFactory,
5 | PostFactory,
6 | )
7 |
8 |
9 | class Command(BaseCommand):
10 |
11 | def handle(self, *args, **options):
12 | UserFactory()
13 | UserFactory()
14 | UserFactory()
15 | UserFactory()
16 | UserFactory()
17 |
18 | PostFactory()
19 | PostFactory()
20 | PostFactory()
21 | PostFactory()
22 | PostFactory()
23 | PostFactory()
24 | PostFactory()
25 | PostFactory()
26 | PostFactory()
27 | PostFactory()
28 |
--------------------------------------------------------------------------------
/server/server/api/models.py:
--------------------------------------------------------------------------------
1 | from django.conf import settings
2 | from django.contrib.auth.models import AbstractUser
3 | from django.db.models import (
4 | CASCADE,
5 | CharField,
6 | DateTimeField,
7 | ForeignKey,
8 | ManyToManyField,
9 | Model,
10 | TextField,
11 | )
12 |
13 |
14 | class User(AbstractUser):
15 |
16 | followers = ManyToManyField('self', related_name='followees', symmetrical=False)
17 |
18 |
19 | class Post(Model):
20 |
21 | author = ForeignKey(User, related_name='posts', on_delete=CASCADE)
22 |
23 | created = DateTimeField(auto_now_add=True)
24 | content = TextField(blank=True, null=True)
25 | title = CharField(max_length=255)
26 | updated = DateTimeField(auto_now=True)
27 |
--------------------------------------------------------------------------------
/client/src/components/Navbar.vue:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
13 |
14 |
41 |
--------------------------------------------------------------------------------
/client/test/e2e/custom-assertions/elementCount.js:
--------------------------------------------------------------------------------
1 | // A custom Nightwatch assertion.
2 | // The assertion name is the filename.
3 | // Example usage:
4 | //
5 | // browser.assert.elementCount(selector, count)
6 | //
7 | // For more information on custom assertions see:
8 | // http://nightwatchjs.org/guide#writing-custom-assertions
9 |
10 | exports.assertion = function (selector, count) {
11 | this.message = 'Testing if element <' + selector + '> has count: ' + count
12 | this.expected = count
13 | this.pass = function (val) {
14 | return val === this.expected
15 | }
16 | this.value = function (res) {
17 | return res.value
18 | }
19 | this.command = function (cb) {
20 | var self = this
21 | return this.api.execute(function (selector) {
22 | return document.querySelectorAll(selector).length
23 | }, [selector], function (res) {
24 | cb.call(self, res)
25 | })
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/server/server/api/permissions.py:
--------------------------------------------------------------------------------
1 | from rest_framework.permissions import SAFE_METHODS, BasePermission
2 |
3 |
4 | class SafeMethodsOnly(BasePermission):
5 |
6 | def has_permission(self, request, view):
7 | return request.method in SAFE_METHODS
8 |
9 | def has_object_permission(self, request, view, obj=None):
10 | return request.method in SAFE_METHODS
11 |
12 |
13 | class AdminOrAuthorCanEdit(BasePermission):
14 |
15 | def has_permission(self, request, view):
16 | """All users can list or view."""
17 | return request.method in SAFE_METHODS
18 |
19 | def has_object_permission(self, request, view, obj=None):
20 | """Only the author can modify existing instances."""
21 | is_safe = request.method in SAFE_METHODS
22 |
23 | try:
24 | is_author = request.user == obj.author
25 | except AttributeError:
26 | is_author = False
27 |
28 | return is_safe or is_author or request.user.is_superuser
29 |
--------------------------------------------------------------------------------
/client/build/webpack.test.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | // This is the webpack config used for unit tests.
3 |
4 | const utils = require('./utils')
5 | const webpack = require('webpack')
6 | const merge = require('webpack-merge')
7 | const baseWebpackConfig = require('./webpack.base.conf')
8 |
9 | const webpackConfig = merge(baseWebpackConfig, {
10 | // use inline sourcemap for karma-sourcemap-loader
11 | module: {
12 | rules: utils.styleLoaders()
13 | },
14 | devtool: '#inline-source-map',
15 | resolveLoader: {
16 | alias: {
17 | // necessary to to make lang="scss" work in test when using vue-loader's ?inject option
18 | // see discussion at https://github.com/vuejs/vue-loader/issues/724
19 | 'scss-loader': 'sass-loader'
20 | }
21 | },
22 | plugins: [
23 | new webpack.DefinePlugin({
24 | 'process.env': require('../config/test.env')
25 | })
26 | ]
27 | })
28 |
29 | // no need for app entry during tests
30 | delete webpackConfig.entry
31 |
32 | module.exports = webpackConfig
33 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | SHELL := /bin/bash
2 | PYTHON_BIN = $(shell cd server && pipenv --venv)/bin/python
3 |
4 | python_bin:
5 | pushd server; pipenv install --dev; popd;
6 |
7 | database: python_bin
8 | $(PYTHON_BIN) ./server/manage.py makemigrations api --noinput
9 | $(PYTHON_BIN) ./server/manage.py migrate --noinput
10 |
11 | fixtures: python_bin
12 | $(PYTHON_BIN) ./server/manage.py createsuperuser --username=root --email=root@example.com --noinput
13 | $(PYTHON_BIN) ./server/manage.py create_fixtures
14 |
15 | server-dev: python_bin
16 | $(PYTHON_BIN) ./server/manage.py runserver --settings=server.settings
17 |
18 | client/node_modules:
19 | yarn --cwd=./client install
20 |
21 | client-dist: client/node_modules
22 | yarn --cwd=./client run build
23 |
24 | clean:
25 | find . -name \*.pyc -o -name -delete
26 | find . -name \*.pyo -o -name -delete
27 | find . -name __pycache__ -o -name -delete
28 | find . -path "./server/server/api/migrations/*.py" -not -name "__init__.py" -o -name -delete
29 | rm -f server/db.sqlite3
30 |
31 | all: clean database fixtures client-dist server-dev
32 |
--------------------------------------------------------------------------------
/client/src/views/Login.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Login
4 |
8 |
11 |
12 | create account |
13 | reset password
14 |
15 |
16 |
17 |
18 |
36 |
37 |
42 |
--------------------------------------------------------------------------------
/server/server/api/serializers.py:
--------------------------------------------------------------------------------
1 | from rest_framework.serializers import (
2 | HyperlinkedIdentityField,
3 | HyperlinkedRelatedField,
4 | ModelSerializer,
5 | )
6 |
7 | from .models import (
8 | User,
9 | Post,
10 | )
11 |
12 |
13 | class UserSerializer(ModelSerializer):
14 |
15 | posts = HyperlinkedIdentityField(view_name='user-posts')
16 |
17 | class Meta:
18 | model = User
19 | fields = (
20 | 'id',
21 | 'username',
22 | 'first_name',
23 | 'last_name',
24 | 'posts',
25 | )
26 |
27 |
28 | class PostSerializer(ModelSerializer):
29 |
30 | author = HyperlinkedRelatedField(view_name='user-detail', read_only=True)
31 |
32 | def get_validation_exclusions(self, *args, **kwargs):
33 | # exclude the author field as we supply it later on in the
34 | # corresponding view based on the http request
35 | exclusions = super(PostSerializer, self).get_validation_exclusions(*args, **kwargs)
36 | return exclusions + ['author']
37 |
38 | class Meta:
39 | model = Post
40 | fields = '__all__'
41 |
--------------------------------------------------------------------------------
/client/src/views/VerifyEmail.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Verify Email
4 | loading...
5 | An error occured.
6 |
7 | Account activation successful.
8 |
9 | Click here to sign in.
10 |
11 |
12 |
13 |
14 |
15 |
44 |
--------------------------------------------------------------------------------
/client/src/api/auth.js:
--------------------------------------------------------------------------------
1 | import session from './session';
2 |
3 | export default {
4 | login(username, password) {
5 | return session.post('/auth/login/', { username, password });
6 | },
7 | logout() {
8 | return session.post('/auth/logout/', {});
9 | },
10 | createAccount(username, password1, password2, email) {
11 | return session.post('/registration/', { username, password1, password2, email });
12 | },
13 | changeAccountPassword(password1, password2) {
14 | return session.post('/auth/password/change/', { password1, password2 });
15 | },
16 | sendAccountPasswordResetEmail(email) {
17 | return session.post('/auth/password/reset/', { email });
18 | },
19 | resetAccountPassword(uid, token, new_password1, new_password2) { // eslint-disable-line camelcase
20 | return session.post('/auth/password/reset/confirm/', { uid, token, new_password1, new_password2 });
21 | },
22 | getAccountDetails() {
23 | return session.get('/auth/user/');
24 | },
25 | updateAccountDetails(data) {
26 | return session.patch('/auth/user/', data);
27 | },
28 | verifyAccountEmail(key) {
29 | return session.post('/registration/verify-email/', { key });
30 | },
31 | };
32 |
--------------------------------------------------------------------------------
/client/test/unit/karma.conf.js:
--------------------------------------------------------------------------------
1 | // This is a karma config file. For more details see
2 | // http://karma-runner.github.io/0.13/config/configuration-file.html
3 | // we are also using it with karma-webpack
4 | // https://github.com/webpack/karma-webpack
5 |
6 | var webpackConfig = require('../../build/webpack.test.conf')
7 |
8 | module.exports = function (config) {
9 | config.set({
10 | // to run in additional browsers:
11 | // 1. install corresponding karma launcher
12 | // http://karma-runner.github.io/0.13/config/browsers.html
13 | // 2. add it to the `browsers` array below.
14 | browsers: ['PhantomJS'],
15 | frameworks: ['mocha', 'sinon-chai', 'phantomjs-shim'],
16 | reporters: ['spec', 'coverage'],
17 | files: [
18 | '../../node_modules/babel-polyfill/dist/polyfill.js',
19 | './index.js'
20 | ],
21 | preprocessors: {
22 | './index.js': ['webpack', 'sourcemap']
23 | },
24 | webpack: webpackConfig,
25 | webpackMiddleware: {
26 | noInfo: true
27 | },
28 | coverageReporter: {
29 | dir: './coverage',
30 | reporters: [
31 | { type: 'lcov', subdir: '.' },
32 | { type: 'text-summary' }
33 | ]
34 | }
35 | })
36 | }
37 |
--------------------------------------------------------------------------------
/client/test/e2e/nightwatch.conf.js:
--------------------------------------------------------------------------------
1 | require('babel-register')
2 | var config = require('../../config')
3 |
4 | // http://nightwatchjs.org/gettingstarted#settings-file
5 | module.exports = {
6 | src_folders: ['test/e2e/specs'],
7 | output_folder: 'test/e2e/reports',
8 | custom_assertions_path: ['test/e2e/custom-assertions'],
9 |
10 | selenium: {
11 | start_process: true,
12 | server_path: require('selenium-server').path,
13 | host: '127.0.0.1',
14 | port: 4444,
15 | cli_args: {
16 | 'webdriver.chrome.driver': require('chromedriver').path
17 | }
18 | },
19 |
20 | test_settings: {
21 | default: {
22 | selenium_port: 4444,
23 | selenium_host: 'localhost',
24 | silent: true,
25 | globals: {
26 | devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port)
27 | }
28 | },
29 |
30 | chrome: {
31 | desiredCapabilities: {
32 | browserName: 'chrome',
33 | javascriptEnabled: true,
34 | acceptSslCerts: true
35 | }
36 | },
37 |
38 | firefox: {
39 | desiredCapabilities: {
40 | browserName: 'firefox',
41 | javascriptEnabled: true,
42 | acceptSslCerts: true
43 | }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/client/src/store/types.js:
--------------------------------------------------------------------------------
1 | export const ACTIVATION_BEGIN = 'ACTIVATION_BEGIN';
2 | export const ACTIVATION_CLEAR = 'ACTIVATION_CLEAR';
3 | export const ACTIVATION_FAILURE = 'ACTIVATION_FAILURE';
4 | export const ACTIVATION_SUCCESS = 'ACTIVATION_SUCCESS';
5 | export const LOGIN_BEGIN = 'LOGIN_BEGIN';
6 | export const LOGIN_CLEAR = 'LOGIN_CLEAR';
7 | export const LOGIN_FAILURE = 'LOGIN_FAILURE';
8 | export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
9 | export const LOGOUT = 'LOGOUT';
10 | export const PASSWORD_EMAIL_BEGIN = 'PASSWORD_EMAIL_BEGIN';
11 | export const PASSWORD_EMAIL_CLEAR = 'PASSWORD_EMAIL_CLEAR';
12 | export const PASSWORD_EMAIL_FAILURE = 'PASSWORD_EMAIL_FAILURE';
13 | export const PASSWORD_EMAIL_SUCCESS = 'PASSWORD_EMAIL_SUCCESS';
14 | export const PASSWORD_RESET_BEGIN = 'PASSWORD_RESET_BEGIN';
15 | export const PASSWORD_RESET_CLEAR = 'PASSWORD_RESET_CLEAR';
16 | export const PASSWORD_RESET_FAILURE = 'PASSWORD_RESET_FAILURE';
17 | export const PASSWORD_RESET_SUCCESS = 'PASSWORD_RESET_SUCCESS';
18 | export const REGISTRATION_BEGIN = 'REGISTRATION_BEGIN';
19 | export const REGISTRATION_CLEAR = 'REGISTRATION_CLEAR';
20 | export const REGISTRATION_FAILURE = 'REGISTRATION_FAILURE';
21 | export const REGISTRATION_SUCCESS = 'REGISTRATION_SUCCESS';
22 | export const SET_TOKEN = 'SET_TOKEN';
23 | export const REMOVE_TOKEN = 'REMOVE_TOKEN';
24 |
--------------------------------------------------------------------------------
/server/server/api/fixtures/factories.py:
--------------------------------------------------------------------------------
1 | import datetime
2 | from random import randint
3 |
4 | from django.conf import settings
5 | from django.contrib.auth import get_user_model
6 | from factory import (
7 | LazyAttribute,
8 | LazyFunction,
9 | Sequence,
10 | SubFactory,
11 | )
12 | from factory.django import DjangoModelFactory
13 | from faker import Faker
14 |
15 | from server.api.models import (
16 | Post,
17 | )
18 |
19 |
20 | delta = datetime.timedelta
21 | now = datetime.datetime.now
22 |
23 | fake = Faker()
24 |
25 |
26 | class UserFactory(DjangoModelFactory):
27 |
28 | class Meta:
29 | model = get_user_model()
30 |
31 | email = LazyAttribute(lambda o: '{username}@123.com'.format(username=o.username))
32 | first_name = LazyFunction(fake.first_name)
33 | last_name = LazyFunction(fake.last_name)
34 | username = Sequence(lambda n: '{}{}'.format(fake.user_name(), n))
35 |
36 |
37 | class PostFactory(DjangoModelFactory):
38 |
39 | class Meta:
40 | model = Post
41 |
42 | author = SubFactory(UserFactory)
43 |
44 | title = LazyFunction(lambda: fake.text(randint(5, 20)))
45 | content = LazyFunction(lambda: fake.text(randint(20, 500)))
46 | created = LazyFunction(lambda: now() - delta(days=365))
47 | updated = LazyAttribute(lambda o: o.created + delta(days=randint(0, 365)))
48 |
--------------------------------------------------------------------------------
/client/build/build.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | require('./check-versions')()
3 |
4 | process.env.NODE_ENV = 'production'
5 |
6 | const ora = require('ora')
7 | const rm = require('rimraf')
8 | const path = require('path')
9 | const chalk = require('chalk')
10 | const webpack = require('webpack')
11 | const config = require('../config')
12 | const webpackConfig = require('./webpack.prod.conf')
13 |
14 | const spinner = ora('building for production...')
15 | spinner.start()
16 |
17 | rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18 | if (err) throw err
19 | webpack(webpackConfig, (err, stats) => {
20 | spinner.stop()
21 | if (err) throw err
22 | process.stdout.write(stats.toString({
23 | colors: true,
24 | modules: false,
25 | children: false, // if you are using ts-loader, setting this to true will make TypeScript errors show up during build
26 | chunks: false,
27 | chunkModules: false
28 | }) + '\n\n')
29 |
30 | if (stats.hasErrors()) {
31 | console.log(chalk.red(' Build failed with errors.\n'))
32 | process.exit(1)
33 | }
34 |
35 | console.log(chalk.cyan(' Build complete.\n'))
36 | console.log(chalk.yellow(
37 | ' Tip: built files are meant to be served over an HTTP server.\n' +
38 | ' Opening index.html over file:// won\'t work.\n'
39 | ))
40 | })
41 | })
42 |
--------------------------------------------------------------------------------
/server/server/api/views.py:
--------------------------------------------------------------------------------
1 | from rest_framework.decorators import detail_route
2 | from rest_framework.permissions import IsAuthenticated
3 | from rest_framework.viewsets import ModelViewSet
4 | from rest_framework.response import Response
5 |
6 | from .permissions import (
7 | AdminOrAuthorCanEdit,
8 | )
9 | from .models import (
10 | User,
11 | Post,
12 | )
13 | from .serializers import (
14 | UserSerializer,
15 | PostSerializer,
16 | )
17 |
18 | class UserViewSet(ModelViewSet):
19 |
20 | queryset = User.objects.all()
21 | serializer_class = UserSerializer
22 |
23 | permission_classes = (
24 | IsAuthenticated,
25 | )
26 |
27 | @detail_route(methods=['get'])
28 | def posts(self, request, pk=None):
29 | queryset = Post.objects.filter(author__pk=pk).order_by('-created')
30 |
31 | context = {'request': request}
32 |
33 | serializer = PostSerializer(queryset, context=context, many=True)
34 |
35 | return Response(serializer.data)
36 |
37 |
38 | class PostViewSet(ModelViewSet):
39 |
40 | queryset = Post.objects.order_by('-created')
41 | serializer_class = PostSerializer
42 |
43 | permission_classes = (
44 | IsAuthenticated,
45 | AdminOrAuthorCanEdit,
46 | )
47 |
48 | def perform_create(self, serializer):
49 | serializer.save(author=self.request.user)
50 | return super(PostViewSet, self).perform_create(serializer)
51 |
--------------------------------------------------------------------------------
/client/build/check-versions.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const chalk = require('chalk')
3 | const semver = require('semver')
4 | const packageConfig = require('../package.json')
5 | const shell = require('shelljs')
6 |
7 | function exec (cmd) {
8 | return require('child_process').execSync(cmd).toString().trim()
9 | }
10 |
11 | const versionRequirements = [
12 | {
13 | name: 'node',
14 | currentVersion: semver.clean(process.version),
15 | versionRequirement: packageConfig.engines.node
16 | }
17 | ]
18 |
19 | if (shell.which('npm')) {
20 | versionRequirements.push({
21 | name: 'npm',
22 | currentVersion: exec('npm --version'),
23 | versionRequirement: packageConfig.engines.npm
24 | })
25 | }
26 |
27 | module.exports = function () {
28 | const warnings = []
29 |
30 | for (let i = 0; i < versionRequirements.length; i++) {
31 | const mod = versionRequirements[i]
32 |
33 | if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
34 | warnings.push(mod.name + ': ' +
35 | chalk.red(mod.currentVersion) + ' should be ' +
36 | chalk.green(mod.versionRequirement)
37 | )
38 | }
39 | }
40 |
41 | if (warnings.length) {
42 | console.log('')
43 | console.log(chalk.yellow('To use this template, you must update following to modules:'))
44 | console.log()
45 |
46 | for (let i = 0; i < warnings.length; i++) {
47 | const warning = warnings[i]
48 | console.log(' ' + warning)
49 | }
50 |
51 | console.log()
52 | process.exit(1)
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/client/src/views/PasswordResetConfirm.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Reset Password Confirm
4 |
5 | loading...
6 |
7 |
8 |
13 |
16 |
17 | A error occured while processing your request.
18 |
19 |
20 |
21 | Your password has been reset.
22 | return to login page
23 |
24 |
25 |
26 |
27 |
52 |
53 |
58 |
--------------------------------------------------------------------------------
/client/src/views/PasswordReset.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Reset Password
4 |
5 | loading...
6 |
7 |
8 |
11 |
14 |
15 | A error occured while processing your request.
16 |
17 |
18 |
19 |
20 | Check your inbox for a link to reset your password. If an email doesn't appear within a few
21 | minutes, check your spam folder.
22 |
23 |
24 | return to login page
25 |
26 |
27 |
28 |
29 |
30 |
52 |
53 |
63 |
--------------------------------------------------------------------------------
/client/.eslintrc.js:
--------------------------------------------------------------------------------
1 | // https://eslint.org/docs/user-guide/configuring
2 |
3 | module.exports = {
4 | root: true,
5 | parserOptions: {
6 | parser: 'babel-eslint'
7 | },
8 | env: {
9 | browser: true,
10 | },
11 | // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
12 | // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
13 | extends: ['plugin:vue/essential', 'airbnb-base'],
14 | // required to lint *.vue files
15 | plugins: [
16 | 'vue'
17 | ],
18 | // check if imports actually resolve
19 | settings: {
20 | 'import/resolver': {
21 | webpack: {
22 | config: 'build/webpack.base.conf.js'
23 | }
24 | }
25 | },
26 | // add your custom rules here
27 | rules: {
28 | // don't require .vue extension when importing
29 | 'import/extensions': ['error', 'always', {
30 | js: 'never',
31 | vue: 'never'
32 | }],
33 | // disallow reassignment of function parameters
34 | // disallow parameter object manipulation except for specific exclusions
35 | 'no-param-reassign': ['error', {
36 | props: true,
37 | ignorePropertyModificationsFor: [
38 | 'state', // for vuex state
39 | 'acc', // for reduce accumulators
40 | 'e' // for e.returnvalue
41 | ]
42 | }],
43 | // allow optionalDependencies
44 | 'import/no-extraneous-dependencies': ['error', {
45 | optionalDependencies: ['test/unit/index.js']
46 | }],
47 | // allow debugger during development
48 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/client/test/e2e/runner.js:
--------------------------------------------------------------------------------
1 | // 1. start the dev server using production config
2 | process.env.NODE_ENV = 'testing'
3 |
4 | const webpack = require('webpack')
5 | const DevServer = require('webpack-dev-server')
6 |
7 | const webpackConfig = require('../../build/webpack.prod.conf')
8 | const devConfigPromise = require('../../build/webpack.dev.conf')
9 |
10 | let server
11 |
12 | devConfigPromise.then(devConfig => {
13 | const devServerOptions = devConfig.devServer
14 | const compiler = webpack(webpackConfig)
15 | server = new DevServer(compiler, devServerOptions)
16 | const port = devServerOptions.port
17 | const host = devServerOptions.host
18 | return server.listen(port, host)
19 | })
20 | .then(() => {
21 | // 2. run the nightwatch test suite against it
22 | // to run in additional browsers:
23 | // 1. add an entry in test/e2e/nightwatch.conf.json under "test_settings"
24 | // 2. add it to the --env flag below
25 | // or override the environment flag, for example: `npm run e2e -- --env chrome,firefox`
26 | // For more information on Nightwatch's config file, see
27 | // http://nightwatchjs.org/guide#settings-file
28 | let opts = process.argv.slice(2)
29 | if (opts.indexOf('--config') === -1) {
30 | opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js'])
31 | }
32 | if (opts.indexOf('--env') === -1) {
33 | opts = opts.concat(['--env', 'chrome'])
34 | }
35 |
36 | const spawn = require('cross-spawn')
37 | const runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' })
38 |
39 | runner.on('exit', function (code) {
40 | server.close()
41 | process.exit(code)
42 | })
43 |
44 | runner.on('error', function (err) {
45 | server.close()
46 | throw err
47 | })
48 | })
49 |
--------------------------------------------------------------------------------
/client/src/store/auth.js:
--------------------------------------------------------------------------------
1 | import auth from '../api/auth';
2 | import session from '../api/session';
3 | import {
4 | LOGIN_BEGIN,
5 | LOGIN_FAILURE,
6 | LOGIN_SUCCESS,
7 | LOGOUT,
8 | REMOVE_TOKEN,
9 | SET_TOKEN,
10 | } from './types';
11 |
12 | const TOKEN_STORAGE_KEY = 'TOKEN_STORAGE_KEY';
13 | const isProduction = process.env.NODE_ENV === 'production';
14 |
15 | const initialState = {
16 | authenticating: false,
17 | error: false,
18 | token: null,
19 | };
20 |
21 | const getters = {
22 | isAuthenticated: state => !!state.token,
23 | };
24 |
25 | const actions = {
26 | login({ commit }, { username, password }) {
27 | commit(LOGIN_BEGIN);
28 | return auth.login(username, password)
29 | .then(({ data }) => commit(SET_TOKEN, data.key))
30 | .then(() => commit(LOGIN_SUCCESS))
31 | .catch(() => commit(LOGIN_FAILURE));
32 | },
33 | logout({ commit }) {
34 | return auth.logout()
35 | .then(() => commit(LOGOUT))
36 | .finally(() => commit(REMOVE_TOKEN));
37 | },
38 | initialize({ commit }) {
39 | const token = localStorage.getItem(TOKEN_STORAGE_KEY);
40 |
41 | if (isProduction && token) {
42 | commit(REMOVE_TOKEN);
43 | }
44 |
45 | if (!isProduction && token) {
46 | commit(SET_TOKEN, token);
47 | }
48 | },
49 | };
50 |
51 | const mutations = {
52 | [LOGIN_BEGIN](state) {
53 | state.authenticating = true;
54 | state.error = false;
55 | },
56 | [LOGIN_FAILURE](state) {
57 | state.authenticating = false;
58 | state.error = true;
59 | },
60 | [LOGIN_SUCCESS](state) {
61 | state.authenticating = false;
62 | state.error = false;
63 | },
64 | [LOGOUT](state) {
65 | state.authenticating = false;
66 | state.error = false;
67 | },
68 | [SET_TOKEN](state, token) {
69 | if (!isProduction) localStorage.setItem(TOKEN_STORAGE_KEY, token);
70 | session.defaults.headers.Authorization = `Token ${token}`;
71 | state.token = token;
72 | },
73 | [REMOVE_TOKEN](state) {
74 | localStorage.removeItem(TOKEN_STORAGE_KEY);
75 | delete session.defaults.headers.Authorization;
76 | state.token = null;
77 | },
78 | };
79 |
80 | export default {
81 | namespaced: true,
82 | state: initialState,
83 | getters,
84 | actions,
85 | mutations,
86 | };
87 |
--------------------------------------------------------------------------------
/client/src/router/index.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import Router from 'vue-router';
3 |
4 | import About from '../views/About';
5 | import Home from '../views/Home';
6 | import Login from '../views/Login';
7 | import Lost from '../views/Lost';
8 | import PasswordReset from '../views/PasswordReset';
9 | import PasswordResetConfirm from '../views/PasswordResetConfirm';
10 | import Register from '../views/Register';
11 | import VerifyEmail from '../views/VerifyEmail';
12 |
13 | import store from '../store';
14 |
15 | const requireAuthenticated = (to, from, next) => {
16 | store.dispatch('auth/initialize')
17 | .then(() => {
18 | if (!store.getters['auth/isAuthenticated']) {
19 | next('/login');
20 | } else {
21 | next();
22 | }
23 | });
24 | };
25 |
26 | const requireUnauthenticated = (to, from, next) => {
27 | store.dispatch('auth/initialize')
28 | .then(() => {
29 | if (store.getters['auth/isAuthenticated']) {
30 | next('/home');
31 | } else {
32 | next();
33 | }
34 | });
35 | };
36 |
37 | const redirectLogout = (to, from, next) => {
38 | store.dispatch('auth/logout')
39 | .then(() => next('/login'));
40 | };
41 |
42 | Vue.use(Router);
43 |
44 | export default new Router({
45 | saveScrollPosition: true,
46 | routes: [
47 | {
48 | path: '/',
49 | redirect: '/home',
50 | },
51 | {
52 | path: '/about',
53 | component: About,
54 | beforeEnter: requireAuthenticated,
55 | },
56 | {
57 | path: '/home',
58 | component: Home,
59 | beforeEnter: requireAuthenticated,
60 | },
61 | {
62 | path: '/password_reset',
63 | component: PasswordReset,
64 | },
65 | {
66 | path: '/password_reset/:uid/:token',
67 | component: PasswordResetConfirm,
68 | },
69 | {
70 | path: '/register',
71 | component: Register,
72 | },
73 | {
74 | path: '/register/:key',
75 | component: VerifyEmail,
76 | },
77 | {
78 | path: '/login',
79 | component: Login,
80 | beforeEnter: requireUnauthenticated,
81 | },
82 | {
83 | path: '/logout',
84 | beforeEnter: redirectLogout,
85 | },
86 | {
87 | path: '*',
88 | component: Lost,
89 | },
90 | ],
91 | });
92 |
--------------------------------------------------------------------------------
/client/src/views/Register.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Create Account
4 |
5 | loading...
6 |
7 |
8 |
15 |
18 |
19 | An error occured while processing your request.
20 |
21 |
22 | Already have an account?
23 | login |
24 | reset password
25 |
26 |
27 |
28 |
29 | Registration complete. You should receive an email shortly with instructions on how to
30 | activate your account.
31 |
32 |
33 | return to login page
34 |
35 |
36 |
37 |
38 |
39 |
68 |
69 |
79 |
--------------------------------------------------------------------------------
/client/src/store/password.js:
--------------------------------------------------------------------------------
1 | import auth from '../api/auth';
2 |
3 | import {
4 | PASSWORD_RESET_BEGIN,
5 | PASSWORD_RESET_CLEAR,
6 | PASSWORD_RESET_FAILURE,
7 | PASSWORD_RESET_SUCCESS,
8 | PASSWORD_EMAIL_BEGIN,
9 | PASSWORD_EMAIL_CLEAR,
10 | PASSWORD_EMAIL_FAILURE,
11 | PASSWORD_EMAIL_SUCCESS,
12 | } from './types';
13 |
14 | export default {
15 | namespaced: true,
16 | state: {
17 | emailCompleted: false,
18 | emailError: false,
19 | emailLoading: false,
20 | resetCompleted: false,
21 | resetError: false,
22 | resetLoading: false,
23 | },
24 | actions: {
25 | resetPassword({ commit }, { uid, token, password1, password2 }) {
26 | commit(PASSWORD_RESET_BEGIN);
27 | return auth.resetAccountPassword(uid, token, password1, password2)
28 | .then(() => commit(PASSWORD_RESET_SUCCESS))
29 | .catch(() => commit(PASSWORD_RESET_FAILURE));
30 | },
31 | sendPasswordResetEmail({ commit }, { email }) {
32 | commit(PASSWORD_EMAIL_BEGIN);
33 | return auth.sendAccountPasswordResetEmail(email)
34 | .then(() => commit(PASSWORD_EMAIL_SUCCESS))
35 | .catch(() => commit(PASSWORD_EMAIL_FAILURE));
36 | },
37 | clearResetStatus({ commit }) {
38 | commit(PASSWORD_RESET_CLEAR);
39 | },
40 | clearEmailStatus({ commit }) {
41 | commit(PASSWORD_EMAIL_CLEAR);
42 | },
43 | },
44 | mutations: {
45 | [PASSWORD_RESET_BEGIN](state) {
46 | state.resetLoading = true;
47 | },
48 | [PASSWORD_RESET_CLEAR](state) {
49 | state.resetCompleted = false;
50 | state.resetError = false;
51 | state.resetLoading = false;
52 | },
53 | [PASSWORD_RESET_FAILURE](state) {
54 | state.resetError = true;
55 | state.resetLoading = false;
56 | },
57 | [PASSWORD_RESET_SUCCESS](state) {
58 | state.resetCompleted = true;
59 | state.resetError = false;
60 | state.resetLoading = false;
61 | },
62 | [PASSWORD_EMAIL_BEGIN](state) {
63 | state.emailLoading = true;
64 | },
65 | [PASSWORD_EMAIL_CLEAR](state) {
66 | state.emailCompleted = false;
67 | state.emailError = false;
68 | state.emailLoading = false;
69 | },
70 | [PASSWORD_EMAIL_FAILURE](state) {
71 | state.emailError = true;
72 | state.emailLoading = false;
73 | },
74 | [PASSWORD_EMAIL_SUCCESS](state) {
75 | state.emailCompleted = true;
76 | state.emailError = false;
77 | state.emailLoading = false;
78 | },
79 | },
80 | };
81 |
--------------------------------------------------------------------------------
/client/src/store/signup.js:
--------------------------------------------------------------------------------
1 | import auth from '../api/auth';
2 |
3 | import {
4 | ACTIVATION_BEGIN,
5 | ACTIVATION_CLEAR,
6 | ACTIVATION_FAILURE,
7 | ACTIVATION_SUCCESS,
8 | REGISTRATION_BEGIN,
9 | REGISTRATION_CLEAR,
10 | REGISTRATION_FAILURE,
11 | REGISTRATION_SUCCESS,
12 | } from './types';
13 |
14 | export default {
15 | namespaced: true,
16 | state: {
17 | activationCompleted: false,
18 | activationError: false,
19 | activationLoading: false,
20 | registrationCompleted: false,
21 | registrationError: false,
22 | registrationLoading: false,
23 | },
24 | actions: {
25 | createAccount({ commit }, { username, password1, password2, email }) {
26 | commit(REGISTRATION_BEGIN);
27 | return auth.createAccount(username, password1, password2, email)
28 | .then(() => commit(REGISTRATION_SUCCESS))
29 | .catch(() => commit(REGISTRATION_FAILURE));
30 | },
31 | activateAccount({ commit }, { key }) {
32 | commit(ACTIVATION_BEGIN);
33 | return auth.verifyAccountEmail(key)
34 | .then(() => commit(ACTIVATION_SUCCESS))
35 | .catch(() => commit(ACTIVATION_FAILURE));
36 | },
37 | clearRegistrationStatus({ commit }) {
38 | commit(REGISTRATION_CLEAR);
39 | },
40 | clearActivationStatus({ commit }) {
41 | commit(ACTIVATION_CLEAR);
42 | },
43 | },
44 | mutations: {
45 | [ACTIVATION_BEGIN](state) {
46 | state.activationLoading = true;
47 | },
48 | [ACTIVATION_CLEAR](state) {
49 | state.activationCompleted = false;
50 | state.activationError = false;
51 | state.activationLoading = false;
52 | },
53 | [ACTIVATION_FAILURE](state) {
54 | state.activationError = true;
55 | state.activationLoading = false;
56 | },
57 | [ACTIVATION_SUCCESS](state) {
58 | state.activationCompleted = true;
59 | state.activationError = false;
60 | state.activationLoading = false;
61 | },
62 | [REGISTRATION_BEGIN](state) {
63 | state.registrationLoading = true;
64 | },
65 | [REGISTRATION_CLEAR](state) {
66 | state.registrationCompleted = false;
67 | state.registrationError = false;
68 | state.registrationLoading = false;
69 | },
70 | [REGISTRATION_FAILURE](state) {
71 | state.registrationError = true;
72 | state.registrationLoading = false;
73 | },
74 | [REGISTRATION_SUCCESS](state) {
75 | state.registrationCompleted = true;
76 | state.registrationError = false;
77 | state.registrationLoading = false;
78 | },
79 | },
80 | };
81 |
--------------------------------------------------------------------------------
/client/build/webpack.base.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const path = require('path')
3 | const utils = require('./utils')
4 | const config = require('../config')
5 | const vueLoaderConfig = require('./vue-loader.conf')
6 |
7 | function resolve (dir) {
8 | return path.join(__dirname, '..', dir)
9 | }
10 |
11 | const createLintingRule = () => ({
12 | test: /\.(js|vue)$/,
13 | loader: 'eslint-loader',
14 | enforce: 'pre',
15 | include: [resolve('src'), resolve('test')],
16 | options: {
17 | formatter: require('eslint-friendly-formatter'),
18 | emitWarning: !config.dev.showEslintErrorsInOverlay
19 | }
20 | })
21 |
22 | module.exports = {
23 | context: path.resolve(__dirname, '../'),
24 | entry: {
25 | app: './src/main.js'
26 | },
27 | output: {
28 | path: config.build.assetsRoot,
29 | filename: '[name].js',
30 | publicPath: process.env.NODE_ENV === 'production'
31 | ? config.build.assetsPublicPath
32 | : config.dev.assetsPublicPath
33 | },
34 | resolve: {
35 | extensions: ['.js', '.vue', '.json'],
36 | alias: {
37 | 'vue$': 'vue/dist/vue.esm.js',
38 | '@': resolve('src'),
39 | }
40 | },
41 | module: {
42 | rules: [
43 | ...(config.dev.useEslint ? [createLintingRule()] : []),
44 | {
45 | test: /\.vue$/,
46 | loader: 'vue-loader',
47 | options: vueLoaderConfig
48 | },
49 | {
50 | test: /\.js$/,
51 | loader: 'babel-loader',
52 | include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
53 | },
54 | {
55 | test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
56 | loader: 'url-loader',
57 | options: {
58 | limit: 10000,
59 | name: utils.assetsPath('img/[name].[hash:7].[ext]')
60 | }
61 | },
62 | {
63 | test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
64 | loader: 'url-loader',
65 | options: {
66 | limit: 10000,
67 | name: utils.assetsPath('media/[name].[hash:7].[ext]')
68 | }
69 | },
70 | {
71 | test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
72 | loader: 'url-loader',
73 | options: {
74 | limit: 10000,
75 | name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
76 | }
77 | }
78 | ]
79 | },
80 | node: {
81 | // prevent webpack from injecting useless setImmediate polyfill because Vue
82 | // source contains it (although only uses it if it's native).
83 | setImmediate: false,
84 | // prevent webpack from injecting mocks to Node native modules
85 | // that does not make sense for the client
86 | dgram: 'empty',
87 | fs: 'empty',
88 | net: 'empty',
89 | tls: 'empty',
90 | child_process: 'empty'
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/client/config/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | // Template version: 1.3.1
3 | // see http://vuejs-templates.github.io/webpack for documentation.
4 |
5 | const path = require('path')
6 |
7 | module.exports = {
8 | dev: {
9 | // Paths
10 | assetsSubDirectory: 'static',
11 | assetsPublicPath: '/',
12 | proxyTable: {
13 | '/api': {
14 | target: 'http://localhost:8000',
15 | changeOrigin: true
16 | },
17 | '/auth': {
18 | target: 'http://localhost:8000',
19 | //changeOrigin: true
20 | }
21 | },
22 | // Various Dev Server settings
23 | host: 'localhost', // can be overwritten by process.env.HOST
24 | port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
25 | autoOpenBrowser: false,
26 | errorOverlay: true,
27 | notifyOnErrors: true,
28 | poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
29 |
30 | // Use Eslint Loader?
31 | // If true, your code will be linted during bundling and
32 | // linting errors and warnings will be shown in the console.
33 | useEslint: true,
34 | // If true, eslint errors and warnings will also be shown in the error overlay
35 | // in the browser.
36 | showEslintErrorsInOverlay: false,
37 |
38 | /**
39 | * Source Maps
40 | */
41 |
42 | // https://webpack.js.org/configuration/devtool/#development
43 | devtool: 'eval-source-map',
44 |
45 | // If you have problems debugging vue-files in devtools,
46 | // set this to false - it *may* help
47 | // https://vue-loader.vuejs.org/en/options.html#cachebusting
48 | cacheBusting: true,
49 | cssSourceMap: true,
50 | },
51 |
52 | build: {
53 | // Template for index.html
54 | index: path.resolve(__dirname, '../dist/index.html'),
55 |
56 | // Paths
57 | assetsRoot: path.resolve(__dirname, '../dist'),
58 | assetsSubDirectory: 'static',
59 | assetsPublicPath: '/',
60 |
61 | /**
62 | * Source Maps
63 | */
64 |
65 | productionSourceMap: true,
66 | // https://webpack.js.org/configuration/devtool/#production
67 | devtool: '#source-map',
68 |
69 | // Gzip off by default as many popular static hosts such as
70 | // Surge or Netlify already gzip all static assets for you.
71 | // Before setting to `true`, make sure to:
72 | // npm install --save-dev compression-webpack-plugin
73 | productionGzip: false,
74 | productionGzipExtensions: ['js', 'css'],
75 |
76 | // Run the build command with an extra argument to
77 | // View the bundle analyzer report after build finishes:
78 | // `npm run build --report`
79 | // Set to `true` or `false` to always turn it on or off
80 | bundleAnalyzerReport: process.env.npm_config_report
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/client/build/utils.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const path = require('path')
3 | const config = require('../config')
4 | const ExtractTextPlugin = require('extract-text-webpack-plugin')
5 | const packageConfig = require('../package.json')
6 |
7 | exports.assetsPath = function (_path) {
8 | const assetsSubDirectory = process.env.NODE_ENV === 'production'
9 | ? config.build.assetsSubDirectory
10 | : config.dev.assetsSubDirectory
11 |
12 | return path.posix.join(assetsSubDirectory, _path)
13 | }
14 |
15 | exports.cssLoaders = function (options) {
16 | options = options || {}
17 |
18 | const cssLoader = {
19 | loader: 'css-loader',
20 | options: {
21 | sourceMap: options.sourceMap
22 | }
23 | }
24 |
25 | const postcssLoader = {
26 | loader: 'postcss-loader',
27 | options: {
28 | sourceMap: options.sourceMap
29 | }
30 | }
31 |
32 | // generate loader string to be used with extract text plugin
33 | function generateLoaders (loader, loaderOptions) {
34 | const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader]
35 |
36 | if (loader) {
37 | loaders.push({
38 | loader: loader + '-loader',
39 | options: Object.assign({}, loaderOptions, {
40 | sourceMap: options.sourceMap
41 | })
42 | })
43 | }
44 |
45 | // Extract CSS when that option is specified
46 | // (which is the case during production build)
47 | if (options.extract) {
48 | return ExtractTextPlugin.extract({
49 | use: loaders,
50 | fallback: 'vue-style-loader'
51 | })
52 | } else {
53 | return ['vue-style-loader'].concat(loaders)
54 | }
55 | }
56 |
57 | // https://vue-loader.vuejs.org/en/configurations/extract-css.html
58 | return {
59 | css: generateLoaders(),
60 | postcss: generateLoaders(),
61 | less: generateLoaders('less'),
62 | sass: generateLoaders('sass', { indentedSyntax: true }),
63 | scss: generateLoaders('sass'),
64 | stylus: generateLoaders('stylus'),
65 | styl: generateLoaders('stylus')
66 | }
67 | }
68 |
69 | // Generate loaders for standalone style files (outside of .vue)
70 | exports.styleLoaders = function (options) {
71 | const output = []
72 | const loaders = exports.cssLoaders(options)
73 |
74 | for (const extension in loaders) {
75 | const loader = loaders[extension]
76 | output.push({
77 | test: new RegExp('\\.' + extension + '$'),
78 | use: loader
79 | })
80 | }
81 |
82 | return output
83 | }
84 |
85 | exports.createNotifierCallback = () => {
86 | const notifier = require('node-notifier')
87 |
88 | return (severity, errors) => {
89 | if (severity !== 'error') return
90 |
91 | const error = errors[0]
92 | const filename = error.file && error.file.split('!').pop()
93 |
94 | notifier.notify({
95 | title: packageConfig.name,
96 | message: severity + ': ' + error.name,
97 | subtitle: filename || '',
98 | icon: path.join(__dirname, 'logo.png')
99 | })
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/client/build/webpack.dev.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const utils = require('./utils')
3 | const webpack = require('webpack')
4 | const config = require('../config')
5 | const merge = require('webpack-merge')
6 | const path = require('path')
7 | const baseWebpackConfig = require('./webpack.base.conf')
8 | const CopyWebpackPlugin = require('copy-webpack-plugin')
9 | const HtmlWebpackPlugin = require('html-webpack-plugin')
10 | const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
11 | const portfinder = require('portfinder')
12 |
13 | const HOST = process.env.HOST
14 | const PORT = process.env.PORT && Number(process.env.PORT)
15 |
16 | const devWebpackConfig = merge(baseWebpackConfig, {
17 | module: {
18 | rules: utils.styleLoaders({
19 | sourceMap: config.dev.cssSourceMap,
20 | usePostCSS: true
21 | })
22 | },
23 | // cheap-module-eval-source-map is faster for development
24 | devtool: config.dev.devtool,
25 |
26 | // these devServer options should be customized in /config/index.js
27 | devServer: {
28 | clientLogLevel: 'warning',
29 | historyApiFallback: {
30 | rewrites: [
31 | { from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') },
32 | ],
33 | },
34 | hot: true,
35 | contentBase: false, // since we use CopyWebpackPlugin.
36 | compress: true,
37 | host: HOST || config.dev.host,
38 | port: PORT || config.dev.port,
39 | open: config.dev.autoOpenBrowser,
40 | overlay: config.dev.errorOverlay
41 | ? { warnings: false, errors: true }
42 | : false,
43 | publicPath: config.dev.assetsPublicPath,
44 | proxy: config.dev.proxyTable,
45 | quiet: true, // necessary for FriendlyErrorsPlugin
46 | watchOptions: {
47 | poll: config.dev.poll,
48 | }
49 | },
50 | plugins: [
51 | new webpack.DefinePlugin({
52 | 'process.env': require('../config/dev.env')
53 | }),
54 | new webpack.HotModuleReplacementPlugin(),
55 | new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
56 | new webpack.NoEmitOnErrorsPlugin(),
57 | // https://github.com/ampedandwired/html-webpack-plugin
58 | new HtmlWebpackPlugin({
59 | filename: 'index.html',
60 | template: 'index.html',
61 | inject: true
62 | }),
63 | // copy custom static assets
64 | new CopyWebpackPlugin([
65 | {
66 | from: path.resolve(__dirname, '../static'),
67 | to: config.dev.assetsSubDirectory,
68 | ignore: ['.*']
69 | }
70 | ])
71 | ]
72 | })
73 |
74 | module.exports = new Promise((resolve, reject) => {
75 | portfinder.basePort = process.env.PORT || config.dev.port
76 | portfinder.getPort((err, port) => {
77 | if (err) {
78 | reject(err)
79 | } else {
80 | // publish the new Port, necessary for e2e tests
81 | process.env.PORT = port
82 | // add port to devServer config
83 | devWebpackConfig.devServer.port = port
84 |
85 | // Add FriendlyErrorsPlugin
86 | devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
87 | compilationSuccessInfo: {
88 | messages: [`Development Server: http://${devWebpackConfig.devServer.host}:${port}`],
89 | },
90 | onErrors: config.dev.notifyOnErrors
91 | ? utils.createNotifierCallback()
92 | : undefined
93 | }))
94 |
95 | resolve(devWebpackConfig)
96 | }
97 | })
98 | })
99 |
--------------------------------------------------------------------------------
/client/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-django-rest-auth",
3 | "version": "1.0.0",
4 | "description": "vue-django-reset-auth-client",
5 | "author": "Jake McDermott",
6 | "private": true,
7 | "scripts": {
8 | "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
9 | "start": "npm run dev",
10 | "unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run",
11 | "e2e": "node test/e2e/runner.js",
12 | "test": "npm run unit && npm run e2e",
13 | "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs",
14 | "build": "node build/build.js"
15 | },
16 | "dependencies": {
17 | "axios": "^0.19.0",
18 | "vue": "^2.5.2",
19 | "vue-router": "^3.0.1",
20 | "vuex": "^3.0.1"
21 | },
22 | "devDependencies": {
23 | "autoprefixer": "^7.1.2",
24 | "babel-core": "^6.22.1",
25 | "babel-eslint": "^8.2.1",
26 | "babel-helper-vue-jsx-merge-props": "^2.0.3",
27 | "babel-loader": "^7.1.1",
28 | "babel-plugin-istanbul": "^4.1.1",
29 | "babel-plugin-syntax-jsx": "^6.18.0",
30 | "babel-plugin-transform-runtime": "^6.22.0",
31 | "babel-plugin-transform-vue-jsx": "^3.5.0",
32 | "babel-polyfill": "^6.26.0",
33 | "babel-preset-env": "^1.3.2",
34 | "babel-preset-stage-2": "^6.22.0",
35 | "babel-register": "^6.22.0",
36 | "chai": "^4.1.2",
37 | "chalk": "^2.0.1",
38 | "chromedriver": "^2.27.2",
39 | "copy-webpack-plugin": "^4.0.1",
40 | "cross-env": "^5.0.1",
41 | "cross-spawn": "^5.0.1",
42 | "css-loader": "^0.28.0",
43 | "eslint": "^4.15.0",
44 | "eslint-config-airbnb-base": "^11.3.0",
45 | "eslint-friendly-formatter": "^3.0.0",
46 | "eslint-import-resolver-webpack": "^0.8.3",
47 | "eslint-loader": "^1.7.1",
48 | "eslint-plugin-import": "^2.7.0",
49 | "eslint-plugin-vue": "^4.0.0",
50 | "extract-text-webpack-plugin": "^3.0.0",
51 | "file-loader": "^1.1.4",
52 | "friendly-errors-webpack-plugin": "^1.6.1",
53 | "html-webpack-plugin": "^2.30.1",
54 | "inject-loader": "^3.0.0",
55 | "karma": "^1.4.1",
56 | "karma-coverage": "^1.1.1",
57 | "karma-mocha": "^1.3.0",
58 | "karma-phantomjs-launcher": "^1.0.2",
59 | "karma-phantomjs-shim": "^1.4.0",
60 | "karma-sinon-chai": "^1.3.1",
61 | "karma-sourcemap-loader": "^0.3.7",
62 | "karma-spec-reporter": "0.0.31",
63 | "karma-webpack": "^2.0.2",
64 | "mocha": "^3.2.0",
65 | "nightwatch": "^0.9.12",
66 | "node-notifier": "^5.1.2",
67 | "optimize-css-assets-webpack-plugin": "^3.2.0",
68 | "ora": "^1.2.0",
69 | "phantomjs-prebuilt": "^2.1.14",
70 | "portfinder": "^1.0.13",
71 | "postcss-import": "^11.0.0",
72 | "postcss-loader": "^2.0.8",
73 | "postcss-url": "^7.2.1",
74 | "rimraf": "^2.6.0",
75 | "selenium-server": "^3.0.1",
76 | "semver": "^5.3.0",
77 | "shelljs": "^0.7.6",
78 | "sinon": "^4.0.0",
79 | "sinon-chai": "^2.8.0",
80 | "uglifyjs-webpack-plugin": "^1.1.1",
81 | "url-loader": "^0.5.8",
82 | "vue-loader": "^13.3.0",
83 | "vue-style-loader": "^3.0.1",
84 | "vue-template-compiler": "^2.5.2",
85 | "webpack": "^3.6.0",
86 | "webpack-bundle-analyzer": "^3.3.2",
87 | "webpack-dev-server": "^2.9.1",
88 | "webpack-merge": "^4.1.0"
89 | },
90 | "engines": {
91 | "node": ">= 6.0.0",
92 | "npm": ">= 3.0.0"
93 | },
94 | "browserslist": [
95 | "> 1%",
96 | "last 2 versions",
97 | "not ie <= 8"
98 | ]
99 | }
100 |
--------------------------------------------------------------------------------
/server/server/api/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 2.0 on 2018-01-03 21:54
2 |
3 | from django.conf import settings
4 | import django.contrib.auth.models
5 | import django.contrib.auth.validators
6 | from django.db import migrations, models
7 | import django.db.models.deletion
8 | import django.utils.timezone
9 |
10 |
11 | class Migration(migrations.Migration):
12 |
13 | initial = True
14 |
15 | dependencies = [
16 | ('auth', '0009_alter_user_last_name_max_length'),
17 | ]
18 |
19 | operations = [
20 | migrations.CreateModel(
21 | name='User',
22 | fields=[
23 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
24 | ('password', models.CharField(max_length=128, verbose_name='password')),
25 | ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
26 | ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
27 | ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
28 | ('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
29 | ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
30 | ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
31 | ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
32 | ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
33 | ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
34 | ('followers', models.ManyToManyField(related_name='followees', to=settings.AUTH_USER_MODEL)),
35 | ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
36 | ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
37 | ],
38 | options={
39 | 'verbose_name_plural': 'users',
40 | 'abstract': False,
41 | 'verbose_name': 'user',
42 | },
43 | managers=[
44 | ('objects', django.contrib.auth.models.UserManager()),
45 | ],
46 | ),
47 | migrations.CreateModel(
48 | name='Post',
49 | fields=[
50 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
51 | ('created', models.DateTimeField(auto_now_add=True)),
52 | ('content', models.TextField(blank=True, null=True)),
53 | ('title', models.CharField(max_length=255)),
54 | ('updated', models.DateTimeField(auto_now=True)),
55 | ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='posts', to=settings.AUTH_USER_MODEL)),
56 | ],
57 | ),
58 | ]
59 |
--------------------------------------------------------------------------------
/server/server/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | For more information on this file, see
3 | https://docs.djangoproject.com/en/1.7/topics/settings/
4 |
5 | For the full list of settings and their values, see
6 | https://docs.djangoproject.com/en/1.7/ref/settings/
7 | """
8 |
9 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
10 | import os
11 |
12 | BASE_DIR = os.path.dirname(os.path.dirname(__file__))
13 | CLIENT_DIST_DIR = os.path.join(BASE_DIR, '..', 'client', 'dist')
14 |
15 | # Quick-start development settings - unsuitable for production
16 | # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
17 |
18 | # SECURITY WARNING: keep the secret key used in production secret
19 | SECRET_KEY = 'ma3c@7uu!%e0=tynp+i6+q%$)9v@$t(eulqurym_b=48z82&5n'
20 |
21 | # SECURITY WARNING: don't run with debug turned on in production
22 | DEBUG = True
23 |
24 | ALLOWED_HOSTS = []
25 |
26 | # Application definition
27 |
28 | INSTALLED_APPS = (
29 | 'django.contrib.admin',
30 | 'django.contrib.auth',
31 | 'django.contrib.contenttypes',
32 | 'django.contrib.sessions',
33 | # 'django.contrib.messages',
34 | 'django.contrib.staticfiles',
35 | 'django.contrib.sites',
36 |
37 | 'rest_framework',
38 | 'rest_framework.authtoken',
39 | 'rest_auth',
40 |
41 | 'allauth',
42 | 'allauth.account',
43 | 'rest_auth.registration',
44 | 'server.api',
45 | )
46 |
47 | MIDDLEWARE = (
48 | 'django.contrib.sessions.middleware.SessionMiddleware',
49 | 'django.middleware.common.CommonMiddleware',
50 | 'django.middleware.csrf.CsrfViewMiddleware',
51 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
52 |
53 | 'django.contrib.messages.middleware.MessageMiddleware',
54 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
55 |
56 | 'django.middleware.security.SecurityMiddleware',
57 | )
58 |
59 | # For backwards compatibility for Django 1.8
60 | MIDDLEWARE_CLASSES = MIDDLEWARE
61 |
62 | ROOT_URLCONF = 'server.urls'
63 |
64 | WSGI_APPLICATION = 'server.wsgi.application'
65 |
66 | # Database
67 | # https://docs.djangoproject.com/en/1.7/ref/settings/#databases
68 |
69 | DATABASES = {
70 | 'default': {
71 | 'ENGINE': 'django.db.backends.sqlite3',
72 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
73 | }
74 | }
75 |
76 | # Internationalization
77 | # https://docs.djangoproject.com/en/1.7/topics/i18n/
78 |
79 | LANGUAGE_CODE = 'en-us'
80 | TIME_ZONE = 'UTC'
81 | USE_I18N = True
82 | USE_L10N = True
83 | USE_TZ = True
84 |
85 | # Static files (CSS, JavaScript, Images)
86 | # https://docs.djangoproject.com/en/1.7/howto/static-files/
87 | STATIC_URL = '/static/'
88 | STATICFILES_DIRS = [os.path.join(CLIENT_DIST_DIR, 'static')]
89 |
90 | TEMPLATE_DIRS = [
91 | CLIENT_DIST_DIR,
92 | os.path.join(BASE_DIR, 'templates')
93 | ]
94 |
95 | TEMPLATES = [
96 | {
97 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
98 | 'DIRS': TEMPLATE_DIRS,
99 | 'APP_DIRS': True,
100 | 'OPTIONS': {
101 | 'context_processors': [
102 | 'django.template.context_processors.debug',
103 | 'django.template.context_processors.request',
104 | 'django.contrib.auth.context_processors.auth',
105 | 'django.contrib.messages.context_processors.messages',
106 | ],
107 | },
108 | },
109 | ]
110 |
111 | REST_SESSION_LOGIN = True
112 | EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
113 | SITE_ID = 1
114 |
115 |
116 | REST_FRAMEWORK = {
117 | 'DEFAULT_AUTHENTICATION_CLASSES': (
118 | 'rest_framework.authentication.SessionAuthentication',
119 | 'rest_framework.authentication.TokenAuthentication',
120 | )
121 | }
122 |
123 | AUTH_USER_MODEL = 'api.User'
124 |
125 | # SECURITY WARNING: don't use AlwaysRootBackend in production
126 | AUTHENTICATION_BACKENDS = ['server.auth.AlwaysRootBackend']
127 |
128 | # Django allauth (account registration email flow)
129 | # http://django-allauth.readthedocs.io/en/latest/configuration.html
130 |
131 | ACCOUNT_EMAIL_REQUIRED = True
132 | ACCOUNT_AUTHENTICATION_METHOD = 'username'
133 | ACCOUNT_EMAIL_VERIFICATION = 'optional'
134 |
--------------------------------------------------------------------------------
/client/build/webpack.prod.conf.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | const path = require('path')
3 | const utils = require('./utils')
4 | const webpack = require('webpack')
5 | const config = require('../config')
6 | const merge = require('webpack-merge')
7 | const baseWebpackConfig = require('./webpack.base.conf')
8 | const CopyWebpackPlugin = require('copy-webpack-plugin')
9 | const HtmlWebpackPlugin = require('html-webpack-plugin')
10 | const ExtractTextPlugin = require('extract-text-webpack-plugin')
11 | const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
12 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
13 |
14 | const env = process.env.NODE_ENV === 'testing'
15 | ? require('../config/test.env')
16 | : require('../config/prod.env')
17 |
18 | const webpackConfig = merge(baseWebpackConfig, {
19 | module: {
20 | rules: utils.styleLoaders({
21 | sourceMap: config.build.productionSourceMap,
22 | extract: true,
23 | usePostCSS: true
24 | })
25 | },
26 | devtool: config.build.productionSourceMap ? config.build.devtool : false,
27 | output: {
28 | path: config.build.assetsRoot,
29 | filename: utils.assetsPath('js/[name].[chunkhash].js'),
30 | chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
31 | },
32 | plugins: [
33 | // http://vuejs.github.io/vue-loader/en/workflow/production.html
34 | new webpack.DefinePlugin({
35 | 'process.env': env
36 | }),
37 | new UglifyJsPlugin({
38 | uglifyOptions: {
39 | compress: {
40 | warnings: false
41 | }
42 | },
43 | sourceMap: config.build.productionSourceMap,
44 | parallel: true
45 | }),
46 | // extract css into its own file
47 | new ExtractTextPlugin({
48 | filename: utils.assetsPath('css/[name].[contenthash].css'),
49 | // Setting the following option to `false` will not extract CSS from codesplit chunks.
50 | // Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack.
51 | // It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`,
52 | // increasing file size: https://github.com/vuejs-templates/webpack/issues/1110
53 | allChunks: true,
54 | }),
55 | // Compress extracted CSS. We are using this plugin so that possible
56 | // duplicated CSS from different components can be deduped.
57 | new OptimizeCSSPlugin({
58 | cssProcessorOptions: config.build.productionSourceMap
59 | ? { safe: true, map: { inline: false } }
60 | : { safe: true }
61 | }),
62 | // generate dist index.html with correct asset hash for caching.
63 | // you can customize output by editing /index.html
64 | // see https://github.com/ampedandwired/html-webpack-plugin
65 | new HtmlWebpackPlugin({
66 | filename: process.env.NODE_ENV === 'testing'
67 | ? 'index.html'
68 | : config.build.index,
69 | template: 'index.html',
70 | inject: true,
71 | minify: {
72 | removeComments: true,
73 | collapseWhitespace: true,
74 | removeAttributeQuotes: true
75 | // more options:
76 | // https://github.com/kangax/html-minifier#options-quick-reference
77 | },
78 | // necessary to consistently work with multiple chunks via CommonsChunkPlugin
79 | chunksSortMode: 'dependency'
80 | }),
81 | // keep module.id stable when vendor modules does not change
82 | new webpack.HashedModuleIdsPlugin(),
83 | // enable scope hoisting
84 | new webpack.optimize.ModuleConcatenationPlugin(),
85 | // split vendor js into its own file
86 | new webpack.optimize.CommonsChunkPlugin({
87 | name: 'vendor',
88 | minChunks (module) {
89 | // any required modules inside node_modules are extracted to vendor
90 | return (
91 | module.resource &&
92 | /\.js$/.test(module.resource) &&
93 | module.resource.indexOf(
94 | path.join(__dirname, '../node_modules')
95 | ) === 0
96 | )
97 | }
98 | }),
99 | // extract webpack runtime and module manifest to its own file in order to
100 | // prevent vendor hash from being updated whenever app bundle is updated
101 | new webpack.optimize.CommonsChunkPlugin({
102 | name: 'manifest',
103 | minChunks: Infinity
104 | }),
105 | // This instance extracts shared chunks from code splitted chunks and bundles them
106 | // in a separate chunk, similar to the vendor chunk
107 | // see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk
108 | new webpack.optimize.CommonsChunkPlugin({
109 | name: 'app',
110 | async: 'vendor-async',
111 | children: true,
112 | minChunks: 3
113 | }),
114 |
115 | // copy custom static assets
116 | new CopyWebpackPlugin([
117 | {
118 | from: path.resolve(__dirname, '../static'),
119 | to: config.build.assetsSubDirectory,
120 | ignore: ['.*']
121 | }
122 | ])
123 | ]
124 | })
125 |
126 | if (config.build.productionGzip) {
127 | const CompressionWebpackPlugin = require('compression-webpack-plugin')
128 |
129 | webpackConfig.plugins.push(
130 | new CompressionWebpackPlugin({
131 | asset: '[path].gz[query]',
132 | algorithm: 'gzip',
133 | test: new RegExp(
134 | '\\.(' +
135 | config.build.productionGzipExtensions.join('|') +
136 | ')$'
137 | ),
138 | threshold: 10240,
139 | minRatio: 0.8
140 | })
141 | )
142 | }
143 |
144 | if (config.build.bundleAnalyzerReport) {
145 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
146 | webpackConfig.plugins.push(new BundleAnalyzerPlugin())
147 | }
148 |
149 | module.exports = webpackConfig
150 |
--------------------------------------------------------------------------------
/server/Pipfile.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_meta": {
3 | "hash": {
4 | "sha256": "f1bb6c800fc40232a91ac97c6b36afe31fca9aca5435baac071a26429a56227a"
5 | },
6 | "pipfile-spec": 6,
7 | "requires": {
8 | "python_version": "3"
9 | },
10 | "sources": [
11 | {
12 | "name": "pypi",
13 | "url": "https://pypi.python.org/simple",
14 | "verify_ssl": true
15 | }
16 | ]
17 | },
18 | "default": {
19 | "certifi": {
20 | "hashes": [
21 | "sha256:e4f3620cfea4f83eedc95b24abd9cd56f3c4b146dd0177e83a21b4eb49e21e50",
22 | "sha256:fd7c7c74727ddcf00e9acd26bba8da604ffec95bf1c2144e67aff7a8b50e6cef"
23 | ],
24 | "version": "==2019.9.11"
25 | },
26 | "chardet": {
27 | "hashes": [
28 | "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae",
29 | "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"
30 | ],
31 | "version": "==3.0.4"
32 | },
33 | "defusedxml": {
34 | "hashes": [
35 | "sha256:6687150770438374ab581bb7a1b327a847dd9c5749e396102de3fad4e8a3ef93",
36 | "sha256:f684034d135af4c6cbb949b8a4d2ed61634515257a67299e5f940fbaa34377f5"
37 | ],
38 | "version": "==0.6.0"
39 | },
40 | "django": {
41 | "hashes": [
42 | "sha256:97886b8a13bbc33bfeba2ff133035d3eca014e2309dff2b6da0bdfc0b8656613",
43 | "sha256:e900b73beee8977c7b887d90c6c57d68af10066b9dac898e1eaf0f82313de334"
44 | ],
45 | "index": "pypi",
46 | "version": "==2.0.7"
47 | },
48 | "django-allauth": {
49 | "hashes": [
50 | "sha256:7d9646e3560279d6294ebb4c361fef829708d106da697658cf158bf2ca57b474"
51 | ],
52 | "index": "pypi",
53 | "version": "==0.36.0"
54 | },
55 | "django-rest-auth": {
56 | "hashes": [
57 | "sha256:cd7874131fb8022c4d7f3ca317485fc3d54c2c9fc06fec32901d4f5247c5f8c1"
58 | ],
59 | "index": "pypi",
60 | "version": "==0.9.2"
61 | },
62 | "djangorestframework": {
63 | "hashes": [
64 | "sha256:b6714c3e4b0f8d524f193c91ecf5f5450092c2145439ac2769711f7eba89a9d9",
65 | "sha256:c375e4f95a3a64fccac412e36fb42ba36881e52313ec021ef410b40f67cddca4"
66 | ],
67 | "index": "pypi",
68 | "version": "==3.8.2"
69 | },
70 | "idna": {
71 | "hashes": [
72 | "sha256:156a6814fb5ac1fc6850fb002e0852d56c0c8d2531923a51032d1b70760e186e",
73 | "sha256:684a38a6f903c1d71d6d5fac066b58d7768af4de2b832e426ec79c30daa94a16"
74 | ],
75 | "version": "==2.7"
76 | },
77 | "oauthlib": {
78 | "hashes": [
79 | "sha256:bee41cc35fcca6e988463cacc3bcb8a96224f470ca547e697b604cc697b2f889",
80 | "sha256:df884cd6cbe20e32633f1db1072e9356f53638e4361bef4e8b03c9127c9328ea"
81 | ],
82 | "version": "==3.1.0"
83 | },
84 | "python3-openid": {
85 | "hashes": [
86 | "sha256:0086da6b6ef3161cfe50fb1ee5cceaf2cda1700019fda03c2c5c440ca6abe4fa",
87 | "sha256:628d365d687e12da12d02c6691170f4451db28d6d68d050007e4a40065868502"
88 | ],
89 | "version": "==3.1.0"
90 | },
91 | "pytz": {
92 | "hashes": [
93 | "sha256:1c557d7d0e871de1f5ccd5833f60fb2550652da6be2693c1e02300743d21500d",
94 | "sha256:b02c06db6cf09c12dd25137e563b31700d3b80fcc4ad23abb7a315f2789819be"
95 | ],
96 | "version": "==2019.3"
97 | },
98 | "requests": {
99 | "hashes": [
100 | "sha256:99dcfdaaeb17caf6e526f32b6a7b780461512ab3f1d992187801694cba42770c",
101 | "sha256:a84b8c9ab6239b578f22d1c21d51b696dcfe004032bb80ea832398d6909d7279"
102 | ],
103 | "index": "pypi",
104 | "version": "==2.20.0"
105 | },
106 | "requests-oauthlib": {
107 | "hashes": [
108 | "sha256:7f71572defaecd16372f9006f33c2ec8c077c3cfa6f5911a9a90202beb513f3d",
109 | "sha256:b4261601a71fd721a8bd6d7aa1cc1d6a8a93b4a9f5e96626f8e4d91e8beeaa6a"
110 | ],
111 | "version": "==1.3.0"
112 | },
113 | "six": {
114 | "hashes": [
115 | "sha256:418a93c397a7edab23e5588dbc067ac74a723edb3d541bd4936f79476e7645da",
116 | "sha256:e24052411fc4fbd1f672635537c3fc2330d9481b18c0317695b46259512c91d5"
117 | ],
118 | "index": "pypi",
119 | "version": "==1.9.0"
120 | },
121 | "urllib3": {
122 | "hashes": [
123 | "sha256:2393a695cd12afedd0dcb26fe5d50d0cf248e5a66f75dbd89a3d4eb333a61af4",
124 | "sha256:a637e5fae88995b256e3409dc4d52c2e2e0ba32c42a6365fee8bbd2238de3cfb"
125 | ],
126 | "version": "==1.24.3"
127 | }
128 | },
129 | "develop": {
130 | "factory-boy": {
131 | "hashes": [
132 | "sha256:6f25cc4761ac109efd503f096e2ad99421b1159f01a29dbb917359dcd68e08ca",
133 | "sha256:d552cb872b310ae78bd7429bf318e42e1e903b1a109e899a523293dfa762ea4f"
134 | ],
135 | "index": "pypi",
136 | "version": "==2.11.1"
137 | },
138 | "faker": {
139 | "hashes": [
140 | "sha256:0e9a1227a3a0f3297a485715e72ee6eb77081b17b629367042b586e38c03c867",
141 | "sha256:b4840807a94a3bad0217d6ed3f9b65a1cc6e1db1c99e1184673056ae2c0a4c4d"
142 | ],
143 | "index": "pypi",
144 | "version": "==0.8.17"
145 | },
146 | "python-dateutil": {
147 | "hashes": [
148 | "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c",
149 | "sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a"
150 | ],
151 | "version": "==2.8.1"
152 | },
153 | "six": {
154 | "hashes": [
155 | "sha256:418a93c397a7edab23e5588dbc067ac74a723edb3d541bd4936f79476e7645da",
156 | "sha256:e24052411fc4fbd1f672635537c3fc2330d9481b18c0317695b46259512c91d5"
157 | ],
158 | "index": "pypi",
159 | "version": "==1.9.0"
160 | },
161 | "text-unidecode": {
162 | "hashes": [
163 | "sha256:5a1375bb2ba7968740508ae38d92e1f889a0832913cb1c447d5e2046061a396d",
164 | "sha256:801e38bd550b943563660a91de8d4b6fa5df60a542be9093f7abf819f86050cc"
165 | ],
166 | "version": "==1.2"
167 | }
168 | }
169 | }
170 |
--------------------------------------------------------------------------------