Преглед изворни кода

增加用户数量统计表,用户登录创建user数据时统计用户数

locky пре 4 година
родитељ
комит
650d3292ce
4 измењених фајлова са 285 додато и 239 уклоњено
  1. 14 3
      controller/index.py
  2. 15 0
      model/models.py
  3. 13 11
      templates/login.html
  4. 243 225
      templates/login_anlapus.html

+ 14 - 3
controller/index.py

@@ -24,7 +24,7 @@ from urllib.parse import urlencode
 import subprocess
 import subprocess
 import uuid
 import uuid
 # from gevent.pool import Pool
 # from gevent.pool import Pool
-from model.models import UserModel,UidRtspModel,AlexaAuthModel
+from model.models import UserModel, UidRtspModel, AlexaAuthModel, UserCountModel
 from object.ResponseObject import ResponseObject
 from object.ResponseObject import ResponseObject
 from object.tkObject import tkObject
 from object.tkObject import tkObject
 from service.CommonService import CommonService
 from service.CommonService import CommonService
@@ -54,7 +54,8 @@ class authView(TemplateView):
             'client_id': client_id,
             'client_id': client_id,
             'response_type': response_type,
             'response_type': response_type,
             'scope': scope,
             'scope': scope,
-            'redirect_uri': redirect_uri
+            'redirect_uri': redirect_uri,
+            'skill_name': 'zosi smart'
         }
         }
         return render_to_response("login.html", context)
         return render_to_response("login.html", context)
 
 
@@ -82,7 +83,8 @@ class authAnlapusView(TemplateView):
             'client_id': client_id,
             'client_id': client_id,
             'response_type': response_type,
             'response_type': response_type,
             'scope': scope,
             'scope': scope,
-            'redirect_uri': redirect_uri
+            'redirect_uri': redirect_uri,
+            'skill_name': 'Anlapus'
         }
         }
         return render_to_response("login_anlapus.html", context)
         return render_to_response("login_anlapus.html", context)
 
 
@@ -107,6 +109,7 @@ class loginHandleView(TemplateView):
         response_type = request_dict.get("response_type", '')
         response_type = request_dict.get("response_type", '')
         scope = request_dict.get("scope", '')
         scope = request_dict.get("scope", '')
         redirect_uri = request_dict.get("redirect_uri", '')
         redirect_uri = request_dict.get("redirect_uri", '')
+        skill_name = request_dict.get("skill_name", '')
         # 返回code
         # 返回code
         logger = logging.getLogger('django')
         logger = logging.getLogger('django')
         logger.info('------开始认证登录------')
         logger.info('------开始认证登录------')
@@ -144,6 +147,14 @@ class loginHandleView(TemplateView):
             user_qs.update(code=code, updTime=nowTime)
             user_qs.update(code=code, updTime=nowTime)
         else:
         else:
             UserModel.objects.create(userID=userID, code=code, addTime=nowTime, updTime=nowTime)
             UserModel.objects.create(userID=userID, code=code, addTime=nowTime, updTime=nowTime)
+            year_month = str(time.strftime('%Y%m', time.localtime(nowTime)))    # 获取当前年月
+            user_count_qs = UserCountModel.objects.filter(skill_name=skill_name, year_month=year_month).values('amount')
+            if not user_count_qs.exists():
+                UserCountModel.objects.create(skill_name=skill_name, year_month=year_month, amount=1)
+            else:
+                # 用户数量+1
+                amount = user_count_qs[0]['amount'] + 1
+                user_count_qs.update(amount=amount)
 
 
         redirect_uri += '?code=' + code + '&state=' + state
         redirect_uri += '?code=' + code + '&state=' + state
         return response.json(0, res=redirect_uri)
         return response.json(0, res=redirect_uri)

+ 15 - 0
model/models.py

@@ -23,6 +23,21 @@ class UserModel(models.Model):
         return self.userID
         return self.userID
 
 
 
 
+class UserCountModel(models.Model):
+    id = models.AutoField(primary_key=True)
+    skill_name = models.CharField(max_length=32, default='', verbose_name=u'skill名称')
+    year_month = models.CharField(max_length=32, default='', verbose_name=u'统计时间/每月')
+    amount = models.IntegerField(default=0, verbose_name=u'用户数量')
+
+    class Meta:
+        ordering = ('-id',)
+        verbose_name = '用户数量统计表'
+        db_table = 'user_count'
+
+    def __str__(self):
+        return self.userID
+
+
 class UidRtspModel(models.Model):
 class UidRtspModel(models.Model):
     id = models.AutoField(primary_key=True)
     id = models.AutoField(primary_key=True)
     nick = models.CharField(max_length=32, verbose_name=u'设备昵称', default='')
     nick = models.CharField(max_length=32, verbose_name=u'设备昵称', default='')

