Final fix for nil pointer
Cette révision appartient à :
Parent
baccce78e2
révision
caa7e499f3
3 fichiers modifiés avec 10 ajouts et 4 suppressions
|
@ -48,5 +48,8 @@ func newSearchForm(c *gin.Context) searchForm {
|
|||
}
|
||||
func getUser(c *gin.Context) *models.User {
|
||||
user, _, _ := cookies.CurrentUser(c)
|
||||
if user == nil {
|
||||
return &models.User{}
|
||||
}
|
||||
return user
|
||||
}
|
||||
|
|
|
@ -36,6 +36,9 @@ type CurrentUserRetriever struct{}
|
|||
// RetrieveCurrentUser retrieve current user for languages
|
||||
func (*CurrentUserRetriever) RetrieveCurrentUser(c *gin.Context) (*models.User, error) {
|
||||
user, _, err := CurrentUser(c)
|
||||
if user == nil {
|
||||
return &models.User{}, err
|
||||
}
|
||||
return user, err
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ func GetDefaultTfunc() (i18n.TranslateFunc, error) {
|
|||
func GetTfuncAndLanguageFromRequest(c *gin.Context) (T i18n.TranslateFunc, Tlang *language.Language) {
|
||||
userLanguage := ""
|
||||
user, _ := getCurrentUser(c)
|
||||
if user != nil {
|
||||
if user.ID > 0 {
|
||||
userLanguage = user.Language
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ func GetTfuncFromRequest(c *gin.Context) TemplateTfunc {
|
|||
// GetThemeFromRequest: Gets the user selected theme from the request
|
||||
func GetThemeFromRequest(c *gin.Context) string {
|
||||
user, _ := getCurrentUser(c)
|
||||
if user != nil {
|
||||
if user.ID > 0 {
|
||||
return user.Theme
|
||||
}
|
||||
cookie, err := c.Cookie("theme")
|
||||
|
@ -149,7 +149,7 @@ func GetThemeFromRequest(c *gin.Context) string {
|
|||
// GetThemeFromRequest: Gets the user selected theme from the request
|
||||
func GetMascotFromRequest(c *gin.Context) string {
|
||||
user, _ := getCurrentUser(c)
|
||||
if user != nil {
|
||||
if user.ID > 0 {
|
||||
return user.Mascot
|
||||
}
|
||||
cookie, err := c.Cookie("mascot")
|
||||
|
@ -163,7 +163,7 @@ func GetMascotFromRequest(c *gin.Context) string {
|
|||
// Returns an empty string if not set.
|
||||
func GetMascotUrlFromRequest(c *gin.Context) string {
|
||||
user, _ := getCurrentUser(c)
|
||||
if user != nil {
|
||||
if user.ID > 0 {
|
||||
return user.MascotURL
|
||||
}
|
||||
|
||||
|
|
Référencer dans un nouveau ticket