Commit f87c8290 by lichenggang

version v1.0.2

- 加入用户验证
- 优化前端
parent 67ac824a
......@@ -10,17 +10,51 @@ import (
"time"
)
func GetApp(directory string, port int) *iris.Application {
type User struct {
Username string
Password string
}
func GetApp(directory string) *iris.Application {
app := iris.New()
w := &WebHandler{"E:\\test_logs"}
app.Get("/index", w.Indexhandle2)
w := &WebHandler{directory}
app.Get("/", func(ctx iris.Context) {
w.loginhandle(ctx, nil)
})
app.Post("/login", func(ctx iris.Context) {
var user User
ctx.ReadForm(&user)
//user.Username = "zzl"
//user.Password = "Lx@520m!@@#"
if ok2, msg := VerifyUser(user.Username, user.Password); ok2 {
ctx.SetCookieKV("sessionid", msg)
ctx.Redirect("/index", 301)
} else {
fmt.Println("验证不通过")
w.loginhandle(ctx, msg)
}
})
app.Use(func(ctx iris.Context) {
sessionid := ctx.GetCookie("sessionid")
ok1, msg := VerifySessionID(sessionid)
fmt.Println(msg)
if ok1 {
ctx.Next()
} else {
w.loginhandle(ctx, "未登录")
}
})
app.Get("/index", w.Indexhandle2)
app.Get("/ws", genCtxHand(directory, manager.filemap))
go manager.start()
return app
}
func genCtxHand(directory string, file_map map[string]map[Client]bool) func(ctx iris.Context) {
f := func(ctx iris.Context) {
w := ctx.ResponseWriter()
......
......@@ -11,11 +11,7 @@ var userMap = make(map[string]string)
var sessionIdMap = make(map[string]string)
func init() {
userMap["zzl"] = "THhANTIwbSFAQCM="
userMap["lcg"] = "THhANTIwbSFAQCM="
userMap["zgj"] = "THhANTIwbSFAQCM="
userMap["ljm"] = "THhANTIwbSFAQCM="
userMap["opt"] = "THhANTIwbSFAQCM="
userMap["weblog"] = "MTIzNDU2"
sessionIdMap["S1oI0nPch9PzJ0ClGEODdzbqcq85JK7YwnLesuTWayU="] = ""
}
......
......@@ -64,6 +64,9 @@ func (wbh *WebHandler) indexhandle(w http.ResponseWriter, r *http.Request) {
}
func (wbh *WebHandler) loginhandle(ctx iris.Context, data interface{}) {
return_res(ctx.ResponseWriter(), "web/views/login.html", data)
}
func (wbh *WebHandler) Indexhandle2(ctx iris.Context) {
innerip := ctx.URLParam("innerip")
server_direc := ctx.URLParam("server_direc")
......
......@@ -9,7 +9,7 @@ import (
// example
func main() {
Directory := "E:\\test_logs" // directory of the log
TestPort := 9997
addrs := "0.0.0.0:9997"
logenv := os.Getenv("GOLOGENV")
if logenv == "TEST" {
Directory = "/data/soft/bigdatav3.0/test_rsync_log"
......@@ -17,7 +17,7 @@ func main() {
if logenv == "PRODUCT" {
Directory = "/data/soft/rsync_log"
}
app := code.GetApp(Directory, TestPort)
app.Run(iris.Addr("0.0.0.0:9997"), iris.WithCharset("UTF-8"))
app := code.GetApp(Directory)
app.Run(iris.Addr(addrs), iris.WithCharset("UTF-8"))
}
......@@ -20,6 +20,18 @@
</script>
<style>
html{
width: 100%;
height: 100%;
overflow: hidden;
}
body{
width: 100%;
height: 100%;
font-family: 'Open Sans',sans-serif;
margin: 0;
background-color: #cccccc;
}
a:active,
a:visited,
a:link {
......
......@@ -19,6 +19,18 @@
</script>
<style>
html{
width: 100%;
height: 100%;
overflow: hidden;
}
body{
width: 100%;
height: 100%;
font-family: 'Open Sans',sans-serif;
margin: 0;
background-color: #cccccc;
}
a:active,
a:visited,
a:link {
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
<style>
html{
width: 100%;
height: 100%;
overflow: hidden;
}
body{
width: 100%;
height: 100%;
font-family: 'Open Sans',sans-serif;
margin: 0;
background-color: #181818;
}
#login{
position: absolute;
top: 50%;
left:50%;
margin: -150px 0 0 -150px;
width: 300px;
height: 300px;
}
#login h1{
color: #fff;
text-shadow:0 0 10px;
letter-spacing: 1px;
text-align: center;
}
h1{
font-size: 2em;
margin: 0.67em 0;
}
input{
width: 278px;
height: 18px;
margin-bottom: 10px;
outline: none;
padding: 10px;
font-size: 13px;
color: #fff;
text-shadow:1px 1px 1px;
border-top: 1px solid #312E3D;
border-left: 1px solid #312E3D;
border-right: 1px solid #312E3D;
border-bottom: 1px solid #56536A;
border-radius: 4px;
background-color: #2D2D3F;
}
.but{
width: 300px;
min-height: 20px;
display: block;
background-color: #4a77d4;
border: 1px solid #3762bc;
color: #fff;
padding: 9px 14px;
font-size: 15px;
line-height: normal;
border-radius: 5px;
margin: 0;
}
</style>
<div id="login">
<h1>Login</h1>
<form method="post", action="login">
<input type="text" required="required" placeholder="用户名" name="username">
<input type="password" required="required" placeholder="密码" name="password">
<h5 style="color: red">{{ . }}</h5>
<button class="but" type="submit">登录</button>
</form>
</div>
</body>
</html>
\ No newline at end of file
......@@ -53,7 +53,7 @@
function reConnect() {
setTimeout(function () {
connect();
}, 1000);
}, 10000);
}
connect()
......
......@@ -19,6 +19,18 @@
</script>
<style>
html{
width: 100%;
height: 100%;
overflow: hidden;
}
body{
width: 100%;
height: 100%;
font-family: 'Open Sans',sans-serif;
margin: 0;
background-color: #cccccc;
}
a:active,
a:visited,
a:link {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment