parent
f934115621
commit
447b353dd2
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
|
||||
"""
|
||||
@version: ??
|
||||
@author: liangliangyy
|
||||
@license: MIT Licence
|
||||
@contact: liangliangyy@gmail.com
|
||||
@site: https://www.lylinux.org/
|
||||
@software: PyCharm
|
||||
@file: forms.py
|
||||
@time: 2016/11/20 下午3:16
|
||||
"""
|
||||
from django.contrib.auth.forms import AuthenticationForm, UserCreationForm
|
||||
from django.forms import widgets
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
|
||||
class LoginForm(AuthenticationForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(LoginForm, self).__init__(*args, **kwargs)
|
||||
self.fields['username'].widget = widgets.TextInput(attrs={'placeholder': "用户名", "class": "form-control"})
|
||||
self.fields['password'].widget = widgets.PasswordInput(attrs={'placeholder': "密码", "class": "form-control"})
|
||||
|
||||
|
||||
class RegisterForm(UserCreationForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(RegisterForm, self).__init__(*args, **kwargs)
|
||||
|
||||
self.fields['username'].widget = widgets.TextInput(attrs={'placeholder': "用户名", "class": "form-control"})
|
||||
self.fields['email'].widget = widgets.EmailInput(attrs={'placeholder': "邮箱", "class": "form-control"})
|
||||
self.fields['password1'].widget = widgets.PasswordInput(attrs={'placeholder': "密码", "class": "form-control"})
|
||||
self.fields['password2'].widget = widgets.PasswordInput(attrs={'placeholder': "确认密码", "class": "form-control"})
|
||||
|
||||
class Meta:
|
||||
model = get_user_model()
|
||||
fields = ("username", "email")
|
||||
@ -1,12 +1,26 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.contrib.auth.models import AbstractUser, BaseUserManager
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
|
||||
# Create your models here.
|
||||
class BlogUserManager(BaseUserManager):
|
||||
def create_user(self, email, username, password=None):
|
||||
user = self.model(
|
||||
username=username, email=email, nickname=username
|
||||
)
|
||||
user.set_password(password)
|
||||
user.save(using=self._db)
|
||||
return user
|
||||
|
||||
|
||||
class BlogUser(AbstractUser):
|
||||
nickname = models.CharField('昵称', max_length=50, blank=True)
|
||||
mugshot = models.ImageField('头像', upload_to='upload/mugshots', blank=True)
|
||||
objects = BlogUserManager()
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('blog:author_detail', kwargs={'author_name': self.username})
|
||||
|
||||
def __str__(self):
|
||||
return self.email
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
|
||||
"""
|
||||
@version: ??
|
||||
@author: liangliangyy
|
||||
@license: MIT Licence
|
||||
@contact: liangliangyy@gmail.com
|
||||
@site: https://www.lylinux.org/
|
||||
@software: PyCharm
|
||||
@file: urls.py
|
||||
@time: 2016/11/20 下午3:52
|
||||
"""
|
||||
|
||||
from django.conf.urls import url
|
||||
from django.contrib.auth import views as auth_view
|
||||
|
||||
from . import views
|
||||
from .forms import LoginForm
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^login/$', views.LoginView.as_view(success_url='/'), name='login', kwargs={'authentication_form': LoginForm}),
|
||||
url(r'^register/$', views.RegisterView.as_view(success_url="/"), name='register'),
|
||||
]
|
||||
@ -1,3 +1,25 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
from django.contrib.auth.views import login
|
||||
from .forms import RegisterForm,LoginForm
|
||||
from django.views.generic.edit import FormView
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
|
||||
# Create your views here.
|
||||
class RegisterView(FormView):
|
||||
form_class = RegisterForm
|
||||
template_name = 'account/registration_form.html'
|
||||
|
||||
def form_valid(self, form):
|
||||
user = form.save(False)
|
||||
|
||||
user.save(True)
|
||||
return HttpResponseRedirect('/')
|
||||
|
||||
|
||||
class LoginView(FormView):
|
||||
form_class =LoginForm
|
||||
template_name = 'account/login.html'
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,58 @@
|
||||
body {
|
||||
padding-top: 40px;
|
||||
padding-bottom: 40px;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.form-signin {
|
||||
max-width: 330px;
|
||||
padding: 15px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.form-signin-heading {
|
||||
margin: 0 0 15px;
|
||||
font-size: 18px;
|
||||
font-weight: 400;
|
||||
color: #555;
|
||||
}
|
||||
.form-signin .checkbox {
|
||||
margin-bottom: 10px;
|
||||
font-weight: normal;
|
||||
}
|
||||
.form-signin .form-control {
|
||||
position: relative;
|
||||
height: auto;
|
||||
-webkit-box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
padding: 10px;
|
||||
font-size: 16px;
|
||||
}
|
||||
.form-signin .form-control:focus {
|
||||
z-index: 2;
|
||||
}
|
||||
.form-signin input[type="email"] {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.form-signin input[type="password"] {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.card {
|
||||
width: 304px;
|
||||
padding: 20px 25px 30px;
|
||||
margin: 0 auto 25px;
|
||||
background-color: #f7f7f7;
|
||||
border-radius: 2px;
|
||||
-webkit-box-shadow: 0 2px 2px rgba(0, 0, 0, .3);
|
||||
box-shadow: 0 2px 2px rgba(0, 0, 0, .3);
|
||||
}
|
||||
.card-signin {
|
||||
width: 354px;
|
||||
padding: 40px;
|
||||
}
|
||||
.card-signin .profile-img {
|
||||
display: block;
|
||||
width: 96px;
|
||||
height: 96px;
|
||||
margin: 0 auto 10px;
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 2.1 KiB |
@ -0,0 +1,40 @@
|
||||
{% extends 'accountbase.html' %}
|
||||
{% load static %}
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
|
||||
<h2 class="form-signin-heading text-center">Sign in with your Account</h2>
|
||||
|
||||
<div class="card card-signin">
|
||||
<img class="img-circle profile-img" src="{% static 'blog/img/avatar.png' %}" alt="">
|
||||
<form class="form-signin" action="{% url 'account:login' %}" method="post">
|
||||
{% csrf_token %}
|
||||
{% comment %}<label for="inputEmail" class="sr-only">Email address</label>
|
||||
<input type="email" id="inputEmail" class="form-control" placeholder="Email" required autofocus>
|
||||
<label for="inputPassword" class="sr-only">Password</label>
|
||||
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required>{% endcomment %}
|
||||
{{ form.non_field_errors }}
|
||||
{% for field in form %}
|
||||
{{ field }}
|
||||
{{ field.errors }}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
|
||||
|
||||
<div class="checkbox">
|
||||
<a class="pull-right">Need help?</a>
|
||||
<label>
|
||||
<input type="checkbox" value="remember-me"> Stay signed in
|
||||
</label>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<p class="text-center">
|
||||
<a>Create an account</a>
|
||||
</p>
|
||||
|
||||
</div> <!-- /container -->
|
||||
{% endblock %}
|
||||
@ -0,0 +1,41 @@
|
||||
{% extends 'accountbase.html' %}
|
||||
{% load static %}
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
|
||||
<h2 class="form-signin-heading text-center">Sign in with your Account</h2>
|
||||
|
||||
<div class="card card-signin">
|
||||
<img class="img-circle profile-img" src="{% static 'blog/img/avatar.png' %}" alt="">
|
||||
<form class="form-signin" action="{% url 'account:register' %}" method="post">
|
||||
{% csrf_token %}
|
||||
{% comment %}<label for="inputEmail" class="sr-only">Email address</label>
|
||||
<input type="email" id="inputEmail" class="form-control" placeholder="Email" required autofocus>
|
||||
<label for="inputPassword" class="sr-only">Password</label>
|
||||
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required>{% endcomment %}
|
||||
{{ form.non_field_errors }}
|
||||
{% for field in form %}
|
||||
{{ field }}
|
||||
{{ field.errors }}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
|
||||
|
||||
{% comment %}
|
||||
<div class="checkbox">
|
||||
<a class="pull-right">Need help?</a>
|
||||
<label>
|
||||
<input type="checkbox" value="remember-me"> Stay signed in
|
||||
</label>
|
||||
</div>
|
||||
{% endcomment %}
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<p class="text-center">
|
||||
<a>Create an account</a>
|
||||
</p>
|
||||
|
||||
</div> <!-- /container -->
|
||||
{% endblock %}
|
||||
@ -0,0 +1,41 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
{% load static %}
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
<link rel="icon" href="../../favicon.ico">
|
||||
|
||||
<title>Signin Template for TODC Bootstrap</title>
|
||||
|
||||
<!-- Bootstrap core CSS -->
|
||||
<link href="{% static 'assets/css/bootstrap.min.css' %}" rel="stylesheet">
|
||||
|
||||
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
|
||||
<link href="{% static 'assets/css/ie10-viewport-bug-workaround.css' %}" rel="stylesheet">
|
||||
<!-- TODC Bootstrap core CSS -->
|
||||
<link href="{% static 'assets/css/todc-bootstrap.min.css' %}" rel="stylesheet">
|
||||
<!-- Custom styles for this template -->
|
||||
<link href="{% static 'assets/css/signin.css' %}" rel="stylesheet">
|
||||
|
||||
<script src="{% static 'assets/js/ie-emulation-modes-warning.js' %}"></script>
|
||||
|
||||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
|
||||
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
|
||||
<script src="{% static 'assets/js/ie10-viewport-bug-workaround.js' %}"></script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in new issue