Exemple #1
0
def login(request):
    if request.method == 'POST':
        login_form = forms.UserForm(request.POST)
        message = '请检查填写内容!'
        if login_form.is_valid():
            username = login_form.cleaned_data['username']
            password = login_form.cleaned_data['password']
            try:
                user = models.User.objects.get(name=username)
                if user.password == password:
                    return redirect('login:index')
                else:
                    message = '密码不正确!'
            except:
                message = '用户不存在!'
        return render(request, 'login/login.html', locals())
    return render(request, 'login/login.html', locals())
def register(request):
    #登录状态不允许注册
    if request.session.get('is_login', None):
        return redirect('/index/')
    if request.method == 'POST':
        register_form = forms.RegisterForm(request.POST)
        message = "所有内容均需填写!"
        if register_form.is_valid():
            username = register_form.cleaned_data['username']
            password1 = register_form.cleaned_data['password1']
            password2 = register_form.cleaned_data['password2']
            email = register_form.cleaned_data['email']
            try:
                same_name = models.User.objects.get(username=username)
            except:
                same_name = False
            try:
                same_email = models.User.objects.get(email_address=email)
            except:
                same_email = False
            if same_name:
                message = "用户名已存在"
                return render(request, 'login/register.html', locals())
            if same_email:
                message = '该邮箱已注册'
                return render(request, 'login/register.html', locals())
            if password1 != password2:
                message = "密码不一致"
                return render(request, 'login/register.html', locals())
            # 一切正常的情况下
            new_user = models.User()
            new_user.username = username
            new_user.password = password1
            new_user.email_address = email
            new_user.save()

            code = make_confirm_string(new_user)
            send_email(email, code)

            message = "注册成功,现在您可以登陆了"
            login_form = forms.UserForm()
            return render(request, "login/login.html", locals())
    register_form = forms.RegisterForm()
    return render(request, 'login/register.html', locals())
Exemple #3
0
def login(request):
    if request.session.get('is_login', None):
        return redirect("/index/")
    if request.method == "POST":
        login_form = forms.UserForm(request.POST)
        message = "请检查填写的内容!"
        if login_form.is_valid():
            username = login_form.cleaned_data['username']
            password = login_form.cleaned_data['password']
            try:
                user = models.User.objects.get(name=username)
                if user.password == hash_code(password):
                    request.session['is_login'] = True
                    request.session['user_id'] = user.id
                    request.session['user_name'] = user.name
                    return redirect('/index/')
                else:
                    message = "密码不正确!"
            except:
                message = "用户不存在!"
    return render(request, 'login/login.html', locals())
Exemple #4
0
def load_unittest_page(request):
    if request.session.get('is_login', None) is None:
        login_form = forms.UserForm()
        return render(request, 'login/login.html', locals())
    return render(request, 'sonarqube/echarts_unittest.html')
