func U2FChallenge(ctx *context.Context) {
	// Ensure user is in a U2F session.
	idSess := ctx.Session.Get("twofaUid")
	if idSess == nil {
		ctx.ServerError("UserSignIn", errors.New("not in U2F session"))
		return
	}
	id := idSess.(int64)
	regs, err := models.GetU2FRegistrationsByUID(id)
	if err != nil {
		ctx.ServerError("UserSignIn", err)
		return
	}
	if len(regs) == 0 {
		ctx.ServerError("UserSignIn", errors.New("no device registered"))
		return
	}
	challenge, err := u2f.NewChallenge(setting.U2F.AppID, setting.U2F.TrustedFacets)
	if err != nil {
		ctx.ServerError("u2f.NewChallenge", err)
		return
	}
	if err := ctx.Session.Set("u2fChallenge", challenge); err != nil {
		ctx.ServerError("UserSignIn: unable to set u2fChallenge in session", err)
		return
	}
	if err := ctx.Session.Release(); err != nil {
		ctx.ServerError("UserSignIn: unable to store session", err)
	}

	ctx.JSON(http.StatusOK, challenge.SignRequest(regs.ToRegistrations()))
}
// U2FChallenge submits a sign challenge to the browser
U2FChallenge submits a sign challenge to the browser
// U2FChallenge submits a sign challenge to the browser
func U2FChallenge(ctx *context.Context) {
	idSess := ctx.Session.Get("twofaUid")
	if idSess == nil {
		ctx.ServerError("UserSignIn", errors.New("not in U2F session"))
		return
	}
	id := idSess.(int64)
	regs, err := models.GetU2FRegistrationsByUID(id)
	if err != nil {
		ctx.ServerError("UserSignIn", err)
		return
	}
	if len(regs) == 0 {
		ctx.ServerError("UserSignIn", errors.New("no device registered"))
		return
	}
	challenge, err := u2f.NewChallenge(setting.U2F.AppID, setting.U2F.TrustedFacets)
	if err != nil {
		ctx.ServerError("u2f.NewChallenge", err)
		return
	}
	if err := ctx.Session.Set("u2fChallenge", challenge); err != nil {
		ctx.ServerError("UserSignIn: unable to set u2fChallenge in session", err)
		return
	}
	if err := ctx.Session.Release(); err != nil {
		ctx.ServerError("UserSignIn: unable to store session", err)
	}
	ctx.JSON(http.StatusOK, challenge.SignRequest(regs.ToRegistrations()))
}
func U2FChallenge ( ctx * context . Context ) { idSess := ctx . Session . Get ( " " ) if idSess == nil { ctx . ServerError ( " " , errors . New ( " " ) ) return } id := idSess . ( int64 ) regs , err := models . GetU2FRegistrationsByUID ( id ) if err != nil { ctx . ServerError ( " " , err ) return } if len ( regs ) == 0 { ctx . ServerError ( " " , errors . New ( " " ) ) return } challenge , err := u2f . NewChallenge ( setting . U2F . AppID , setting . U2F . TrustedFacets ) if err != nil { ctx . ServerError ( " " , err ) return } if err := ctx . Session . Set ( " " , challenge ) ; err != nil { ctx . ServerError ( " " , err ) return } if err := ctx . Session . Release ( ) ; err != nil { ctx . ServerError ( " " , err ) } ctx . JSON ( http . StatusOK , challenge . SignRequest ( regs . ToRegistrations ( ) ) ) }
U2FChallenge submits a sign challenge to the browser
U2FChallenge submits a sign challenge to the browser
// Ensure user is in a U2F session.