+ 13 - 11
templates/login.html

@@ -37,7 +37,7 @@
 		border-top: solid 1px #66677C;
 		border-top: solid 1px #66677C;
 		position: relative;
 		position: relative;
 		background-color: yellow;
 		background-color: yellow;
-		
+
 	}
 	}
 	#c_leftdiv{
 	#c_leftdiv{
 		width: 50%;
 		width: 50%;
@@ -73,12 +73,12 @@
 
 
 	#c_centerdiv > p{
 	#c_centerdiv > p{
 		font-size: 20px;
 		font-size: 20px;
-		font-weight: 100px;
+		font-weight: 100;
 		margin-left: 100px;
 		margin-left: 100px;
 		margin: 10px auto;
 		margin: 10px auto;
 		text-align: center;
 		text-align: center;
 	}
 	}
-	
+
 	#c_centerdiv > img{
 	#c_centerdiv > img{
 		margin-left: 10px;
 		margin-left: 10px;
 	}
 	}
@@ -89,7 +89,7 @@
 		line-height: 30px;
 		line-height: 30px;
 		/*background-color: red;*/
 		/*background-color: red;*/
 		font-size: 40px;
 		font-size: 40px;
-		
+
 	}
 	}
 	#c_centerdiv > img{
 	#c_centerdiv > img{
 		display: block;
 		display: block;
@@ -98,7 +98,7 @@
 		top: 10px;
 		top: 10px;
 		padding: 0px;
 		padding: 0px;
 	}
 	}
-	
+
 	#c_centerdiv{
 	#c_centerdiv{
 		background-color: #fff;
 		background-color: #fff;
 		position: absolute;
 		position: absolute;
@@ -152,7 +152,7 @@
 	#c_center_div2 > img{
 	#c_center_div2 > img{
 		position: absolute;
 		position: absolute;
 		left: 0px;
 		left: 0px;
-		top: 0px;	
+		top: 0px;
 	}
 	}
 	#user_text{
 	#user_text{
 		width: 100%;
 		width: 100%;
@@ -169,7 +169,7 @@
 	    display: inline-block;
 	    display: inline-block;
 		font-family: "微软雅黑";
 		font-family: "微软雅黑";
 	}
 	}
-	
+
 	#password_text{
 	#password_text{
 		width: 100%;
 		width: 100%;
 		/*width: 80%;*/
 		/*width: 80%;*/
@@ -218,7 +218,7 @@
 		background-color:#66677C;
 		background-color:#66677C;
 
 
 	}
 	}
-	
+
 </style>
 </style>
 <body marginheight="0px" marginwidth="0px">
 <body marginheight="0px" marginwidth="0px">
 <div id="t_div">
 <div id="t_div">
@@ -247,11 +247,11 @@
 	</div>
 	</div>
 	<!--阴影部分-->
 	<!--阴影部分-->
 <!--	<div id="c_centerdiv-shadow">-->
 <!--	<div id="c_centerdiv-shadow">-->
-		
+
 	</div>
 	</div>
 </div>
 </div>
 <div id="b_div">
 <div id="b_div">
-	
+
 </div>
 </div>
 
 
 <script type="text/javascript">
 <script type="text/javascript">
@@ -262,7 +262,9 @@
             //console.log("user: " + user.value);
             //console.log("user: " + user.value);
             //console.log("pwd: " + pwd.value);
             //console.log("pwd: " + pwd.value);
 
 