Exemple #5
0
def agregarAsesor(request):
        if request.user.persona.idRol.idRole == 3:
            if request.method == 'POST':
                usuario = fLogin.UserForm(request.POST)
                persona = fInfo.PersonaForm(request.POST)
                if usuario.is_valid():
                    user = usuario.save()
                    rol = mLogin.Roles.objects.get(idRole=2)
                    fecha = request.POST.get("fechaDeNacimiento",None)
                    estadoCivil = request.POST.get("estadoCivil",None)
                    direccion = request.POST.get("idtipodireccion",None)
                    persona = mLogin.Persona.objects.get(user_id=user)
                    if estadoCivil == "":
                        estado = mLogin.EstadoCivil.objects.get(idEstadoCivil="1")
                    else:
                        estado = mLogin.EstadoCivil.objects.get(idEstadoCivil=estadoCivil)
                    if direccion == "":
                        tipodireccion = mLogin.CatTipodireccion.objects.get(idtipoDireccion="1")
                    else:
                        tipodireccion = mLogin.CatTipodireccion.objects.get(idtipoDireccion=direccion)
                    if request.POST.get("clienteProspecto",None) == "on":
                        prospecto = True
                    else:
                        prospecto = False
                    mLogin.Persona.objects.filter(user_id=user).update(
                        estadoCivil = estado,
                        fechaDeNacimiento = fecha,
                        idRol = rol,
                        curp = request.POST.get("curp",None),
                        rfc = request.POST.get("rfc",None),
                    )
                    direccion = mLogin.Direccion(
                        idpersona = persona,
                        idtipodireccion = tipodireccion,
                        calle = request.POST.get("calle",None),
                        colonia = request.POST.get("colonia",None),
                        delegacion = request.POST.get("delegacion",None),
                        cp = request.POST.get("cp",None),
                        numinterior = request.POST.get("numinterior",None),
                        numexterior = request.POST.get("numexterior",None),
                    )
                    contacto = mLogin.Contacto(
                        idpersona = persona,
                        celular = request.POST.get("celular",None),
                        telcasa = request.POST.get("telcasa",None),
                        oficina = request.POST.get("oficina",None),
                        facebookid = request.POST.get("facebookid",None),
                    )
                    clientec.save()
                    contacto.save()
                    direccion.save()
                    return redirect('asesor:gestionarAsesor')
                else:
                    return redirect('asesor:agregarAsesor')
            usuario = fLogin.UserForm()
            institucion = f.promotorAsesorForm()
            persona = fInfo.PersonaForm()
            direccion = fInfo.DireccionForm()
            contacto = fInfo.ContactoForm()
            context = {
                "institucion":institucion,
                "usuario":usuario,
                "persona":persona,
                "contacto":contacto,
                "direccion":direccion,
            }
            return render(request,"asesor/asesor_add.html",context)
        else:
            return render(request,'error/404.html')
Exemple #6
0
def agregarCliente(request):
    if request.user.persona.idRol.idRole == 2 or request.user.persona.idRol.idRole == 3:
        if request.method == 'POST':
            usuario = fLogin.UserForm(request.POST)
            persona = f.PersonaForm(request.POST)
            cliente = f.ClienteForm(request.POST)
            print(usuario.is_valid())
            print(request.POST)
            if usuario.is_valid() and persona.is_valid() and cliente.is_valid(
            ):
                user = usuario.save()
                rol = mLogin.Roles.objects.get(idRole=1)
                origin = request.POST.get("Origen", None)
                status = request.POST.get("Estatus", None)
                fecha = request.POST.get("fechaDeNacimiento", None)
                estadoCivil = request.POST.get("estadoCivil", None)
                direccion = request.POST.get("idtipodireccion", None)
                persona = mLogin.Persona.objects.get(user_id=user)
                if estadoCivil == "":
                    estado = mLogin.EstadoCivil.objects.get(idEstadoCivil="1")
                else:
                    estado = mLogin.EstadoCivil.objects.get(
                        idEstadoCivil=estadoCivil)
                if direccion == "":
                    tipodireccion = mLogin.CatTipodireccion.objects.get(
                        idtipoDireccion="1")
                else:
                    tipodireccion = mLogin.CatTipodireccion.objects.get(
                        idtipoDireccion=direccion)
                if origin == "":
                    origenCliente = mcliente.OrigenRecomendacion.objects.get(
                        idOrigen="1")
                else:
                    origenCliente = mcliente.OrigenRecomendacion.objects.get(
                        idOrigen=origin)
                if status == "":
                    estatusCliente = mcliente.Estatus.objects.get(
                        idEstatus="1")
                else:
                    estatusCliente = mcliente.Estatus.objects.get(
                        idEstatus=status)

                if request.POST.get("clienteProspecto", None) == "on":
                    prospecto = True
                else:
                    prospecto = False
                mLogin.Persona.objects.filter(user_id=user).update(
                    estadoCivil=estado,
                    fechaDeNacimiento=fecha,
                    idRol=rol,
                    curp=request.POST.get("curp", None),
                    rfc=request.POST.get("rfc", None),
                )
                clientec = m.AsesorCliente(
                    idCliente=persona,
                    idAsesor=get_user(request),
                    clienteProspecto=prospecto,
                    Origen=origenCliente,
                    Estatus=estatusCliente,
                    fechaActualizacion=date.today(),
                    activo=True,
                )
                direccion = mLogin.Direccion(
                    idpersona=persona,
                    idtipodireccion=tipodireccion,
                    calle=request.POST.get("calle", None),
                    colonia=request.POST.get("colonia", None),
                    delegacion=request.POST.get("delegacion", None),
                    cp=request.POST.get("cp", None),
                    numinterior=request.POST.get("numinterior", None),
                    numexterior=request.POST.get("numexterior", None),
                )
                contacto = mLogin.Contacto(
                    idpersona=persona,
                    celular=request.POST.get("celular", None),
                    telcasa=request.POST.get("telcasa", None),
                    oficina=request.POST.get("oficina", None),
                    facebookid=request.POST.get("facebookid", None),
                )
                clientec.save()
                contacto.save()
                direccion.save()
                return redirect('cliente:agregarCliente')
            else:
                return redirect('cliente:agregarCliente')
        usuario = fLogin.UserForm()
        persona = f.PersonaForm()
        cliente = f.ClienteForm()
        direccion = f.DireccionForm()
        contacto = f.ContactoForm()
        context = {
            "usuario": usuario,
            "persona": persona,
            "cliente": cliente,
            "contacto": contacto,
            "direccion": direccion,
        }
        return render(request, "cliente/cliente_add.html", context)
    else:
        return render(request, 'error/404.html')
