Exemple #1
0
def changeExtUserInfo(request):
    if 'id' not in request.session:
        return HttpResponseRedirect('/')
    if request.method == 'POST':
        errors = list()
        extUserForm = forms.ChangeExtUserInfo(request.POST, request.FILES)
        if extUserForm.is_valid():
            extUser = extUserForm.save(commit=False)
            extUser.user_id = request.session['id']

            if extUser.phone != "" and not extUser.chkPhoneNumber():
                errors.append('Неправильный номер телефона!')
            if extUser.total_square != None:
                if extUser.total_square < 1:
                    errors.append('Некорректное значение площади')
            if extUser.cnt_fiodr != None:
                if extUser.cnt_fiodr < 1:
                    errors.append('Некорректное количество проживающих')

            print(extUser.ava.name)

            if len(errors) == 0:
                if ExtUser.objects.filter(user_id=extUser.user_id).exists():
                    tmpExtUser = ExtUser.objects.get(user_id=extUser.user_id)
                    if extUser.phone == "":
                        extUser.phone = tmpExtUser.phone
                    if extUser.adress == "":
                        extUser.adress = tmpExtUser.phone
                    if extUser.ava.name != '':
                        extUser.ava = tmpExtUser.ava
                    if extUser.cnt_fiodr != None:
                        extUser.cnt_fiodr = tmpExtUser.cnt_fiodr
                    if extUser.total_square != None:
                        extUser.total_square = tmpExtUser.total_square
                    tmpExtUser.delete()

                extUser.save()

                return render(
                    request, 'OK/index.html', {
                        'title': 'Отлично!',
                        'msg': 'Ваши данные успешно изменены.',
                        'link': 'account'
                    })

        defaultUserInfoForm = forms.ChangeUserInfo()
        changePassForm = forms.ChangePassword()
        changeMailForm = forms.ChangeMail()
        return render(
            request, 'AccountSettings/index.html', {
                'defUserInfo': defaultUserInfoForm,
                'extUserInfo': extUserForm,
                'changePass': changePassForm,
                'changeMail': changeMailForm,
                'extUserInfoErrors': errors,
            })
    return HttpResponseRedirect('/account')
Exemple #2
0
def changePassword(request):
    if 'id' not in request.session:
        return HttpResponseRedirect('/logout')
    if request.method == 'POST':
        errors = list()
        changePassForm = forms.ChangePassword(request.POST)
        if changePassForm.is_valid():
            oldpass = request.POST['oldpass']
            newpass = request.POST['newpass']
            repass = request.POST['repass']

            user = DefaultUser.objects.get(id=request.session['id'])
            user.decrypt()

            hashedOldPass = HashPassword(oldpass)
            if hashedOldPass != user.password:
                errors.append('Неверный пароль!')
            else:
                if newpass == oldpass:
                    errors.append('Придумайте новый пароль!')
                elif newpass != repass:
                    errors.append('Новые пароли не совпадают!')
                else:
                    DefaultUser.objects.filter(
                        id=request.session['id']
                    ).update(password=StandartEncryptField(
                        HashPassword(newpass), settings.AES_DEFAULT_KEY))
                    return render(
                        request, 'OK/index.html', {
                            'title': 'Отлично!',
                            'msg': 'Ваш пароль успешно изменен.',
                            'link': 'account'
                        })
        changeMailForm = forms.ChangeMail()
        extUserForm = forms.ChangeExtUserInfo()
        defaultUserInfoForm = forms.ChangeUserInfo()
        return render(
            request, 'AccountSettings/index.html', {
                'defUserInfo': defaultUserInfoForm,
                'extUserInfo': extUserForm,
                'changePass': changePassForm,
                'changeMail': changeMailForm,
                'changePassErrors': errors,
            })
    return HttpResponseRedirect('/account')
Exemple #3
0
def changeStandartUserInfo(request):
    if 'id' not in request.session:
        return HttpResponseRedirect('/account')
    if request.method == "POST":
        errors = list()
        defaultUserInfoForm = forms.ChangeUserInfo(request.POST)
        if defaultUserInfoForm.is_valid():
            userInfo = defaultUserInfoForm.save(commit=False)
            userInfo.user_id = request.session['id']

            user = DefaultUser.objects.get(id=userInfo.user_id)
            if userInfo.name != "":
                user.name = StandartEncryptField(userInfo.name,
                                                 settings.AES_DEFAULT_KEY)
            if userInfo.surname != "":
                user.surname = StandartEncryptField(userInfo.surname,
                                                    settings.AES_DEFAULT_KEY)
            if userInfo.patronymic != "":
                user.patronymic = StandartEncryptField(
                    userInfo.patronymic, settings.AES_DEFAULT_KEY)

            user.save()
            return render(
                request, 'OK/index.html', {
                    'title': 'Отлично!',
                    'msg': 'Ваши данные успешно изменены.',
                    'link': 'account'
                })
        else:
            changePassForm = forms.ChangePassword()
            changeMailForm = forms.ChangeMail()
            extUserForm = forms.ChangeExtUserInfo()
            return render(
                request, 'AccountSettings/index.html', {
                    'defUserInfo': defaultUserInfoForm,
                    'extUserInfo': extUserForm,
                    'changePass': changePassForm,
                    'changeMail': changeMailForm,
                    'extUserInfoErrors': errors,
                })
    return HttpResponseRedirect('/account')
Exemple #4
0
def settings(request):
    if 'id' not in request.session:
        return HttpResponseRedirect('/')
    id = request.session['id']

    if not DefaultUser.objects.filter(id=id).exists():
        return HttpResponseRedirect('/logout')

    user = DefaultUser.objects.get(id=id)
    user.decrypt()

    extUser = ExtUser()
    if ExtUser.objects.filter(user_id=id).exists():
        extUser = ExtUser.objects.get(user_id=id)

    defaultUserInfoForm = forms.ChangeUserInfo()
    extUserInfoForm = forms.ChangeExtUserInfo()
    changePassForm = forms.ChangePassword()
    changeMailForm = forms.ChangeMail()
    feedbackForm = forms.SendFeedback()
    return render(request, 'AccountSettings/index.html', {'defUserInfo': defaultUserInfoForm, 'extUserInfo': extUserInfoForm,
                                                          'changePass': changePassForm, 'changeMail': changeMailForm,
                                                           'user': user, 'extUser': extUser, 'feedbackForm': feedbackForm})