update demo project - still not finished

This commit is contained in:
Mateusz Sikora 2014-10-15 17:32:19 +02:00
parent 5bd8842c4b
commit 5fd7ea5596
17 changed files with 311 additions and 123 deletions

Binary file not shown.

View File

@ -98,3 +98,10 @@ USE_TZ = True
STATIC_URL = '/static/'
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
REST_SESSION_LOGIN = False
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
SITE_ID = 1
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'

View File

@ -3,9 +3,16 @@ from django.contrib import admin
from django.views.generic import TemplateView
urlpatterns = patterns('',
# Examples:
url(r'^$', TemplateView.as_view(template_name="home.html"), name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^signup/$', TemplateView.as_view(template_name="signup.html"), name='signup'),
url(r'^email-verification/$', TemplateView.as_view(template_name="email_verification.html"), name='email-verification'),
url(r'^login/$', TemplateView.as_view(template_name="login.html"), name='login'),
url(r'^password-reset/$', TemplateView.as_view(template_name="password_reset.html"), name='password-reset'),
url(r'^password-reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
TemplateView.as_view(template_name="password_reset_confirm.html"),
name='password_reset_confirm'),
url(r'^rest-auth/', include('rest_auth.urls')),
url(r'^rest-auth/registration/', include('rest_auth.registration.urls')),
url(r'^admin/', include(admin.site.urls)),

96
demo/templates/base.html Normal file
View File

@ -0,0 +1,96 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Django-rest-auth demo">
<meta name="author" content="Tivix, Inc.">
<title>Starter Template for Bootstrap</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body role="document">
<div class="navbar navbar-inverse" role="navigation">
<div class="container">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">API endpoints <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
{% if request.user.is_authenticated %}
<li><a href="#">User details</a></li>
<li><a href="#">Password change</a></li>
<li><a href="#">Logout</a></li>
{% else %}
<li><a href="{% url 'signup' %}">Signup</a></li>
<li><a href="{% url 'email-verification' %}">E-mail verification</a></li>
<li><a href="{% url 'login' %}">Login</a></li>
<li><a href="{% url 'password-reset' %}">Password Reset</a></li>
{% endif %}
</ul>
</li>
</ul>
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">django-rest-auth demo</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="/">Demo</a></li>
<li><a target="_blank" href="http://django-rest-auth.readthedocs.org/en/latest/">Documentation</a></li>
<li><a target="_blank" href="https://github.com/Tivix/django-rest-auth">Source code</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<div class="container theme-showcase" role="main">
{% block content %}{% endblock %}
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
var error_response = function(data){
$('.api-response').html("API Response: " + data.status + ' ' + data.statusText + '<br/>Content: ' + data.responseText);
}
var susccess_response = function(data){
$('.api-response').html("API Response: OK<br/>Content: " + JSON.stringify(data));
}
$().ready(function(){
$('form button[type=submit]').click(function(){
var form = $('form');
$.post(form.attr('action'), $('form').serialize())
.fail(function(data){error_response(data);})
.done(function(data){susccess_response(data);});
return false;
});
});
</script>
{% block script %}{% endblock %}
</body>
</html>

View File

@ -0,0 +1,9 @@
{% extends "base.html" %}
{% block content %}
<div class="row">
<h3>E-mail verification</h3><hr/>
<p>Paste here a key which was sent in verification email</p>
{% include "fragments/email_verification_form.html" %}
</div>
{% endblock %}

View File

@ -0,0 +1,17 @@
<!-- Signup form -->
<form class="form-horizontal" role="form" action="{% url 'verify_email' %}">
<div class="form-group">
<label for="key" class="col-sm-2 control-label">Key</label>
<div class="col-sm-10">
<input name="key" type="text" class="form-control" id="key" placeholder="Key">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Verify</button>
</div>
</div>
<div class="form-group api-response"></div>
</form>

View File

@ -0,0 +1,24 @@
<!-- Signup form -->
<form class="form-horizontal" role="form" action="{% url 'rest_login' %}">
<div class="form-group">
<label for="username" class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<input name="username" type="text" class="form-control" id="username" placeholder="Username">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input name="password" type="password" class="form-control" id="password" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Login</button>
</div>
</div>
<div class="form-group api-response"></div>
</form>

View File

@ -0,0 +1,38 @@
<!-- Signup form -->
<form class="form-horizontal" role="form" action="{% url 'verify_email' %}">
<div class="form-group">
<label for="uid" class="col-sm-2 control-label">uid</label>
<div class="col-sm-10">
<input name="uid" type="text" class="form-control" id="uid" placeholder="uid">
</div>
</div>
<div class="form-group">
<label for="token" class="col-sm-2 control-label">token</label>
<div class="col-sm-10">
<input name="token" type="text" class="form-control" id="token" placeholder="token">
</div>
</div>
<div class="form-group">
<label for="password1" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input name="password1" type="password" class="form-control" id="password1" placeholder="Password">
</div>
</div>
<div class="form-group">
<label for="password2" class="col-sm-2 control-label">Repeat password</label>
<div class="col-sm-10">
<input name="password2" type="password" class="form-control" id="password2" placeholder="Repeat password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Set new password</button>
</div>
</div>
<div class="form-group api-response"></div>
</form>

View File

@ -0,0 +1,16 @@
<!-- Signup form -->
<form class="form-horizontal" role="form" action="{% url 'rest_password_reset' %}">
<div class="form-group">
<label for="email" class="col-sm-2 control-label">E-mail</label>
<div class="col-sm-10">
<input name="email" type="text" class="form-control" id="email" placeholder="Email">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Reset</button>
</div>
</div>
<div class="form-group api-response"></div>
</form>

View File

@ -0,0 +1,38 @@
<!-- Signup form -->
<form class="form-horizontal" id="signup" role="form" action="{% url 'rest_register' %}">
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input name="email" type="text" class="form-control" id="email" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="username" class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<input name="username" type="text" class="form-control" id="username" placeholder="Username">
</div>
</div>
<div class="form-group">
<label for="password1" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input name="password1" type="password" class="form-control" id="password1" placeholder="Password">
</div>
</div>
<div class="form-group">
<label for="password2" class="col-sm-2 control-label">Repeat password</label>
<div class="col-sm-10">
<input name="password2" type="password" class="form-control" id="password2" placeholder="Repeat password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Sign up</button>
</div>
</div>
<div class="form-group api-response"></div>
</form>

View File

@ -1,120 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Django-rest-auth demo">
<meta name="author" content="Tivix, Inc.">
{% extends "base.html" %}
<title>Starter Template for Bootstrap</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body role="document">
<div class="navbar navbar-inverse" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">django-rest-auth demo</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="/">Demo</a></li>
<li><a target="_blank" href="http://django-rest-auth.readthedocs.org/en/latest/">Documentation</a></li>
<li><a target="_blank" href="https://github.com/Tivix/django-rest-auth">Source code</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<div class="container theme-showcase" role="main">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li class="active"><a href="#signup" role="tab" data-toggle="tab">Signup</a></li>
<li><a href="#email-verification" role="tab" data-toggle="tab">E-mail verification</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active" id="signup">
<div class="row">
<!-- Signup form -->
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="username" class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<input name="username" type="text" class="form-control" id="username" placeholder="Username">
</div>
</div>
<div class="form-group">
<label for="password1" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input name="password1" type="password" class="form-control" id="password1" placeholder="Password">
</div>
</div>
<div class="form-group">
<label for="password2" class="col-sm-2 control-label">Repeat password</label>
<div class="col-sm-10">
<input name="password2" type="password" class="form-control" id="password2" placeholder="Repeat password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Sign up</button>
</div>
</div>
</form>
</div>
<div class="row api-response">
</div>
</div>
<div class="tab-pane" id="email-verification">E-mail verification</div>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
var print_response = function(selctor, data){
console.log(data);
$(selctor).html("API Response:<br/>Status code: " + data.status + ' ' + data.statusText + '<br/>Content: ' + data.responseText);
}
$().ready(function(){
$('#signup button[type=submit]').click(function(){
$.post( "/rest-auth/registration/", $('#signup form').serialize())
.always(function(data){
print_response('#signup .api-response', data);
});
return false;
});
});
</script>
</body>
</html>
{% block content %}
<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
<h1>django-rest-auth demo</h1>
<p>Welcome in django-rest-auth demo project!</p>
</div>
{% endblock %}

View File

@ -0,0 +1,8 @@
{% extends "base.html" %}
{% block content %}
<div class="row">
<h3>Login</h3><hr/>
{% include "fragments/login_form.html" %}
</div>
{% endblock %}

View File

@ -0,0 +1,8 @@
{% extends "base.html" %}
{% block content %}
<div class="row">
<h3>Password reset</h3><hr/>
{% include "fragments/password_reset_form.html" %}
</div>
{% endblock %}

View File

@ -0,0 +1,8 @@
{% extends "base.html" %}
{% block content %}
<div class="row">
<h3>Password reset confirmation</h3><hr/>
{% include "fragments/password_reset_confirm_form.html" %}
</div>
{% endblock %}

View File

@ -0,0 +1,23 @@
{% extends "base.html" %}
{% block content %}
<div class="row">
<h3>Signup</h3><hr/>
{% include "fragments/signup_form.html" %}
</div>
{% endblock %}
{% comment %}
{% block script %}
<script type="text/javascript">
$().ready(function(){
$('#signup button[type=submit]').click(function(){
$.post( "/rest-auth/registration/", $('#signup').serialize())
.fail(function(data){error_response(data);})
.done(function(data){susccess_response(data);});
return false;
});
});
</script>
{% endblock %}
{% endcomment %}

View File

@ -60,7 +60,7 @@ Registration
See allauth documentation for more details.
- /rest-auth/registration/ (POST)
- /rest-auth/registration/verify-email/ (POST)
- key

View File

@ -5,7 +5,7 @@ from .views import Register, VerifyEmail
urlpatterns = patterns('',
url(r'^$', Register.as_view(), name='rest_register'),
url(r'^verify-email/$', VerifyEmail.as_view(), name='verify_email'),
url(r'^verify-email/$', VerifyEmail.as_view(), name='rest_verify_email'),
# These two views are used in django-allauth and empty TemplateView were
# defined just to allow reverse() call inside app, for example when email