-            var params = ("user=" + user.value + "&pwd=" + pwd.value + "&state={{ state }}" + "&client_id={{ client_id }}" + "&response_type={{ response_type }}" + "&scope={{ scope }}" + "&redirect_uri={{ redirect_uri }}");
+            var params = ("user=" + user.value + "&pwd=" + pwd.value + "&state={{ state }}" + "&client_id={{ client_id }}"
+                + "&response_type={{ response_type }}" + "&scope={{ scope }}" + "&redirect_uri={{ redirect_uri }}"
+                + "&skill_name={{ skill_name }}");
             $.get("/oa2/login", params, function (reUrl) {
             $.get("/oa2/login", params, function (reUrl) {
                 //alert(reUrl);
                 //alert(reUrl);
                 let data = JSON.parse(reUrl)
                 let data = JSON.parse(reUrl)

+ 243 - 225
templates/login_anlapus.html

@@ -9,114 +9,123 @@
     <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
     <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
 </head>
 </head>
 <style type="text/css">
 <style type="text/css">
-	html,body{
-		width: 100%;
-		height: 100%;
-		margin: 0px;
-	}
-	*{
-		margin: 0px;
-		padding: 0px;
-		box-sizing: border-box;
-	}
-	#t_div{
-		width: 100%;
-		/*height: 200px;*/
-		height: 25%;
-		background-color:#66677C;
-		margin-top: 0px;
-		margin-bottom: -20px;
-		/*border-bottom: solid 1px red;*/
-	}
-	#c_div{
-		width: 100%;
-		/*height: 430px ;*/
-		height: 50%;
-		margin-top: 0px;
-		margin-bottom: 0px;
-		border-top: solid 1px #66677C;
-		position: relative;
-		background-color: yellow;
-		
-	}
-	#c_leftdiv{
-		width: 50%;
-		/*height: 430px;*/
-		height: 100%;
-		margin: 0px;
-		background-color: #7ab6b6;
-		float: left;
-		/*position: relative;*/
-		/*left: 50px;
-		top: 100px;*/
-	}
-	#c_rightdiv{
-		width: 50%;
-		/*height: 430px;*/
-		height: 100%;
-		margin: 0px;
-		background-color: #e5cfaa;
-		float: left;
-	}
-	/*阴影部分*/
-	/*#c_centerdiv-shadow{
-		width: 350px;
-		height: 390px;
-		background-color: #a09177;
-		position: absolute;
-		left: 0;
-		right: 0;
-		margin-left: 37.3%;
-		margin-top: 3.5%;
-		z-index: 1;
-	}*/
-
-	#c_centerdiv > p{
-		font-size: 20px;
-		font-weight: 100px;
-		margin-left: 100px;
-		margin: 10px auto;
-		text-align: center;
-	}
-	
-	#c_centerdiv > img{
-		margin-left: 10px;
-	}
-
-	#password_text{
-		width: 90%;
-		height: 50px;
-		line-height: 30px;
-		/*background-color: red;*/
-		font-size: 40px;
-		
-	}
-	#c_centerdiv > img{
-		display: block;
-		position: relative;
-		left: 0px;
-		top: 10px;
-		padding: 0px;
-	}
-	
-	#c_centerdiv{
-		background-color: #fff;
-		position: absolute;
-		left: 0;
-		right: 0;
-		margin-left: auto;
-		margin-right: auto;
-		top: 50%;
-		margin-top: -193px;
-		/*margin-top: -15.1%;*/
-		z-index: 10;
-	}
-	#c_centerdiv{
-		width: 350px;
-		height: 390px;
-		padding: 50px 30px;
-	}
-    #c_center_title{
+    html, body {
+        width: 100%;
+        height: 100%;
+        margin: 0px;
+    }
+
+    * {
+        margin: 0px;
+        padding: 0px;
+        box-sizing: border-box;
+    }
+
+    #t_div {
+        width: 100%;
+        /*height: 200px;*/
+        height: 25%;
+        background-color: #66677C;
+        margin-top: 0px;
+        margin-bottom: -20px;
+        /*border-bottom: solid 1px red;*/
+    }
+
+    #c_div {
+        width: 100%;
+        /*height: 430px ;*/
+        height: 50%;
+        margin-top: 0px;
+        margin-bottom: 0px;
+        border-top: solid 1px #66677C;
+        position: relative;
+        background-color: yellow;
+
+    }
+
+    #c_leftdiv {
+        width: 50%;
+        /*height: 430px;*/
+        height: 100%;
+        margin: 0px;
+        background-color: #7ab6b6;
+        float: left;
+        /*position: relative;*/
+        /*left: 50px;
+        top: 100px;*/
+    }
+
+    #c_rightdiv {
+        width: 50%;
+        /*height: 430px;*/
+        height: 100%;
+        margin: 0px;
+        background-color: #e5cfaa;
+        float: left;
+    }
+
+    /*阴影部分*/
+    /*#c_centerdiv-shadow{
+        width: 350px;
+        height: 390px;
+        background-color: #a09177;
+        position: absolute;
+        left: 0;
+        right: 0;
+        margin-left: 37.3%;
+        margin-top: 3.5%;
+        z-index: 1;
+    }*/
+
+    #c_centerdiv > p {
+        font-size: 20px;
+        font-weight: 100;
+        margin-left: 100px;
+        margin: 10px auto;
+        text-align: center;
+    }
+
+    #c_centerdiv > img {
+        margin-left: 10px;
+    }
+
+    #password_text {
+        width: 90%;
+        height: 50px;
+        line-height: 30px;
+        /*background-color: red;*/
+        font-size: 40px;
+
+    }
+
+    #c_centerdiv > img {
+        display: block;
+        position: relative;
+        left: 0px;
+        top: 10px;
+        padding: 0px;
+    }
+
+    #c_centerdiv {
+        background-color: #fff;
+        position: absolute;
+        left: 0;
+        right: 0;
+        margin-left: auto;
+        margin-right: auto;
+        top: 50%;
+        margin-top: -193px;
+        /*margin-top: -15.1%;*/
+        z-index: 10;
+    }
+
+    #c_centerdiv {
+        width: 350px;
+        height: 390px;
+        padding: 50px 30px;
+    }
+
+    #c_center_title {
         width: 100%;
         width: 100%;
         height: 19%;
         height: 19%;
         /*height: 55px;*/
         /*height: 55px;*/
