微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 硬件工程师文库 > 基于Dragonboard 410c服务器系列之二局域网用户管理系统

基于Dragonboard 410c服务器系列之二局域网用户管理系统

时间:02-15 来源:互联网 点击:

一、前言

在上一篇文章中,博主给大家分享了如何基于410c利用python的Django框架去构建自己的局域网web服务器,今天我们在其基础上再扩展建立一个局域网的用户管理系统。

二、代码分析

1.代码框架

图1 代码框架

2.主代码分享:

2.1.online/view.py

#coding=utf-8

from django.shortcuts import render,render_to_response

from django.http import HttpResponse,HttpResponseRedirect

from django.template import RequestContext

from django import forms

from online.models import User

from django.contrib.auth import authenTIcate, login

#表单

class UserForm(forms.Form):

username = forms.CharField(label='用户名',max_length=100)

password = forms.CharField(label='密码',widget=forms.PasswordInput())

 

#def getuser(forms):

# return forms.username

# password1 = forms.CharField(label='重复密码',widget=forms.TexTInput())

# loginaddr="http://127.0.0.1:8000/online/login/"

# registaddr=http://127.0.0.1:8000/online/regist/

 

#注册

def regist(req):

if req.method == 'POST':

uf = UserForm(req.POST)

if uf.is_valid():

#获得表单数据

username = uf.cleaned_data['username']

password = uf.cleaned_data['password']

password1 = req.POST['password1']

#比较数据库中是否已有用户

#user = myUser.objects.all().filter(username = username)

#print(user)

if User.objects.filter(username =username).exists():

return render_to_response('registfaild.html',{'uf':uf}, context_instance=RequestContext(req))

else:

if password1==password:

# User.objects.create(username= username,password=password)#添加用户进数据库

# profile=UserProfile()#e*************************

# profile.user_id=user.id

# profile.phone=phone

# profile.save()

 

# user=User()

# user.username=username

# user.password=password

# user.save()

user = User.objects.create_user(username,password)

user.save()

response = HttpResponseRedirect('/online/registsuccee/')

return response

else:

return render_to_response('registfaild1.html',{'uf':uf}, context_instance=RequestContext(req))

else:

uf = UserForm()

return render_to_response('regist.html',{'uf':uf}, context_instance=RequestContext(req))

 

#登陆

def login(req):

# getAllUser(req)

if req.method == 'POST':

uf = UserForm(req.POST)

if uf.is_valid():

#获取表单用户密码

username = uf.cleaned_data['username']

password = uf.cleaned_data['password']

 

#获取的表单数据与数据库进行比较

user = authenTIcate(username=username, password=password)

if user is not None:

#比较成功,跳转index

response = HttpResponseRedirect('/online/index/')

#将username写入浏览器cookie,失效时间为3600

response.set_cookie('username',username,3600)

return response

else:

#比较失败,跳转loginfaild

return render_to_response('loginfaild.html',{'uf':uf},context_instance=RequestContext(req))

else:

uf = UserForm()

return render_to_response('login.html',{'uf':uf},context_instance=RequestContext(req))

 

 

 

#def loginfaild(req):

# response = login(req)

# return response

#

def registsuccee(req):

if req.method == 'POST':

uf = UserForm(req.POST)

if uf.is_valid():

#获取表单用户密码

username = uf.cleaned_data['username']

password = uf.cleaned_data['password']

#获取的表单数据与数据库进行比较

user = User.objects.filter(username__exact = username,password__exact = password)

if user:

#比较成功,跳

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top