1
0
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:
astaxie
2013-12-12 22:25:08 +08:00
parent d603a6714d
commit 19119e99f7
7 changed files with 555 additions and 591 deletions

View File

@ -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)
}