1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00

opt cookie.expire

This commit is contained in:
shylinux 2019-09-22 22:33:04 +08:00
parent 3f19571c05
commit ce7d698550
5 changed files with 37 additions and 12 deletions

View File

@ -4,5 +4,5 @@ var version = struct {
host string host string
self int self int
}{ }{
"2019-09-22 20:28:29", "com", 635, "2019-09-22 22:04:56", "com", 640,
} }

View File

@ -3,6 +3,7 @@ package web
import ( import (
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/skip2/go-qrcode" "github.com/skip2/go-qrcode"
"time"
"contexts/ctx" "contexts/ctx"
"toolkit" "toolkit"
@ -39,6 +40,13 @@ type WEB struct {
*ctx.Context *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 { func proxy(m *ctx.Message, url string) string {
if strings.HasPrefix(url, "//") { if strings.HasPrefix(url, "//") {
return "proxy/https:" + 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.Options("username") && msg.Options("password") {
if msg.Cmds("aaa.auth", "username", msg.Option("username"), "password", msg.Option("password")) { if msg.Cmds("aaa.auth", "username", msg.Option("username"), "password", msg.Option("password")) {
msg.Log("info", "login: %s", msg.Option("username")) msg.Log("info", "login: %s", msg.Option("username"))
http.SetCookie(w, &http.Cookie{Name: "sessid", Value: msg.Cmdx("aaa.user", "session", "select"), Path: "/"}) if Cookie(msg, w, r); msg.Options("relay") {
if msg.Options("relay") {
if role := msg.Cmdx("aaa.relay", "check", msg.Option("relay"), "userrole"); role != "" { if role := msg.Cmdx("aaa.relay", "check", msg.Option("relay"), "userrole"); role != "" {
msg.Cmd("aaa.role", role, "user", msg.Option("username")) msg.Cmd("aaa.role", role, "user", msg.Option("username"))
msg.Log("info", "relay: %s", role) 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") { 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")) 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)) 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 != "" { if role := relay.Append("userrole"); role != "" {
msg.Cmd("aaa.role", role, "user", msg.Option("username")) 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") { 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.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"))) 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 return true
@ -408,6 +415,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
}, },
}, Help: "功能配置"}, }, Help: "功能配置"},
"login": &ctx.Config{Name: "login", Value: map[string]interface{}{ "login": &ctx.Config{Name: "login", Value: map[string]interface{}{
"expire": "240h",
"local": true, "local": true,
"check": true, "check": true,
"sess_void": false, "sess_void": false,

View File

@ -3,6 +3,7 @@ package chat
import ( import (
"contexts/ctx" "contexts/ctx"
"contexts/web" "contexts/web"
"net/http"
"toolkit" "toolkit"
) )
@ -27,7 +28,7 @@ func check(m *ctx.Message, arg []string) ([]string, string, bool) {
var Index = &ctx.Context{Name: "chat", Help: "会议中心", var Index = &ctx.Context{Name: "chat", Help: "会议中心",
Caches: map[string]*ctx.Cache{}, Caches: map[string]*ctx.Cache{},
Configs: map[string]*ctx.Config{ 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{}{ "componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
"index": []interface{}{ "index": []interface{}{
map[string]interface{}{"name": "chat", 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 { if msg := m.Find("cli.weixin", true); msg != nil {
msg.Cmd("js_token") msg.Cmd("js_token")
m.Copy(msg, "append") 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() m.Table()
} }
return return
@ -113,6 +116,10 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
m.Cmd("aaa.auth", "username", arg[0], "data", "chat.default", 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"))) 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")) m.Echo(m.Option("sessid"))
} }
} }

View File

@ -138,7 +138,7 @@ ctx = context = {
location.search = arg.join("&"); location.search = arg.join("&");
return value return value
}, },
Cookie: function(key, value) { Cookie: function(key, value, expire) {
if (key == undefined) { if (key == undefined) {
cs = {} cs = {}
cookies = document.cookie.split("; ") cookies = document.cookie.split("; ")

View File

@ -460,7 +460,8 @@ function Page(page) {
field.Pane.Login(ui.username.value, ui.password.value, function(sessid) { field.Pane.Login(ui.username.value, ui.password.value, function(sessid) {
if (!sessid) {kit.alert("用户或密码错误"); return} 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"}, }]}, {type: "br"},
]) ])
@ -810,10 +811,19 @@ function Plugin(page, pane, field, runs) {
}), plugin.Check() }), plugin.Check()
}, },
getLocation: function(event, target, option, field, cb) { getLocation: function(event) {
page.getLocation && page.getLocation(cb || (function(res) { var x = parseFloat(option.x.value)
page.ontoast(JSON.stringify(res)) 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) { openLocation: function(event) {
var x = parseFloat(option.x.value) var x = parseFloat(option.x.value)