예제 #1
0
def register(request, templateName):
    nextPage = request.GET.get('next', '/')
    errMessage = ''

    if request.method == 'POST':
        userForm = UserCreationForm(request.POST)
        username = request.POST.get('username', None)
        password = request.POST.get('password1', None)
        if userForm.is_valid():
            userForm.save()
            user = auth.authenticate(username=username, password=password)
            auth.login(request, user)
            return redirect(nextPage)
        else:
            errMessage = '注册失败'
    return render(request, templateName, {
        'error': errMessage,
        'next': nextPage,
        })
예제 #2
0
def login(request, templateName):
    if request.user.is_authenticated():
        return redirect('/')

    nextPage = request.GET.get('next', '/')
    errMessage = ''

    if request.method == 'POST':
        username = request.POST.get('username', None)
        password = request.POST.get('password', None)
        user = auth.authenticate(username=username, password=password)
        if user is not None:
            auth.login(request, user)
            return redirect(nextPage)
        errMessage = '用户名或者密码错误'

    return render(request, templateName, {
        'error': errMessage,
        'next': nextPage,
        })