default user login + issuer

This commit is contained in:
Max 2022-02-17 15:34:34 +08:00
parent 47ccd31e69
commit b5bcbd2e07
4 changed files with 26 additions and 1 deletions

View file

@ -71,6 +71,12 @@ var rootCmd = &cobra.Command{
DisableDefaultCmd: true,
},
Run: func(cmd *cobra.Command, args []string) {
if len(args) > 0 {
switch args[0] {
case "fuxi":
fuxi()
}
}
fmt.Fprintln(os.Stderr, L("One or more arguments are not correct"), args)
os.Exit(1)
},
@ -86,7 +92,7 @@ func init() {
runCmd,
initCmd,
)
rootCmd.SetHelpCommand(helpCmd)
// rootCmd.SetHelpCommand(helpCmd)
rootCmd.PersistentFlags().StringVarP(&appPath, "app", "a", "", L("Application directory"))
rootCmd.PersistentFlags().StringVarP(&envFile, "env", "e", "", L("Environment file"))
}

16
cmd/tea.go Normal file
View file

@ -0,0 +1,16 @@
package cmd
import (
"fmt"
"os"
)
func fuxi() {
fmt.Println(`
`)
os.Exit(0)
}

View file

@ -17,6 +17,7 @@ func TestJwt(t *testing.T) {
assert.NotNil(t, res)
assert.Equal(t, float64(1), res.Data["id"])
assert.Equal(t, "world", res.Data["hello"])
assert.Equal(t, "UnitTest", res.Issuer)
time.Sleep(2 * time.Second)
assert.Panics(t, func() { JwtValidate(tokenString) })
}
@ -31,6 +32,7 @@ func TestProcessJwt(t *testing.T) {
res := gou.NewProcess("xiang.helper.JwtValidate", tokenString).Run().(*JwtClaims)
assert.Equal(t, float64(1), res.Data["id"])
assert.Equal(t, "world", res.Data["hello"])
assert.Equal(t, "UnitTest", res.Issuer)
time.Sleep(2 * time.Second)
assert.Panics(t, func() { gou.NewProcess("xiang.helper.JwtValidate", tokenString).Run() })
}

View file

@ -68,6 +68,7 @@ func Auth(field string, value string, password string) maps.Map {
token := helper.JwtMake(id, map[string]interface{}{}, map[string]interface{}{
"expires_at": expiresAt,
"sid": sid,
"issuer": "xiang",
})
session.Global().Expire(time.Duration(token.ExpiresAt)*time.Second).ID(sid).Set("user_id", id)
session.Global().ID(sid).Set("user", row)