Browse Source

Доработан выход из учетной записи. Реализован пример "висячей" админки.

Alec 4 years ago
parent
commit
7ac0d90c42
7 changed files with 92 additions and 15 deletions
  1. 52 2
      assets/css/admin.css
  2. 12 8
      assets/css/style.css
  3. 8 0
      assets/js/admin.js
  4. 1 1
      assets/js/script.js
  5. 5 1
      html/admin.html
  6. 11 1
      html/index.html
  7. 3 2
      main.go

+ 52 - 2
assets/css/admin.css

@@ -1,4 +1,54 @@
 .admin {
-    background-color: rgb(212, 190, 233);
-    margin: 20px 0;
+	position: fixed;
+	bottom: 40px;
+	right: 0;
+    padding: 5px;
+    transform: translateX(100%);
+    background-color: rgba(104, 58, 148, 0.35);
+    transition: transform 400ms ease-in-out;
+    border-radius: 5px;
+    z-index: 100;
+}
+.admin > .button {
+	color: #673ab7;
+	margin: 5px;
+	border-radius: 10px;
+	padding: 2px 10px;
+}
+.admin > .button:hover {
+    background-color: #e0cfff;
+    cursor: pointer;
+}
+.admin > .switch {
+    position: absolute;
+    right: 100%;
+    width: 40px;
+    height: 40px;
+    top: 50%;
+    border-radius: 5px 0 0 5px;
+    transform: translateY(-50%);
+    background-color: rgba(104, 58, 148, 0.5);
+    cursor: pointer;
+}
+.admin > .switch::before {
+    content: "";
+    position: absolute;
+    top: 50%;
+    left: 50%;
+    width: 20px;
+    height: 20px;
+    transform: translate(-25%, -50%) rotateZ(45deg);
+    transition: transform 400ms ease-in-out;
+}
+.admin > .switch::before {
+    border-bottom: 5px solid white;
+    border-left: 5px solid white;
+}
+.admin.open > .switch::before {
+    transform: translate(-60%, -50%) rotateZ(225deg);
+    transition: transform 400ms ease-in-out;
+}
+.admin.open {
+    transform: translateX(0);
+    transition: transform 400ms ease-in-out;
 }

+ 12 - 8
assets/css/style.css

@@ -172,16 +172,20 @@ footer {
     grid-gap: 20px;
 }
 
-.catalog > .item {
-    padding: 10px;
-    color: black;
-}
-.catalog > .item:hover {
-    color: #006064;
-    background-color: #E0F7FA;
-    cursor: pointer;
+.login {
+	position: fixed;
+	top: 0;
+	right: 20%;
+	display: block;
+	padding: 20px 5px 5px 5px;
+	border-bottom-left-radius: 10px;
+	border-bottom-right-radius: 10px;
+	background-color: #2196F3;
+	color: white;
+	cursor: pointer;
 }
 
+
 p {
     margin: 10px 0;
 }

+ 8 - 0
assets/js/admin.js

@@ -0,0 +1,8 @@
+let switchPanel = document.querySelector(".admin > .switch");
+if (switchPanel) {
+    switchPanel.onclick = function () {
+        if (this.parentElement) {
+            this.parentElement.classList.toggle("open");
+        }
+    };
+}

+ 1 - 1
assets/js/script.js

@@ -6,10 +6,10 @@ for (let d of dots) {
 	d.onclick = function (event) {
 		if (isSwipe) return;
 		if (this.dataset && this.dataset.page) {
-			isSwipe = true;
 			let switchPage = document.querySelector(this.dataset.page);
 			if (switchPage) {
 				if (!this.classList.contains("active") && !switchPage.classList.contains("active")) {
+					isSwipe = true;
 					let active = document.querySelector(".page-dots > .active");
 					let activePage = document.querySelector(".page.active");
 					if (active && activePage) {

+ 5 - 1
html/admin.html

@@ -1,3 +1,7 @@
 {{define "admin"}}
-<div class="admin">Тут можно создать какую-нибудь панель администратора</div>
+<div class="admin">
+    <div class="switch"></div>
+    <div class="button">Добавить тест</div>
+    <div class="button">Посмотреть результаты</div>
+</div>
 {{end}}

+ 11 - 1
html/index.html

@@ -80,9 +80,19 @@
 
 	{{template "footer" .}}
 
+	{{if eq .IsLogin true}}
+	<a href="/logout" class="login">Выйти</a>
+	{{else}}
+	<a href="/authorization" class="login">Вход</a>
+	{{end}}
+
+	{{if eq .IsAdmin true}}
+	{{template "admin"}}
+	{{end}}
+
 	<script src="/assets/js/message.js"></script>
 	<script src="/assets/js/query.js"></script>
-	<script src="/assets/js/carousel.js"></script>
+	<!-- <script src="/assets/js/carousel.js"></script> -->
 	{{if eq .IsAdmin true}}
 	<script src="/assets/js/admin.js"></script>
 	{{end}}

+ 3 - 2
main.go

@@ -171,16 +171,17 @@ func login(c *gin.Context) {
 func logout(c *gin.Context) {
 	s := sessions.Default(c)
 
-	role, ok := s.Get("MySecretKey").(string)
+	_, ok := s.Get("MySecretKey").(string)
 	if ok {
-		s.Delete(role)
 		s.Clear()
 		s.Save()
+		c.SetCookie("session", "", -1, "/", c.Request.Host, false, true)
 	}
 
 	c.HTML(200, "index", gin.H{
 		"Title":   "Мой сайт",
 		"IsAdmin": false,
 		"IsLogin": false,
+		"Page":    "main",
 	})
 }