Exemple #7
0
def login(request):
    #判断有没有cookies
    judeg_cookies(request)
    if request.session.get('is_login', None):
        return redirect("/")
    if request.method == "POST":
        login_form = forms.UserForm(request.POST)
        message = "所有字段都必须填写正确哦~"
        if login_form.is_valid():
            username = login_form.cleaned_data['username']
            password = login_form.cleaned_data['password']
            try:
                # 判断是否是邮箱或者用户名
                user = models.User.objects.get(
                    Q(name=username) | Q(email=username))
                #判断是否通过邮件确认
                if not user.has_confirmed:
                    message = "您还未通过邮件确认注册"
                    hashkey = CaptchaStore.generate_key()
                    image_url = captcha_image_url(hashkey)
                    return render(request, 'login/login.html', locals())
                #哈希值和数据库值对比
                if user.password == hash_code(password):
                    #设置session
                    request.session['is_login'] = True
                    request.session['user_id'] = user.id
                    request.session['user_name'] = user.name
                    #读取session
                    url = request.session['url']
                    #如果勾选了记住密码
                    if request.POST.get('chocookies', None):
                        #传递cookies
                        try:
                            obj_cookies = redirect(url, locals())
                            #保存用户和哈希值密码3天
                            #保存为json
                            save_username = json.dumps(user.name)

                            obj_cookies.set_cookie('username',
                                                   save_username,
                                                   max_age=3 * 24 * 60 * 60)
                            obj_cookies.set_cookie('password',
                                                   user.password,
                                                   max_age=3 * 24 * 60 * 60)

                            return obj_cookies
                        except Exception as e:
                            print('保存cookies失败:', e)
                    #如果不存cookies
                    else:
                        #跳转到get进入登录页面前的一个页面
                        return redirect(url)
                else:
                    message = "密码不正确哦"
            except:
                message = "用户名或邮箱不存在~"
        hashkey = CaptchaStore.generate_key()
        image_url = captcha_image_url(hashkey)
        return render(request, "login/login.html", locals())
    #如果是get请求
    else:
        #如果是判断邮箱验证的网址跳转的,就不记录了,跳到首页
        if 'confirm' in request.META.get('HTTP_REFERER', '/'):
            request.session['url'] = '/'
        else:
            #无论登录成功与否,都保存请求源进session
            request.session['url'] = request.META.get('HTTP_REFERER', '/')

        login_form = forms.UserForm()
        hashkey = CaptchaStore.generate_key()
        image_url = captcha_image_url(hashkey)
        return render(request, 'login/login.html', locals())
Exemple #8
0
def load_department_page(request):
    if request.session.get('is_login', None) is None:
        login_form = forms.UserForm()
        return render(request, 'login/login.html', locals())
    return render(request, 'zentao/echarts_department.html')
Exemple #9
0
def load_personal_page(request):
    if request.session.get('is_login') is None:
        login_form = forms.UserForm()
        return render(request, 'login/login.html', locals())
    return render(request, 'zentao/echarts_personal.html')