<commit_before>from django.contrib.auth import authenticate, login as auth_login, logout as auth_logout
from django.contrib.auth.models import User
from django.shortcuts import redirect, render_to_response
from django.template import RequestContext
from django.views.decorators.http import require_http_methods
from frontend.forms import LoginForm, RegisterForm


def index(request):
    return redirect('frontend.views.login')


@require_http_methods(['GET', 'POST'])
def login(request):
    params = {'erorr': ''}

    if request.method == 'POST':
        form = LoginForm(request.POST)

        if form.is_valid():
            user = authenticate(username=form.cleaned_data['user_id'],
                                password=form.cleaned_data['password'])

            if user:
                auth_login(request, user)
                # TODO: go to dashboard

            else:
                params['error'] = 'invalid mail address or password'

        else:
            params['error'] = 'Invalid request'

    return _render_to_response('login.html', params, request)


def logout(request):
    auth_logout(request)
    return redirect('frontend.views.index')


@require_http_methods(['GET', 'POST'])
def register(request):
    params = {'is_succeeded': False,
              'has_error': False,
              'message': ''}

    if request.method == 'POST':
        form = RegisterForm(request.POST)

        if form.is_valid():
            user_id = form.cleaned_data['user_id']
            password1 = form.cleaned_data['password1']
            password2 = form.cleaned_data['<PASSWORD>']

            if password1 == password2:
                try:
                    user = User.objects.create_user(user_id, user_id, password1)
                    user.save()

                except:
                    params['has_error'] = True
                    params['message'] = 'Already registered'

                else:
                    params['is_succeeded'] = True
                    params['message'] = 'You have successfully registered!'

            else:
                params['has_error'] = True
                params['message'] = 'Passwords doesn\'t match'


        else:
            params['has_error'] = True
            params['message'] = 'Invalid request'


    return _render_to_response('register.html', params, request)


def settings(request):
    pass


def about(request):
    return render_to_response('about.html')


def _render_to_response(template, params, request):
    return render_to_response(template,
                              params,
                              context_instance=RequestContext(request))
<commit_msg>change to add user to MongoDB<commit_after>from django.contrib.auth import authenticate, login as auth_login, logout as auth_logout
from django.contrib.auth.models import User
from django.shortcuts import redirect, render_to_response
from django.template import RequestContext
from django.views.decorators.http import require_http_methods
from frontend.forms import LoginForm, RegisterForm

import pymongo


def index(request):
    return redirect('frontend.views.login')


@require_http_methods(['GET', 'POST'])
def login(request):
    params = {'erorr': ''}

    if request.method == 'POST':
        form = LoginForm(request.POST)

        if form.is_valid():
            user = authenticate(username=form.cleaned_data['user_id'],
                                password=form.cleaned_data['password'])

            if user:
                auth_login(request, user)
                # TODO: go to dashboard

            else:
                params['error'] = 'invalid mail address or password'

        else:
            params['error'] = 'Invalid request'

    return _render_to_response('login.html', params, request)


def logout(request):
    auth_logout(request)
    return redirect('frontend.views.index')


@require_http_methods(['GET', 'POST'])
def register(request):
    params = {'is_succeeded': False,
              'has_error': False,
              'message': ''}

    if request.method == 'POST':
        form = RegisterForm(request.POST)

        if form.is_valid():
            user_id = form.cleaned_data['user_id']
            password1 = form.cleaned_data['<PASSWORD>']
            password2 = form.cleaned_data['password2']

            if password1 == password2:
                try:
                    user = User.objects.create_user(user_id, user_id, password1)
                    user.save()

                except:
                    params['has_error'] = True
                    params['message'] = 'Already registered'

                else:
                    with pymongo.Connection() as connection:
                        db = connection['pergenie']
                        users = db['users']
                        users.insert({'user_id': user_id})

                    params['is_succeeded'] = True
                    params['message'] = 'You have successfully registered!'

            else:
                params['has_error'] = True
                params['message'] = 'Passwords doesn\'t match'


        else:
            params['has_error'] = True
            params['message'] = 'Invalid request'


    return _render_to_response('register.html', params, request)


def settings(request):
    pass


def about(request):
    return render_to_response('about.html')


def _render_to_response(template, params, request):
    return render_to_response(template,
                              params,
                              context_instance=RequestContext(request))

{'fraction_non_alphanumeric': 0.10409586835986406, 'fraction_numerical': 0.0021463065641209086, 'mean_word_length': 2.1066666666666665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7527167', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1411, 'n_words': 333}