Exemplo n.º 1
0
def get_login_form(request):
    loginForm = AuthenticationForm(prefix=settings.PREFIX_LOGIN)
    form = u"<div>{0}{1}</div>".format(loginForm['username'].label_tag(), loginForm['username'])
    form += u"<div>{0}{1}</div>".format(loginForm['password'].label_tag(), loginForm['password'])
    
    data={'form': form,}
    json_serializer = LazyEncoder()
    return HttpResponse(json_serializer.encode(data), mimetype='application/json')
Exemplo n.º 2
0
def get_signup_form(request):
    signupForm = SigninUserForm(prefix=settings.PREFIX_SIGNUP)
    form = u"<div>{0}{1}</div>".format(signupForm['username'].label_tag(), signupForm['username'])
    form += u"<div>{0}{1}</div>".format(signupForm['password1'].label_tag(), signupForm['password1'])
    form += u"<div>{0}{1}</div>".format(signupForm['password2'].label_tag(), signupForm['password2'])
    form += u"<div>{0}{1}</div>".format(signupForm['email'].label_tag(), signupForm['email'])
    
    data={'form': form,}
    json_serializer = LazyEncoder()
    return HttpResponse(json_serializer.encode(data), mimetype='application/json')
Exemplo n.º 3
0
def validate(request, *args, **kwargs):    
    form_class = kwargs.pop('form_class')    
    from_prefix = request.POST.get('formPrefix', '')
    form = form_class(request.POST, prefix=from_prefix)
    if form.is_valid():
        data = {
            'valid': True,
        }
        if request.POST.get('save'):
            signin_user(form)
            username = form.cleaned_data['username']
            password = form.cleaned_data['password1']
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
    else:        
        data = processErrors(request, form)
    json_serializer = LazyEncoder()
    return HttpResponse(json_serializer.encode(data), mimetype='application/json')
Exemplo n.º 4
0
def validate_login(request): 
    from_prefix = request.POST.get('formPrefix', '')
    if from_prefix:
        from_prefix += '-'
    username = request.POST.get(from_prefix+'username')
    password = request.POST.get(from_prefix+'password')
    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            login(request, user)
            data = {
                'valid': True,
            }
    else:
        final_errors = {}
        final_errors['__all__'] = ["Имя или пароль неверные",]
        data = {
            'valid': False,
            'errors': final_errors,
        }
    json_serializer = LazyEncoder()
    return HttpResponse(json_serializer.encode(data), mimetype='application/json')
Exemplo n.º 5
0
def validate_profile(request, *args, **kwargs):    
    if request.user.is_authenticated():
        form_class = kwargs.pop('form_class')
        edit_form = form_class(user=request.user, data=request.POST)
        if edit_form.is_valid():
            data = {
                'valid': True,
            }
            if request.POST.get('save'):
                user = edit_form.save() 
                request.user.message_set.create(message='Ваши данные обновлены')
        else:
            data = processErrors(request, edit_form)
    else:
        final_errors = {}
        final_errors['__all__'] = ["Вы не вошли",]
        data = {
            'valid': False,
            'errors': final_errors,
        }
        
    json_serializer = LazyEncoder()
    return HttpResponse(json_serializer.encode(data), mimetype='application/json')