mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-22 18:00:37 +01:00
bc05ddc0eb
* Add redirect for user * Add redirect for orgs * Add user redirect test * Appease linter * Add comment to DeleteUserRedirect function * Fix locale changes * Fix GetUserByParams * Fix orgAssignment * Remove debug logging * Add redirect prompt * Dont Export DeleteUserRedirect & only use it within a session * Unexport newUserRedirect * cleanup * Fix & Dedub API code * Format Template * Add Migration & rm dublicat * Refactor: unexport newRepoRedirect() & rm dedub del exec * if this fails we'll need to re-rename the user directory Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
36 lines
999 B
Go
36 lines
999 B
Go
// Copyright 2021 The Gitea Authors.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package user
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"code.gitea.io/gitea/models"
|
|
"code.gitea.io/gitea/modules/context"
|
|
)
|
|
|
|
// GetUserByParamsName get user by name
|
|
func GetUserByParamsName(ctx *context.APIContext, name string) *models.User {
|
|
username := ctx.Params(name)
|
|
user, err := models.GetUserByName(username)
|
|
if err != nil {
|
|
if models.IsErrUserNotExist(err) {
|
|
if redirectUserID, err := models.LookupUserRedirect(username); err == nil {
|
|
context.RedirectToUser(ctx.Context, username, redirectUserID)
|
|
} else {
|
|
ctx.NotFound("GetUserByName", err)
|
|
}
|
|
} else {
|
|
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
|
|
}
|
|
return nil
|
|
}
|
|
return user
|
|
}
|
|
|
|
// GetUserByParams returns user whose name is presented in URL (":username").
|
|
func GetUserByParams(ctx *context.APIContext) *models.User {
|
|
return GetUserByParamsName(ctx, ":username")
|
|
}
|