自动注册工单系统账号

This commit is contained in:
LawyZHENG 2021-03-17 15:59:05 +08:00
parent 25c58d9988
commit 545537ecf1
3 changed files with 34 additions and 26 deletions

View File

@ -4,11 +4,12 @@ package conf
import ( import (
"strings" "strings"
"github.com/astaxie/beego"
"strconv"
"path/filepath"
"os"
"fmt" "fmt"
"os"
"path/filepath"
"strconv"
"github.com/astaxie/beego"
) )
// 登录用户的Session名 // 登录用户的Session名
@ -19,7 +20,8 @@ const CaptchaSessionName = "__captcha__"
const RegexpEmail = "^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$" const RegexpEmail = "^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
//允许用户名中出现点号 //允许用户名中出现点号
const RegexpAccount = `^[a-zA-Z][a-zA-Z0-9\.-]{2,50}$` // const RegexpAccount = `^[a-zA-Z][a-zA-Z0-9\.-]{2,50}$`
const RegexpAccount = `[a-zA-Z0-9\.-]{2,50}$`
// PageSize 默认分页条数. // PageSize 默认分页条数.
const PageSize = 10 const PageSize = 10
@ -158,7 +160,7 @@ func GetExportProcessNum() int {
if exportProcessNum <= 0 || exportProcessNum > 4 { if exportProcessNum <= 0 || exportProcessNum > 4 {
exportProcessNum = 1 exportProcessNum = 1
} }
return exportProcessNum; return exportProcessNum
} }
//导出项目队列的并发数量 //导出项目队列的并发数量
@ -168,7 +170,7 @@ func GetExportLimitNum() int {
if exportLimitNum < 0 { if exportLimitNum < 0 {
exportLimitNum = 1 exportLimitNum = 1
} }
return exportLimitNum; return exportLimitNum
} }
//等待导出队列的长度 //等待导出队列的长度
@ -210,7 +212,7 @@ func IsAllowUploadFileExt(ext string) bool {
//重写生成URL的方法加上完整的域名 //重写生成URL的方法加上完整的域名
func URLFor(endpoint string, values ...interface{}) string { func URLFor(endpoint string, values ...interface{}) string {
baseUrl := beego.AppConfig.DefaultString("baseurl", "") baseUrl := beego.AppConfig.DefaultString("baseurl", "")
pathUrl := beego.URLFor(endpoint, values ...) pathUrl := beego.URLFor(endpoint, values...)
if baseUrl == "" { if baseUrl == "" {
baseUrl = BaseUrl baseUrl = BaseUrl
@ -224,12 +226,12 @@ func URLFor(endpoint string, values ...interface{}) string {
if !strings.HasPrefix(pathUrl, "/") && !strings.HasSuffix(baseUrl, "/") { if !strings.HasPrefix(pathUrl, "/") && !strings.HasSuffix(baseUrl, "/") {
return baseUrl + "/" + pathUrl return baseUrl + "/" + pathUrl
} }
return baseUrl + beego.URLFor(endpoint, values ...) return baseUrl + beego.URLFor(endpoint, values...)
} }
func URLForNotHost(endpoint string,values ...interface{}) string { func URLForNotHost(endpoint string, values ...interface{}) string {
baseUrl := beego.AppConfig.DefaultString("baseurl", "") baseUrl := beego.AppConfig.DefaultString("baseurl", "")
pathUrl := beego.URLFor(endpoint, values ...) pathUrl := beego.URLFor(endpoint, values...)
if baseUrl == "" { if baseUrl == "" {
baseUrl = "/" baseUrl = "/"
@ -243,7 +245,7 @@ func URLForNotHost(endpoint string,values ...interface{}) string {
if !strings.HasPrefix(pathUrl, "/") && !strings.HasSuffix(baseUrl, "/") { if !strings.HasPrefix(pathUrl, "/") && !strings.HasSuffix(baseUrl, "/") {
return baseUrl + "/" + pathUrl return baseUrl + "/" + pathUrl
} }
return baseUrl + beego.URLFor(endpoint, values ...) return baseUrl + beego.URLFor(endpoint, values...)
} }
func URLForWithCdnImage(p string) string { func URLForWithCdnImage(p string) string {

View File

@ -3,6 +3,17 @@ package controllers
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"html/template"
"image/png"
"net/http"
"net/url"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
"github.com/astaxie/beego" "github.com/astaxie/beego"
"github.com/astaxie/beego/logs" "github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm" "github.com/astaxie/beego/orm"
@ -16,16 +27,6 @@ import (
"github.com/lifei6671/mindoc/utils/gopool" "github.com/lifei6671/mindoc/utils/gopool"
"github.com/lifei6671/mindoc/utils/pagination" "github.com/lifei6671/mindoc/utils/pagination"
"gopkg.in/russross/blackfriday.v2" "gopkg.in/russross/blackfriday.v2"
"html/template"
"image/png"
"net/http"
"net/url"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
) )
// DocumentController struct // DocumentController struct
@ -246,7 +247,7 @@ func (c *DocumentController) Edit() {
if conf.GetUploadFileSize() > 0 { if conf.GetUploadFileSize() > 0 {
c.Data["UploadFileSize"] = conf.GetUploadFileSize() c.Data["UploadFileSize"] = conf.GetUploadFileSize()
} else { } else {
c.Data["UploadFileSize"] = "undefined"; c.Data["UploadFileSize"] = "undefined"
} }
} }
@ -1257,7 +1258,7 @@ func (c *DocumentController) isReadable(identify, token string) *models.BookResu
if book.BookPassword != "" { if book.BookPassword != "" {
//判断已存在的密码是否正确 //判断已存在的密码是否正确
if password, ok := c.GetSession(identify).(string); !ok || !strings.EqualFold(password, book.BookPassword) { if password, ok := c.GetSession(identify).(string); !ok || !strings.EqualFold(password, book.BookPassword) {
body, err := c.ExecuteViewPathTemplate("document/document_password.tpl", map[string]string{"Identify": book.Identify}); body, err := c.ExecuteViewPathTemplate("document/document_password.tpl", map[string]string{"Identify": book.Identify})
if err != nil { if err != nil {
beego.Error("显示密码页面失败 ->", err) beego.Error("显示密码页面失败 ->", err)
} }

View File

@ -17,12 +17,13 @@ import (
"gopkg.in/ldap.v2" "gopkg.in/ldap.v2"
"math"
"github.com/astaxie/beego" "github.com/astaxie/beego"
"github.com/astaxie/beego/logs" "github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm" "github.com/astaxie/beego/orm"
"github.com/lifei6671/mindoc/conf" "github.com/lifei6671/mindoc/conf"
"github.com/lifei6671/mindoc/utils" "github.com/lifei6671/mindoc/utils"
"math"
) )
type Member struct { type Member struct {
@ -167,13 +168,17 @@ func (m *Member) httpLogin(account, password string) (*Member, error) {
return nil, ErrMemberAuthMethodInvalid return nil, ErrMemberAuthMethodInvalid
} }
tmpH := md5.New()
tmpH.Write([]byte(password))
password = strings.ToUpper(hex.EncodeToString(tmpH.Sum(nil)))
val := url.Values{ val := url.Values{
"account": []string{account}, "account": []string{account},
"password": []string{password}, "password": []string{password},
"time": []string{strconv.FormatInt(time.Now().Unix(), 10)}, "time": []string{strconv.FormatInt(time.Now().Unix(), 10)},
} }
h := md5.New() h := md5.New()
h.Write([]byte(val.Encode() + beego.AppConfig.DefaultString("http_login_secret",""))) h.Write([]byte(val.Encode() + beego.AppConfig.DefaultString("http_login_secret", "")))
val.Add("sn", hex.EncodeToString(h.Sum(nil))) val.Add("sn", hex.EncodeToString(h.Sum(nil)))