mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-19 07:37:29 -06:00
rename util functions
This commit is contained in:
parent
8f874a0ec0
commit
fa4d267d16
4 changed files with 36 additions and 17 deletions
|
|
@ -58,7 +58,7 @@ func (m *Module) AuthorizeGETHandler(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
user := m.userFromSession(c, s)
|
user := m.mustUserFromSession(c, s)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
// Error already
|
// Error already
|
||||||
// written.
|
// written.
|
||||||
|
|
@ -81,21 +81,21 @@ func (m *Module) AuthorizeGETHandler(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
redirectURI := m.stringFromSession(c, s, sessionRedirectURI)
|
redirectURI := m.mustStringFromSession(c, s, sessionRedirectURI)
|
||||||
if redirectURI == "" {
|
if redirectURI == "" {
|
||||||
// Error already
|
// Error already
|
||||||
// written.
|
// written.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
scope := m.stringFromSession(c, s, sessionScope)
|
scope := m.mustStringFromSession(c, s, sessionScope)
|
||||||
if scope == "" {
|
if scope == "" {
|
||||||
// Error already
|
// Error already
|
||||||
// written.
|
// written.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app := m.appFromSession(c, s)
|
app := m.mustAppFromSession(c, s)
|
||||||
if app == nil {
|
if app == nil {
|
||||||
// Error already
|
// Error already
|
||||||
// written.
|
// written.
|
||||||
|
|
@ -136,35 +136,35 @@ func (m *Module) AuthorizePOSTHandler(c *gin.Context) {
|
||||||
// can be validated by the oauth2 library.
|
// can be validated by the oauth2 library.
|
||||||
s := sessions.Default(c)
|
s := sessions.Default(c)
|
||||||
|
|
||||||
responseType := m.stringFromSession(c, s, sessionResponseType)
|
responseType := m.mustStringFromSession(c, s, sessionResponseType)
|
||||||
if responseType == "" {
|
if responseType == "" {
|
||||||
// Error already
|
// Error already
|
||||||
// written.
|
// written.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
clientID := m.stringFromSession(c, s, sessionClientID)
|
clientID := m.mustStringFromSession(c, s, sessionClientID)
|
||||||
if clientID == "" {
|
if clientID == "" {
|
||||||
// Error already
|
// Error already
|
||||||
// written.
|
// written.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
redirectURI := m.stringFromSession(c, s, sessionRedirectURI)
|
redirectURI := m.mustStringFromSession(c, s, sessionRedirectURI)
|
||||||
if redirectURI == "" {
|
if redirectURI == "" {
|
||||||
// Error already
|
// Error already
|
||||||
// written.
|
// written.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
scope := m.stringFromSession(c, s, sessionScope)
|
scope := m.mustStringFromSession(c, s, sessionScope)
|
||||||
if scope == "" {
|
if scope == "" {
|
||||||
// Error already
|
// Error already
|
||||||
// written.
|
// written.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
user := m.userFromSession(c, s)
|
user := m.mustUserFromSession(c, s)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
// Error already
|
// Error already
|
||||||
// written.
|
// written.
|
||||||
|
|
|
||||||
|
|
@ -37,14 +37,14 @@ func (m *Module) OOBTokenGETHandler(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
user := m.userFromSession(c, s)
|
user := m.mustUserFromSession(c, s)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
// Error already
|
// Error already
|
||||||
// written.
|
// written.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
scope := m.stringFromSession(c, s, sessionScope)
|
scope := m.mustStringFromSession(c, s, sessionScope)
|
||||||
if scope == "" {
|
if scope == "" {
|
||||||
// Error already
|
// Error already
|
||||||
// written.
|
// written.
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ func (m *Module) SignInGETHandler(c *gin.Context) {
|
||||||
//
|
//
|
||||||
// We need the internal state to know where
|
// We need the internal state to know where
|
||||||
// to redirect to.
|
// to redirect to.
|
||||||
internalState := m.stringFromSession(
|
internalState := m.mustStringFromSession(
|
||||||
c,
|
c,
|
||||||
sessions.Default(c),
|
sessions.Default(c),
|
||||||
sessionInternalState,
|
sessionInternalState,
|
||||||
|
|
@ -195,7 +195,7 @@ func incorrectPassword(err error) (*gtsmodel.User, gtserror.WithCode) {
|
||||||
func (m *Module) TwoFactorCodeGETHandler(c *gin.Context) {
|
func (m *Module) TwoFactorCodeGETHandler(c *gin.Context) {
|
||||||
s := sessions.Default(c)
|
s := sessions.Default(c)
|
||||||
|
|
||||||
user := m.userFromSession(c, s)
|
user := m.mustUserFromSession(c, s)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
// Error already
|
// Error already
|
||||||
// written.
|
// written.
|
||||||
|
|
@ -226,7 +226,7 @@ func (m *Module) TwoFactorCodeGETHandler(c *gin.Context) {
|
||||||
func (m *Module) TwoFactorCodePOSTHandler(c *gin.Context) {
|
func (m *Module) TwoFactorCodePOSTHandler(c *gin.Context) {
|
||||||
s := sessions.Default(c)
|
s := sessions.Default(c)
|
||||||
|
|
||||||
user := m.userFromSession(c, s)
|
user := m.mustUserFromSession(c, s)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
// Error already
|
// Error already
|
||||||
// written.
|
// written.
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,13 @@ func (m *Module) mustSaveSession(s sessions.Session) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Module) userFromSession(
|
// mustUserFromSession returns a *gtsmodel.User by checking the
|
||||||
|
// session for a user id and fetching the user from the database.
|
||||||
|
//
|
||||||
|
// On failure, the function clears session state, writes an internal
|
||||||
|
// error to the response writer, and returns nil. Callers should always
|
||||||
|
// return immediately if receiving nil back from this function!
|
||||||
|
func (m *Module) mustUserFromSession(
|
||||||
c *gin.Context,
|
c *gin.Context,
|
||||||
s sessions.Session,
|
s sessions.Session,
|
||||||
) *gtsmodel.User {
|
) *gtsmodel.User {
|
||||||
|
|
@ -74,7 +80,13 @@ func (m *Module) userFromSession(
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Module) appFromSession(
|
// mustAppFromSession returns a *gtsmodel.Application by checking the
|
||||||
|
// session for an application keyid and fetching the app from the database.
|
||||||
|
//
|
||||||
|
// On failure, the function clears session state, writes an internal
|
||||||
|
// error to the response writer, and returns nil. Callers should always
|
||||||
|
// return immediately if receiving nil back from this function!
|
||||||
|
func (m *Module) mustAppFromSession(
|
||||||
c *gin.Context,
|
c *gin.Context,
|
||||||
s sessions.Session,
|
s sessions.Session,
|
||||||
) *gtsmodel.Application {
|
) *gtsmodel.Application {
|
||||||
|
|
@ -95,7 +107,14 @@ func (m *Module) appFromSession(
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Module) stringFromSession(
|
// mustStringFromSession returns the string value
|
||||||
|
// corresponding to the given session key, if any is set.
|
||||||
|
//
|
||||||
|
// On failure (nothing set), the function clears session
|
||||||
|
// state, writes an internal error to the response writer,
|
||||||
|
// and returns nil. Callers should always return immediately
|
||||||
|
// if receiving nil back from this function!
|
||||||
|
func (m *Module) mustStringFromSession(
|
||||||
c *gin.Context,
|
c *gin.Context,
|
||||||
s sessions.Session,
|
s sessions.Session,
|
||||||
key string,
|
key string,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue