注册并自动登陆时报错

1. 运行环境

macOS M1
go1.17.7 darwin/arm64

2. 问题描述?

注册时登陆报错


func (*AuthController) DoRegister(w http.ResponseWriter, r *http.Request) {
    _user := user.User{
        Name:            r.PostFormValue("name"),
        Email:           r.PostFormValue("email"),
        Password:        r.PostFormValue("password"),
        PasswordConfirm: r.PostFormValue("password_confirm"),
    }
    errs := requests.ValidateRegistrationForm(_user)
    if len(errs) > 0 {
        view.RenderSimple(w, view.D{
            "Errors": errs,
            "User":   _user,
        }, "auth.register")
    } else {
        _user.Create()
        if _user.ID > 0 {
            auth.Login(_user)
            http.Redirect(w, r, "/", http.StatusFound)
            fmt.Fprint(w, "插入成功,ID 为"+_user.GetStringID())
        } else {
            w.WriteHeader(http.StatusInternalServerError)
            fmt.Fprint(w, "注册失败,请联系管理员")
        }
    }
}

3. 您期望得到的结果?

注册后自动登录

4. 您实际得到的结果?

注册过程报错(慢sql)、session保存时也报错(接口未注册)
这两个报错都是必现的.

2022/08/22 16:15:15 …/go/src/github.com/jiffy/goblog/app/models/user/curd.go:10 SLOW SQL >= 200ms
[1111.392ms] [rows:1] INSERT INTO users (created_at,updated_at,name,email,password) VALUES (‘2022-08-22 16:15:15.479’,’2022-08-22 16:15:15.479’,’test10’,‘10@qq.com‘,’$2a$14$SjeVdryyrSJSLLvT1WYNC.EUkLNpWfUJnq4mEUvJC1E6CiEmFcBWO’)
2022/08/22 16:15:15 securecookie: error - caused by: securecookie: error - caused by: gob: type not registered for interface: user.User

讨论数量: 1

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!