mirror of
https://github.com/luscis/openlan.git
synced 2025-10-06 00:57:03 +08:00
fix: user: default lease is 1 year
Signed-off-by: zhihui.ding <danieldin186@gmail.com>
This commit is contained in:
@@ -2,13 +2,14 @@ package v5
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/luscis/openlan/cmd/api"
|
"github.com/luscis/openlan/cmd/api"
|
||||||
"github.com/luscis/openlan/pkg/libol"
|
"github.com/luscis/openlan/pkg/libol"
|
||||||
"github.com/luscis/openlan/pkg/schema"
|
"github.com/luscis/openlan/pkg/schema"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
@@ -153,7 +154,7 @@ func (u User) Check(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u User) Commands(app *api.App) {
|
func (u User) Commands(app *api.App) {
|
||||||
lease := time.Now().AddDate(99, 0, 0)
|
lease := time.Now().AddDate(1, 0, 0)
|
||||||
app.Command(&cli.Command{
|
app.Command(&cli.Command{
|
||||||
Name: "user",
|
Name: "user",
|
||||||
Aliases: []string{"us"},
|
Aliases: []string{"us"},
|
||||||
|
7
pkg/cache/user.go
vendored
7
pkg/cache/user.go
vendored
@@ -4,12 +4,13 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"github.com/luscis/openlan/pkg/libol"
|
|
||||||
"github.com/luscis/openlan/pkg/models"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/luscis/openlan/pkg/libol"
|
||||||
|
"github.com/luscis/openlan/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type user struct {
|
type user struct {
|
||||||
@@ -45,7 +46,7 @@ func (w *user) Load() {
|
|||||||
if len(columns) > 3 {
|
if len(columns) > 3 {
|
||||||
leStr = columns[3]
|
leStr = columns[3]
|
||||||
}
|
}
|
||||||
lease, _ := libol.GetLocalTime(libol.LeaseTime, leStr)
|
lease, _ := libol.GetLeaseTime(leStr)
|
||||||
obj := &models.User{
|
obj := &models.User{
|
||||||
Name: user,
|
Name: user,
|
||||||
Password: pass,
|
Password: pass,
|
||||||
|
@@ -306,6 +306,10 @@ func GetLocalTime(layout, value string) (time.Time, error) {
|
|||||||
return time.ParseInLocation(layout, value, time.Local)
|
return time.ParseInLocation(layout, value, time.Local)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetLeaseTime(value string) (time.Time, error) {
|
||||||
|
return time.ParseInLocation(LeaseTime, value, time.Local)
|
||||||
|
}
|
||||||
|
|
||||||
func Base64Decode(value string) ([]byte, error) {
|
func Base64Decode(value string) ([]byte, error) {
|
||||||
return base64.StdEncoding.DecodeString(value)
|
return base64.StdEncoding.DecodeString(value)
|
||||||
}
|
}
|
||||||
|
@@ -80,7 +80,7 @@ func NewUserSchema(u *User) schema.User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SchemaToUserModel(user *schema.User) *User {
|
func SchemaToUserModel(user *schema.User) *User {
|
||||||
lease, _ := libol.GetLocalTime(libol.LeaseTime, user.Lease)
|
lease, _ := libol.GetLeaseTime(user.Lease)
|
||||||
obj := &User{
|
obj := &User{
|
||||||
Alias: user.Alias,
|
Alias: user.Alias,
|
||||||
Password: user.Password,
|
Password: user.Password,
|
||||||
|
Reference in New Issue
Block a user