mirror of
https://github.com/astaxie/beego.git
synced 2025-07-12 00:01:02 +00:00
move utils to utils libs & func move to templatefunc
This commit is contained in:
@ -3,6 +3,7 @@ package beego
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/hmac"
|
||||
"crypto/rand"
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
@ -370,7 +371,7 @@ func (c *Controller) XsrfToken() string {
|
||||
} else {
|
||||
expire = int64(XSRFExpire)
|
||||
}
|
||||
token = GetRandomString(15)
|
||||
token = getRandomString(15)
|
||||
c.SetSecureCookie(XSRFKEY, "_xsrf", token, expire)
|
||||
}
|
||||
c._xsrf_token = token
|
||||
@ -405,3 +406,14 @@ func (c *Controller) GoToFunc(funcname string) {
|
||||
}
|
||||
c.gotofunc = funcname
|
||||
}
|
||||
|
||||
//utils func for controller internal
|
||||
func getRandomString(n int) string {
|
||||
const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
var bytes = make([]byte, n)
|
||||
rand.Read(bytes)
|
||||
for i, b := range bytes {
|
||||
bytes[i] = alphanum[b%byte(len(alphanum))]
|
||||
}
|
||||
return string(bytes)
|
||||
}
|
||||
|
Reference in New Issue
Block a user