第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在 golang revel 框架中使用 session

如何在 golang revel 框架中使用 session

Go
慕標(biāo)琳琳 2021-09-27 17:32:15
我使用 golang web 框架作為我的 web 框架。但是會(huì)話(huà)不使用。我寫(xiě)的代碼如下:package controllers import (    "fmt"    "net/http"    "strconv"    "GoRBAC/app/base"    "GoRBAC/app/models"    r "github.com/revel/revel")type App struct {    *r.Controller}// 首頁(yè)func (this App) Index() r.Result {    userDao := models.NewUserDao()    user, err := userDao.QueryById(1)    if err != nil {        fmt.Println(err)    }    fmt.Println(user)    return this.Render()}// 跳轉(zhuǎn)至登錄頁(yè)面func (this App) ToLogin() r.Result {    return this.RenderTemplate("App/login.html")}func (this App) Login() r.Result {    username := this.Params.Get("username")    password := this.Params.Get("password")    securityCode := this.Params.Get("securityCode")    fmt.Println(this.Session["securityCode"])    fmt.Println(username)    fmt.Println(password)    fmt.Println(securityCode)    if securityCode != this.Session["securityCode"] {        return this.RenderText("error securityCode")    } else {        userDao := models.NewUserDao()        user, err := userDao.QueryByUsername(username)        if err != nil || user == nil {            return this.RenderText("username not exsit")        } else if user.Password != password {            return this.RenderText("error password")        } else {            delete(this.Session, "securityCode")            this.RenderText("ok")        }    }    return this.RenderText("ok")}// 獲取驗(yàn)證碼圖片func (this App) GetSecurityCode(timestamp int64) r.Result {    // 時(shí)間戳參數(shù),第一次加載為1,后續(xù)加載為當(dāng)前的時(shí)間戳,可以用來(lái)驗(yàn)證客戶(hù)端刷新頻率    // 如:刷新頻率過(guò)高,直接限制當(dāng)前客戶(hù)端等    fmt.Println("GetSecurityCode", timestamp)    d := make([]byte, 4)    s := base.NewLen(4)    ss := ""    d = []byte(s)    for v := range d {        d[v] %= 10        ss += strconv.FormatInt(int64(d[v]), 32)    }}我在方法 GetSecurityCode() 中設(shè)置了 session 中的 securityCode 值,該方法用于生成登錄驗(yàn)證的安全代碼我在方法 Login() 中使用了 securityCode 值。但我一無(wú)所獲誰(shuí)能幫助我,我該如何解決這個(gè)問(wèn)題?
查看完整描述

2 回答

?
慕村225694

TA貢獻(xiàn)1880條經(jīng)驗(yàn) 獲得超4個(gè)贊

謝謝正如你所說(shuō),我解決了這個(gè)問(wèn)題:


// 獲取驗(yàn)證碼圖片

func (this App) GetSecurityCode(timestamp int64) r.Result {

// 時(shí)間戳參數(shù),第一次加載為1,后續(xù)加載為當(dāng)前的時(shí)間戳,可以用來(lái)驗(yàn)證客戶(hù)端刷新頻率

// 如:刷新頻率過(guò)高,直接限制當(dāng)前客戶(hù)端等

//fmt.Println("GetSecurityCode", timestamp)


d := make([]byte, 4)

s := base.NewLen(4)

ss := ""

d = []byte(s)


for v := range d {

    d[v] %= 10

    ss += strconv.FormatInt(int64(d[v]), 32)

}


this.Session["securityCode"] = ss

fmt.Println(this.Session["securityCode"])


//this.Response.Status = http.StatusOK

//this.Response.ContentType = "image/png"


buff := &bytes.Buffer{}

base.NewImage(d, 100, 40).WriteTo(buff)


return this.RenderBinary(buff, "img", r.Attachment, time.Now())

}


查看完整回答
反對(duì) 回復(fù) 2021-09-27
  • 2 回答
  • 0 關(guān)注
  • 200 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)