@@ -127,131 +136,138 @@
         text-align: center;
         text-align: center;
         /*background-color: red;*/
         /*background-color: red;*/
     }
     }
-	#c_center_div1{
-		width: 100%;
-		height: 19%;
-		/*height: 55px;*/
-	    color: #555;
-	    font-size: 10px;
-	    font-weight: 600;
-	    font-family: 'Arimo', sans-serif;
-		text-align: center;
-	    /*background-color: red;*/
-	}
-	#c_center_div2{
-		width: 100%;
-		height: 13.8%;
-		text-align: center;
-	    padding: 0px;
-	    position: relative;
-	    /*background-color: yellow;*/
-	    margin-top: 0px;
-	    margin-top: 30px;
-	}
-	/*图片*/
-	#c_center_div2 > img{
-		position: absolute;
-		left: 0px;
-		top: 0px;	
-	}
-	#user_text{
-		width: 100%;
-		/*width: 80%;*/
-		height: 40px;
-		float: right;
-		background-color: #fff;
-	    font-size: 17px;
-	    letter-spacing: 1px;
-	    box-shadow: 0 0 0 0 transparent;
-	    border: none;
-	    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
-	    border-radius: 0;
-	    display: inline-block;
-		font-family: "微软雅黑";
-	}
-	
-	#password_text{
-		width: 100%;
-		/*width: 80%;*/
-		height: 40px;
-		float: right;
-		background-color: #fff;
-	    font-size: 17px;
-	    letter-spacing: 1px;
-	    box-shadow: 0 0 0 0 transparent;
-	    border: none;
-	    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
-	    border-radius: 0;
-	    display: inline-block;
-		font-family: "微软雅黑";
-	}
-	#c_center_div4{
-		width: 100%;
-		height: 16%;
-		text-align: center;
-	    padding: 0px;
-	    position: relative;
-/*	    background-color: yellow;*/
-	    margin-top: 0px;
-	    margin-top: 30px;
-	}
-	#login_button{
-		width: 50.7%;
-		height: 100%;
-		/*background-image: url(img/按钮初始界面.png);*/
-		outline:none;
-		border:none;
-		background-color: #7ab6b6;
-		border-radius:30px;
-		font-size: large;
-		color: white;
-		font-family: Arial;
-	}
-	#login_button:hover{
-		cursor: pointer;
-	}
-
-	#b_div{
-		width: 100%;
-		/*height: 120px;*/
-		height: 27.2%;
-		background-color:#66677C;
-
-	}
-	
+
+    #c_center_div1 {
+        width: 100%;
+        height: 19%;
+        /*height: 55px;*/
+        color: #555;
+        font-size: 10px;
+        font-weight: 600;
+        font-family: 'Arimo', sans-serif;
+        text-align: center;
+        /*background-color: red;*/
+    }
+
+    #c_center_div2 {
+        width: 100%;
+        height: 13.8%;
+        text-align: center;
+        padding: 0px;
+        position: relative;
+        /*background-color: yellow;*/
+        margin-top: 0px;
+        margin-top: 30px;
+    }
+
+    /*图片*/
+    #c_center_div2 > img {
+        position: absolute;
+        left: 0px;
+        top: 0px;
+    }
+
+    #user_text {
+        width: 100%;
+        /*width: 80%;*/
+        height: 40px;
+        float: right;
+        background-color: #fff;
+        font-size: 17px;
+        letter-spacing: 1px;
+        box-shadow: 0 0 0 0 transparent;
+        border: none;
+        border-bottom: 1px solid rgba(0, 0, 0, 0.1);
+        border-radius: 0;
+        display: inline-block;
+        font-family: "微软雅黑";
+    }
+
+    #password_text {
+        width: 100%;
+        /*width: 80%;*/
+        height: 40px;
+        float: right;
+        background-color: #fff;
+        font-size: 17px;
+        letter-spacing: 1px;
+        box-shadow: 0 0 0 0 transparent;
+        border: none;
+        border-bottom: 1px solid rgba(0, 0, 0, 0.1);
+        border-radius: 0;
+        display: inline-block;
+        font-family: "微软雅黑";
+    }
+
+    #c_center_div4 {
+        width: 100%;
+        height: 16%;
+        text-align: center;
+        padding: 0px;
+        position: relative;
+        /*	    background-color: yellow;*/
+        margin-top: 0px;
+        margin-top: 30px;
+    }
+
+    #login_button {
+        width: 50.7%;
+        height: 100%;
+        /*background-image: url(img/按钮初始界面.png);*/
+        outline: none;
+        border: none;
+        background-color: #7ab6b6;
+        border-radius: 30px;
+        font-size: large;
+        color: white;
+        font-family: Arial;
+    }
+
+    #login_button:hover {
+        cursor: pointer;
+    }
+
+    #b_div {
+        width: 100%;
+        /*height: 120px;*/
+        height: 27.2%;
+        background-color: #66677C;
+
+    }
+
 </style>
 </style>
 <body marginheight="0px" marginwidth="0px">
 <body marginheight="0px" marginwidth="0px">
 <div id="t_div">
 <div id="t_div">
 </div>
 </div>
 <div id="c_div">
 <div id="c_div">
