<commit_before>from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib.auth import login, logout, authenticate
from django.contrib.auth.views import login as django_login_view
from django.contrib.auth.models import UserManager
from .models import User


def login_view(request):
    """用户登录"""
    context = {}
    if request.method == 'POST':
        django_login_view(request)
        if not request.user.is_authenticated():
            context['error'] = 'error'

    return render(request, 'blogs/index.html', context)


def logout_view(request):
    """注销用户"""
    logout(request)
    return render(request, 'blogs/index.html')


def register(request):
    """注册"""
    if request.method == 'POST':
        data = request.POST
        user_manager = UserManager()
        username_ = data['username']
        email_ = data['email']
        password_ = data['password']
        nickname_ = data['nickname']

        # new_user = user_manager.create_user(username_, email_, password_, nickname =nickname_)
        new_user = User()
        new_user.username = username_
        new_user.nickname = nickname_
        new_user.email = email_
        new_user.set_password(password_)
        new_user.save()

        print(new_user)
        authenticated_user = authenticate(username = username_, password = password_)
        login(request, authenticated_user)
        return HttpResponseRedirect(reverse('blogs:index'))

    return render(request, 'users/register.html')
<commit_msg>完成注册功能<commit_after>from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib.auth import login, logout, authenticate
from django.contrib.auth.views import login as django_login_view
from django.contrib.auth.models import UserManager
from .models import User


def login_view(request):
    """用户登录"""
    context = {}
    if request.method == 'POST':
        django_login_view(request)
        if not request.user.is_authenticated():
            context['error'] = 'error'

    return render(request, 'blogs/index.html', context)


def logout_view(request):
    """注销用户"""
    logout(request)
    return render(request, 'blogs/index.html')


def register(request):
    """注册"""
    if request.method == 'POST':
        data = request.POST
        user_manager = UserManager()
        username_ = data['username']
        email_ = data['email']
        password_ = data['password']
        nickname_ = data['nickname']

        # new_user = user_manager.create_user(username_, email_, password_, nickname=nickname_)
        new_user = User()
        new_user.username = username_
        new_user.nickname = nickname_
        new_user.email = email_
        new_user.set_password(password_)
        new_user.save()

        print(new_user)
        authenticated_user = authenticate(username=username_, password=password_)
        login(request, authenticated_user)
        return HttpResponseRedirect(reverse('blogs:index'))

    return render(request, 'users/register.html')

{'fraction_non_alphanumeric': 0.10516252390057361, 'fraction_numerical': 0.0, 'mean_word_length': 3.3, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1624480', 'n_tokens_mistral': 908, 'n_tokens_neox': 881, 'n_words': 203}