zoukankan      html  css  js  c++  java
  • 18-crm项目-kingadmin,完成crm用户认证登陆

    完成crm用户认证登陆

    {% extends 'base.html' %}
    
    {% block body %}
        <div class="container col-lg-offset-4 ">
          <form class="form-signin col-lg-3 pu " method="post"  role="form">{% csrf_token %}
            <h3 class="form-signin-heading">Oldboy PerfectCRM</h3>
            <input type="email"  name="email" class="form-control" placeholder="Email address" required autofocus>
            <input type="password" name="password" class="form-control" placeholder="Password" required>
            {% if errors %}
               <span style="color: red;">{{ errors.error }}</span>
            {% endif %}
            <div class="checkbox">
              <label>
                <input type="checkbox" value="remember-me"> Remember me
              </label>
            </div>
            <button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>
          </form>
    
        </div> <!-- /container -->
    
    {% endblock %}

    增加url路由

    from django.conf.urls import url,include
    from django.contrib import admin
    # admin.autodiscover()
    from PerfectCRM import views
    
    urlpatterns = [
        url(r'^admin/', admin.site.urls),
        url(r'^crm/', include("crm.urls")),
        url(r'^$', views.index),
        url(r'^account/login/$', views.acc_login),
        url(r'^account/logout/$', views.acc_logout,name="acc_logout"),
        url(r'^student/', include("student.urls")),
        url(r'^king_admin/', include("king_admin.urls")),
    ]

    增加视图:

    def acc_login(request):
    
        errors = {}
        if request.method == "POST":
            _email = request.POST.get("email")
            _password = request.POST.get("password")
    
            user = authenticate(username = _email, password = _password)
            if user:
                login(request,user)
                next_url = request.GET.get("next","/")
                return redirect(next_url)
            else:
                errors['error'] = "Wrong username or password!"
    
    
        return render(request,"login.html",{"errors":errors})

    对每一个视图进行登陆校验,使用了django自带的认证系统,

    from django.contrib.auth.decorators import login_required

    还需要一个登出

    def acc_logout(request):
    
        logout(request)
    
        return redirect("/account/login/")

    ###################################

  • 相关阅读:
    k8s 集群文件共享
    .net core 使用IOptionsXXX读取配置
    docker Dockerfile
    k8s 部署tomcatservice (NodePort通过节点向外提供服务)
    k8s 用Rinetd对外tomcatservice
    k8s 部署应用
    坑爹的matlab除法
    Cygwin/Git与Git Source Control Provider结合时初始目录
    手机电话号码从excel导入的最简单方法
    快捷方式改变电源计划,设置关闭显示器时间
  • 原文地址:https://www.cnblogs.com/andy0816/p/13794777.html
Copyright © 2011-2022 走看看