-	<div id="c_leftdiv"></div>
-	<div id="c_rightdiv"></div>
-	<div id="c_centerdiv">
+    <div id="c_leftdiv"></div>
+    <div id="c_rightdiv"></div>
+    <div id="c_centerdiv">
         <div id="c_center_title">
         <div id="c_center_title">
             ANLAPUS
             ANLAPUS
         </div>
         </div>
-		<div id="c_center_div1">
+        <div id="c_center_div1">
             Please enter your Anlapus account for association
             Please enter your Anlapus account for association
-		</div>
-		<div id="c_center_div2">
-			<!--<img src="img/用户.png"/>-->
-			<input id="user_text" type="text" placeholder="Account"/>
-		</div>
-		<div id="c_center_div2">
-			<!--<img src="img/密码.png"/>-->
-			<input id="password_text" type="password" placeholder="Password"/>
-		</div>
-		<div id="c_center_div4">
-			<input type="button" id="login_button" value="LOGIN" onclick="Login();return false;"/>
-		</div>
-	</div>
-	<!--阴影部分-->
-<!--	<div id="c_centerdiv-shadow">-->
-		
-	</div>
+        </div>
+        <div id="c_center_div2">
+            <!--<img src="img/用户.png"/>-->
+            <input id="user_text" type="text" placeholder="Account"/>
+        </div>
+        <div id="c_center_div2">
+            <!--<img src="img/密码.png"/>-->
+            <input id="password_text" type="password" placeholder="Password"/>
+        </div>
+        <div id="c_center_div4">
+            <input type="button" id="login_button" value="LOGIN" onclick="Login();return false;"/>
+        </div>
+    </div>
+    <!--阴影部分-->
+    <!--	<div id="c_centerdiv-shadow">-->
+
+</div>
 </div>
 </div>
 <div id="b_div">
 <div id="b_div">
-	
+
 </div>
 </div>
 
 
 <script type="text/javascript">
 <script type="text/javascript">
@@ -262,14 +278,16 @@
             //console.log("user: " + user.value);
             //console.log("user: " + user.value);
             //console.log("pwd: " + pwd.value);
             //console.log("pwd: " + pwd.value);
 
 
-            var params = ("user=" + user.value + "&pwd=" + pwd.value + "&state={{ state }}" + "&client_id={{ client_id }}" + "&response_type={{ response_type }}" + "&scope={{ scope }}" + "&redirect_uri={{ redirect_uri }}");
+            var params = ("user=" + user.value + "&pwd=" + pwd.value + "&state={{ state }}" + "&client_id={{ client_id }}"
+                + "&response_type={{ response_type }}" + "&scope={{ scope }}" + "&redirect_uri={{ redirect_uri }}
+                + "&skill_name={{ skill_name }}");
             $.get("/oa2/login", params, function (reUrl) {
             $.get("/oa2/login", params, function (reUrl) {
                 //alert(reUrl);
                 //alert(reUrl);
                 let data = JSON.parse(reUrl)
                 let data = JSON.parse(reUrl)
-                if(data['code']===0){
+                if (data['code'] === 0) {
                     console.log('request start')
                     console.log('request start')
                     window.location = data['res'];
                     window.location = data['res'];
-                }else{
+                } else {
                     alert(data['msg'])
                     alert(data['msg'])
                 }
                 }