mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 08:48:06 +08:00
opt cookie.expire
This commit is contained in:
parent
3f19571c05
commit
ce7d698550
@ -4,5 +4,5 @@ var version = struct {
|
||||
host string
|
||||
self int
|
||||
}{
|
||||
"2019-09-22 20:28:29", "com", 635,
|
||||
"2019-09-22 22:04:56", "com", 640,
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package web
|
||||
import (
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/skip2/go-qrcode"
|
||||
"time"
|
||||
|
||||
"contexts/ctx"
|
||||
"toolkit"
|
||||
@ -39,6 +40,13 @@ type WEB struct {
|
||||
*ctx.Context
|
||||
}
|
||||
|
||||
func Cookie(msg *ctx.Message, w http.ResponseWriter, r *http.Request) {
|
||||
expire := time.Now().Add(kit.Duration(msg.Conf("login", "expire")))
|
||||
msg.Log("info", "expire %v", expire)
|
||||
http.SetCookie(w, &http.Cookie{Name: "sessid",
|
||||
Value: msg.Cmdx("aaa.user", "session", "select"), Path: "/", Expires: expire})
|
||||
return
|
||||
}
|
||||
func proxy(m *ctx.Message, url string) string {
|
||||
if strings.HasPrefix(url, "//") {
|
||||
return "proxy/https:" + url
|
||||
@ -99,8 +107,7 @@ func (web *WEB) Login(msg *ctx.Message, w http.ResponseWriter, r *http.Request)
|
||||
if msg.Options("username") && msg.Options("password") {
|
||||
if msg.Cmds("aaa.auth", "username", msg.Option("username"), "password", msg.Option("password")) {
|
||||
msg.Log("info", "login: %s", msg.Option("username"))
|
||||
http.SetCookie(w, &http.Cookie{Name: "sessid", Value: msg.Cmdx("aaa.user", "session", "select"), Path: "/"})
|
||||
if msg.Options("relay") {
|
||||
if Cookie(msg, w, r); msg.Options("relay") {
|
||||
if role := msg.Cmdx("aaa.relay", "check", msg.Option("relay"), "userrole"); role != "" {
|
||||
msg.Cmd("aaa.role", role, "user", msg.Option("username"))
|
||||
msg.Log("info", "relay: %s", role)
|
||||
@ -122,7 +129,7 @@ func (web *WEB) Login(msg *ctx.Message, w http.ResponseWriter, r *http.Request)
|
||||
if relay.Appends("username") {
|
||||
name := msg.Cmdx("ssh._route", msg.Conf("runtime", "work.route"), "_check", "work", "create", relay.Append("username"), msg.Conf("runtime", "node.route"))
|
||||
msg.Log("info", "login: %s", msg.Option("username", name))
|
||||
http.SetCookie(w, &http.Cookie{Name: "sessid", Value: msg.Option("sessid", msg.Cmdx("aaa.user", "session", "select")), Path: "/"})
|
||||
Cookie(msg, w, r)
|
||||
}
|
||||
if role := relay.Append("userrole"); role != "" {
|
||||
msg.Cmd("aaa.role", role, "user", msg.Option("username"))
|
||||
@ -151,7 +158,7 @@ func (web *WEB) Login(msg *ctx.Message, w http.ResponseWriter, r *http.Request)
|
||||
if !msg.Options("username") && kit.IsLocalIP(msg.Option("remote_ip")) && msg.Confs("web.login", "local") {
|
||||
msg.Cmd("aaa.role", "root", "user", msg.Cmdx("ssh.work", "create"))
|
||||
msg.Log("info", "%s: %s", msg.Option("remote_ip"), msg.Option("username", msg.Conf("runtime", "work.name")))
|
||||
http.SetCookie(w, &http.Cookie{Name: "sessid", Value: msg.Option("sessid", msg.Cmdx("aaa.user", "session", "select")), Path: "/"})
|
||||
Cookie(msg, w, r)
|
||||
}
|
||||
|
||||
return true
|
||||
@ -408,6 +415,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
},
|
||||
}, Help: "功能配置"},
|
||||
"login": &ctx.Config{Name: "login", Value: map[string]interface{}{
|
||||
"expire": "240h",
|
||||
"local": true,
|
||||
"check": true,
|
||||
"sess_void": false,
|
||||
|
@ -3,6 +3,7 @@ package chat
|
||||
import (
|
||||
"contexts/ctx"
|
||||
"contexts/web"
|
||||
"net/http"
|
||||
"toolkit"
|
||||
)
|
||||
|
||||
@ -27,7 +28,7 @@ func check(m *ctx.Message, arg []string) ([]string, string, bool) {
|
||||
var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
Caches: map[string]*ctx.Cache{},
|
||||
Configs: map[string]*ctx.Config{
|
||||
"login": &ctx.Config{Name: "login", Value: map[string]interface{}{"check": false, "local": true}, Help: "默认组件"},
|
||||
"login": &ctx.Config{Name: "login", Value: map[string]interface{}{"check": false, "local": true, "expire": "720h"}, Help: "默认组件"},
|
||||
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
|
||||
"index": []interface{}{
|
||||
map[string]interface{}{"name": "chat",
|
||||
@ -95,6 +96,8 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
if msg := m.Find("cli.weixin", true); msg != nil {
|
||||
msg.Cmd("js_token")
|
||||
m.Copy(msg, "append")
|
||||
m.Append("remote_ip", m.Option("remote_ip"))
|
||||
m.Append("nickname", kit.Select(m.Option("username"), m.Option("nickname")))
|
||||
m.Table()
|
||||
}
|
||||
return
|
||||
@ -113,6 +116,10 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
m.Cmd("aaa.auth", "username", arg[0], "data", "chat.default",
|
||||
m.Cmdx(".ocean", "spawn", "", m.Option("username")+"@"+m.Conf("runtime", "work.name"), m.Option("username")))
|
||||
}
|
||||
r := m.Optionv("request").(*http.Request)
|
||||
w := m.Optionv("response").(http.ResponseWriter)
|
||||
|
||||
web.Cookie(m, w, r)
|
||||
m.Echo(m.Option("sessid"))
|
||||
}
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ ctx = context = {
|
||||
location.search = arg.join("&");
|
||||
return value
|
||||
},
|
||||
Cookie: function(key, value) {
|
||||
Cookie: function(key, value, expire) {
|
||||
if (key == undefined) {
|
||||
cs = {}
|
||||
cookies = document.cookie.split("; ")
|
||||
|
@ -460,7 +460,8 @@ function Page(page) {
|
||||
|
||||
field.Pane.Login(ui.username.value, ui.password.value, function(sessid) {
|
||||
if (!sessid) {kit.alert("用户或密码错误"); return}
|
||||
ctx.Cookie("sessid", sessid), page.login.Pane.Dialog(1, 1), page.onload()
|
||||
// ctx.Cookie("sessid", sessid),
|
||||
page.login.Pane.Dialog(1, 1), page.onload()
|
||||
})
|
||||
}]}, {type: "br"},
|
||||
])
|
||||
@ -810,10 +811,19 @@ function Plugin(page, pane, field, runs) {
|
||||
}), plugin.Check()
|
||||
},
|
||||
|
||||
getLocation: function(event, target, option, field, cb) {
|
||||
page.getLocation && page.getLocation(cb || (function(res) {
|
||||
page.ontoast(JSON.stringify(res))
|
||||
}))
|
||||
getLocation: function(event) {
|
||||
var x = parseFloat(option.x.value)
|
||||
var y = parseFloat(option.y.value)
|
||||
page.getLocation && page.getLocation(function(res) {
|
||||
plugin.msg = {
|
||||
append: ["longitude", "latitude", "accuracy", "speed"],
|
||||
longitude: [res.longitude+x+""],
|
||||
latitude: [res.latitude+y+""],
|
||||
accuracy: [res.accuracy+""],
|
||||
speed: [res.speed+""],
|
||||
}
|
||||
plugin.display("table")
|
||||
})
|
||||
},
|
||||
openLocation: function(event) {
|
||||
var x = parseFloat(option.x.value)
|
||||
|
Loading…
x
Reference in New Issue
Block a user