Permalink
Browse files

Initial commit

  • Loading branch information...
cuu508 committed Jun 11, 2015
0 parents commit 00cdc313eca85a5a2bc68e77fc7dcef5f72eadfc
@@ -0,0 +1 @@
__pycache__/
No changes.
No changes.
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
@@ -0,0 +1,5 @@
from django import forms


class EmailForm(forms.Form):
email = forms.EmailField()
No changes.
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
@@ -0,0 +1,9 @@
from django.conf.urls import url

from hc.accounts import views

urlpatterns = [
url(r'^login/$', views.login, name="hc-login"),
url(r'^login_link_sent/$', views.login_link_sent, name="hc-login-link-sent"),
url(r'^check_token/([\w-]+)/$', views.check_token, name="hc-check-token"),
]
@@ -0,0 +1,49 @@
import uuid

from django.conf import settings
from django.contrib.auth.models import User
from django.core.mail import send_mail
from django.core.urlresolvers import reverse
from django.shortcuts import redirect, render

from hc.accounts.forms import EmailForm


def login(request):

if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = EmailForm(request.POST)
# check whether it's valid:
if form.is_valid():
email = form.cleaned_data["email"]
user = User.objects.get(email=email)
token = str(uuid.uuid4())
user.set_password(token)
user.save()

login_link = reverse("hc-check-token", args=[token])
login_link = settings.SITE_ROOT + login_link
body = "login link: %s" % login_link

send_mail('Log In', body, 'cuu508@gmail.com', [email], fail_silently=False)

# FIXME send login token here
return redirect("hc-login-link-sent")

else:
form = EmailForm()

ctx = {
"form": form
}

return render(request, "accounts/login.html", ctx)


def login_link_sent(request):
return render(request, "accounts/login_link_sent.html")


def check_token(request):
return render(request, "accounts/login_link_sent.html")
No changes.
@@ -0,0 +1,8 @@
from django.contrib import admin

from hc.checks.models import Canary


@admin.register(Canary)
class CanaryAdmin(admin.ModelAdmin):
list_display = ("id", "code", "user", "last_ping")
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import uuid
from django.conf import settings


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Canary',
fields=[
('id', models.AutoField(auto_created=True, serialize=False, primary_key=True, verbose_name='ID')),
('code', models.UUIDField(default=uuid.uuid4, editable=False)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
],
),
]
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('checks', '0001_initial'),
]

operations = [
migrations.AlterModelOptions(
name='canary',
options={'verbose_name_plural': 'canaries'},
),
migrations.AddField(
model_name='canary',
name='last_ping',
field=models.DateTimeField(null=True, blank=True),
),
]
No changes.
@@ -0,0 +1,13 @@
import uuid

from django.contrib.auth.models import User
from django.db import models


class Canary(models.Model):
class Meta:
verbose_name_plural = "canaries"

code = models.UUIDField(default=uuid.uuid4, editable=False)
user = models.ForeignKey(User)
last_ping = models.DateTimeField(null=True, blank=True)
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
@@ -0,0 +1,7 @@
from django.conf.urls import url

from hc.checks import views

urlpatterns = [
url(r'^ping/([\w-]+)/$', views.ping, name="hc-ping"),
]
@@ -0,0 +1,16 @@
from django.http import HttpResponse, HttpResponseBadRequest
from django.utils import timezone

from hc.checks.models import Canary


def ping(request, code):
try:
canary = Canary.objects.get(code=code)
except Canary.DoesNotExist:
return HttpResponseBadRequest()

canary.last_ping = timezone.now()
canary.save()

return HttpResponse()
@@ -0,0 +1,111 @@
"""
Django settings for hc project.
Generated by 'django-admin startproject' using Django 1.8.2.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '9)gjy!j50uvbcy#y9ifoh@9pf%3m5^-9h0jv@+3^ln$%az8e(7'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

'bootstrap3',

'hc.accounts',
'hc.checks'
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'hc.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'hc.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'hc',
'USER': 'hc',
'PASSWORD': '',
'HOST': '192.168.1.111',
'PORT': 5432,
'TEST': {'CHARSET': 'UTF8'}
}
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


SITE_ROOT = "http://localhost:8000"
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
@@ -0,0 +1,8 @@
from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('hc.accounts.urls')),
url(r'^', include('hc.checks.urls')),
]
@@ -0,0 +1,16 @@
"""
WSGI config for hc project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hc.settings")

application = get_wsgi_application()
@@ -0,0 +1,10 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hc.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
@@ -0,0 +1,3 @@
Django==1.8.2
django-bootstrap3
psycopg2==2.6

Large diffs are not rendered by default.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 00cdc31

Please sign in to comment.