func TeamsRepoAction(ctx *middleware.Context) { if !ctx.Org.IsOwner { ctx.Error(404) return } var err error switch ctx.Params(":action") { case "add": repoName := path.Base(ctx.Query("repo-name")) var repo *models.Repository repo, err = models.GetRepositoryByName(ctx.Org.Organization.Id, repoName) if err != nil { if models.IsErrRepoNotExist(err) { ctx.Flash.Error(ctx.Tr("org.teams.add_nonexistent_repo")) ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories") return } ctx.Handle(500, "GetRepositoryByName", err) return } err = ctx.Org.Team.AddRepository(repo) case "remove": err = ctx.Org.Team.RemoveRepository(com.StrTo(ctx.Query("repoid")).MustInt64()) } if err != nil { log.Error(3, "Action(%s): '%s' %v", ctx.Params(":action"), ctx.Org.Team.Name, err) ctx.Handle(500, "TeamsRepoAction", err) return } ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories") }
func Stars(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("repos.stars") page := ctx.QueryInt("page") if page <= 0 { page = 1 } ctx.Data["Page"] = paginater.New(ctx.Repo.Repository.NumStars, models.ItemsPerPage, page, 5) stars, err := ctx.Repo.Repository.GetStars(ctx.QueryInt("page")) if err != nil { ctx.Handle(500, "GetStars", err) return } if (ctx.QueryInt("page")-1)*models.ItemsPerPage > ctx.Repo.Repository.NumStars { ctx.Handle(404, "ctx.Repo.Repository.NumStars", nil) return } ctx.Data["Stars"] = stars ctx.HTML(200, STARS) }
func Explore(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("explore") ctx.Data["PageIsExplore"] = true ctx.Data["PageIsExploreRepositories"] = true page := ctx.QueryInt("page") if page <= 1 { page = 1 } ctx.Data["Page"] = paginater.New(int(models.CountPublicRepositories()), setting.ExplorePagingNum, page, 5) repos, err := models.GetRecentUpdatedRepositories(page) if err != nil { ctx.Handle(500, "GetRecentUpdatedRepositories", err) return } for _, repo := range repos { if err = repo.GetOwner(); err != nil { ctx.Handle(500, "GetOwner", fmt.Errorf("%d: %v", repo.ID, err)) return } } ctx.Data["Repos"] = repos ctx.HTML(200, EXPLORE_REPOS) }
func SignInPost(ctx *middleware.Context, form auth.SignInForm) { ctx.Data["Title"] = ctx.Tr("sign_in") if ctx.HasError() { ctx.HTML(200, SIGNIN) return } u, err := models.UserSignIn(form.UserName, form.Password) if err != nil { if models.IsErrUserNotExist(err) { ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), SIGNIN, &form) } else { ctx.Handle(500, "UserSignIn", err) } return } if form.Remember { days := 86400 * setting.LogInRememberDays ctx.SetCookie(setting.CookieUserName, u.Name, days, setting.AppSubUrl) ctx.SetSuperSecureCookie(base.EncodeMd5(u.Rands+u.Passwd), setting.CookieRememberName, u.Name, days, setting.AppSubUrl) } ctx.Session.Set("uid", u.Id) ctx.Session.Set("uname", u.Name) if redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")); len(redirectTo) > 0 { ctx.SetCookie("redirect_to", "", -1, setting.AppSubUrl) ctx.Redirect(redirectTo) return } ctx.Redirect(setting.AppSubUrl + "/") }
func Invitation(ctx *middleware.Context) { org := ctx.Org.Organization ctx.Data["Title"] = org.FullName ctx.Data["PageIsOrgMembers"] = true if ctx.Req.Method == "POST" { uname := ctx.Query("uname") u, err := models.GetUserByName(uname) if err != nil { if models.IsErrUserNotExist(err) { ctx.Flash.Error(ctx.Tr("form.user_not_exist")) ctx.Redirect(ctx.Org.OrgLink + "/invitations/new") } else { ctx.Handle(500, " GetUserByName", err) } return } if err = org.AddMember(u.Id); err != nil { ctx.Handle(500, " AddMember", err) return } log.Trace("New member added(%s): %s", org.Name, u.Name) ctx.Redirect(ctx.Org.OrgLink + "/members") return } ctx.HTML(200, MEMBER_INVITE) }
func Monitor(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("admin.monitor") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminMonitor"] = true ctx.Data["Processes"] = process.Processes ctx.Data["Entries"] = cron.ListTasks() ctx.HTML(200, MONITOR) }
func DeleteTeam(ctx *middleware.Context) { if err := models.DeleteTeam(ctx.Org.Team); err != nil { ctx.Handle(500, "DeleteTeam", err) return } ctx.Flash.Success(ctx.Tr("org.teams.delete_team_success")) ctx.Redirect(ctx.Org.OrgLink + "/teams") }
func MembersAction(ctx *middleware.Context) { uid := com.StrTo(ctx.Query("uid")).MustInt64() if uid == 0 { ctx.Redirect(ctx.Org.OrgLink + "/members") return } org := ctx.Org.Organization var err error switch ctx.Params(":action") { case "private": if ctx.User.Id != uid && !ctx.Org.IsOwner { ctx.Error(404) return } err = models.ChangeOrgUserStatus(org.Id, uid, false) case "public": if ctx.User.Id != uid { ctx.Error(404) return } err = models.ChangeOrgUserStatus(org.Id, uid, true) case "remove": if !ctx.Org.IsOwner { ctx.Error(404) return } err = org.RemoveMember(uid) if models.IsErrLastOrgOwner(err) { ctx.Flash.Error(ctx.Tr("form.last_org_owner")) ctx.Redirect(ctx.Org.OrgLink + "/members") return } case "leave": err = org.RemoveMember(ctx.User.Id) if models.IsErrLastOrgOwner(err) { ctx.Flash.Error(ctx.Tr("form.last_org_owner")) ctx.Redirect(ctx.Org.OrgLink + "/members") return } } if err != nil { log.Error(4, "Action(%s): %v", ctx.Params(":action"), err) ctx.JSON(200, map[string]interface{}{ "ok": false, "err": err.Error(), }) return } if ctx.Params(":action") != "leave" { ctx.Redirect(ctx.Org.OrgLink + "/members") } else { ctx.Redirect(setting.AppSubUrl + "/") } }
func DeleteNotice(ctx *middleware.Context) { id := ctx.ParamsInt64(":id") if err := models.DeleteNotice(id); err != nil { ctx.Handle(500, "DeleteNotice", err) return } log.Trace("System notice deleted by admin(%s): %d", ctx.User.Name, id) ctx.Flash.Success(ctx.Tr("admin.notices.delete_success")) ctx.Redirect("/admin/notices") }
func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) { form.Enable = true if err := user.UpdateAvatarSetting(ctx, form, ctx.Org.Organization); err != nil { ctx.Flash.Error(err.Error()) } else { ctx.Flash.Success(ctx.Tr("org.settings.update_avatar_success")) } ctx.Redirect(ctx.Org.OrgLink + "/settings") }
func DeleteDeployKey(ctx *middleware.Context) { if err := models.DeleteDeployKey(ctx.QueryInt64("id")); err != nil { ctx.Flash.Error("DeleteDeployKey: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("repo.settings.deploy_key_deletion_success")) } ctx.JSON(200, map[string]interface{}{ "redirect": ctx.Repo.RepoLink + "/settings/keys", }) }
func DeleteWebhook(ctx *middleware.Context) { if err := models.DeleteWebhook(ctx.QueryInt64("id")); err != nil { ctx.Flash.Error("DeleteWebhook: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("repo.settings.webhook_deletion_success")) } ctx.JSON(200, map[string]interface{}{ "redirect": ctx.Org.OrgLink + "/settings/hooks", }) }
func ResetPasswd(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("auth.reset_password") code := ctx.Query("code") if len(code) == 0 { ctx.Error(404) return } ctx.Data["Code"] = code ctx.Data["IsResetForm"] = true ctx.HTML(200, RESET_PASSWORD) }
func EditUser(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("admin.users.edit_account") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminUsers"] = true prepareUserInfo(ctx) if ctx.Written() { return } ctx.HTML(200, USER_EDIT) }
func ForgotPasswd(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("auth.forgot_password") if setting.MailService == nil { ctx.Data["IsResetDisable"] = true ctx.HTML(200, FORGOT_PASSWORD) return } ctx.Data["IsResetRequest"] = true ctx.HTML(200, FORGOT_PASSWORD) }
func Migrate(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("new_migrate") ctx.Data["private"] = ctx.User.LastRepoVisibility ctxUser := checkContextUser(ctx, ctx.QueryInt64("org")) if ctx.Written() { return } ctx.Data["ContextUser"] = ctxUser ctx.HTML(200, MIGRATE) }
func DeployKeys(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings.deploy_keys") ctx.Data["PageIsSettingsKeys"] = true keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID) if err != nil { ctx.Handle(500, "ListDeployKeys", err) return } ctx.Data["Deploykeys"] = keys ctx.HTML(200, DEPLOY_KEYS) }
func GitHooks(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings.githooks") ctx.Data["PageIsSettingsGitHooks"] = true hooks, err := ctx.Repo.GitRepo.Hooks() if err != nil { ctx.Handle(500, "Hooks", err) return } ctx.Data["Hooks"] = hooks ctx.HTML(200, GITHOOKS) }
func NewAuthSource(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("admin.auths.new") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminAuthentications"] = true ctx.Data["type"] = models.LDAP ctx.Data["CurTypeName"] = models.LoginNames[models.LDAP] ctx.Data["smtp_auth"] = "PLAIN" ctx.Data["is_active"] = true ctx.Data["AuthSources"] = authSources ctx.Data["SMTPAuths"] = models.SMTPAuths ctx.HTML(200, AUTH_NEW) }
func WebHooksEdit(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook") ctx.Data["PageIsSettingsHooks"] = true ctx.Data["PageIsSettingsHooksEdit"] = true orCtx, w := checkWebhook(ctx) if ctx.Written() { return } ctx.Data["Webhook"] = w ctx.HTML(200, orCtx.NewTemplate) }
func SignUp(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("sign_up") ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha if setting.Service.DisableRegistration { ctx.Data["DisableRegistration"] = true ctx.HTML(200, SIGNUP) return } ctx.HTML(200, SIGNUP) }
func CreatePost(ctx *middleware.Context, form auth.CreateOrgForm) { ctx.Data["Title"] = ctx.Tr("new_org") if ctx.HasError() { ctx.HTML(200, CREATE) return } org := &models.User{ Name: form.OrgName, IsActive: true, Type: models.ORGANIZATION, } if err := models.CreateOrganization(org, ctx.User); err != nil { ctx.Data["Err_OrgName"] = true switch { case models.IsErrUserAlreadyExist(err): ctx.RenderWithErr(ctx.Tr("form.org_name_been_taken"), CREATE, &form) case models.IsErrNameReserved(err): ctx.RenderWithErr(ctx.Tr("org.form.name_reserved", err.(models.ErrNameReserved).Name), CREATE, &form) case models.IsErrNamePatternNotAllowed(err): ctx.RenderWithErr(ctx.Tr("org.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), CREATE, &form) default: ctx.Handle(500, "CreateOrganization", err) } return } log.Trace("Organization created: %s", org.Name) ctx.Redirect(setting.AppSubUrl + "/org/" + form.OrgName + "/dashboard") }
func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) { ctx.Data["Title"] = ctx.Tr("new_migrate") ctxUser := checkContextUser(ctx, form.Uid) if ctx.Written() { return } ctx.Data["ContextUser"] = ctxUser if ctx.HasError() { ctx.HTML(200, MIGRATE) return } // Remote address can be HTTP/HTTPS/Git URL or local path. // Note: remember to change api/v1/repo.go: MigrateRepo // FIXME: merge these two functions with better error handling remoteAddr := form.CloneAddr if strings.HasPrefix(form.CloneAddr, "http://") || strings.HasPrefix(form.CloneAddr, "https://") || strings.HasPrefix(form.CloneAddr, "git://") { u, err := url.Parse(form.CloneAddr) if err != nil { ctx.Data["Err_CloneAddr"] = true ctx.RenderWithErr(ctx.Tr("form.url_error"), MIGRATE, &form) return } if len(form.AuthUsername) > 0 || len(form.AuthPassword) > 0 { u.User = url.UserPassword(form.AuthUsername, form.AuthPassword) } remoteAddr = u.String() } else if !com.IsDir(remoteAddr) { ctx.Data["Err_CloneAddr"] = true ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), MIGRATE, &form) return } repo, err := models.MigrateRepository(ctxUser, form.RepoName, form.Description, form.Private, form.Mirror, remoteAddr) if err == nil { log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName) ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + form.RepoName) return } if repo != nil { if errDelete := models.DeleteRepository(ctxUser.Id, repo.ID); errDelete != nil { log.Error(4, "DeleteRepository: %v", errDelete) } } if strings.Contains(err.Error(), "Authentication failed") || strings.Contains(err.Error(), " not found") || strings.Contains(err.Error(), "could not read Username") { ctx.Data["Err_Auth"] = true ctx.RenderWithErr(ctx.Tr("form.auth_failed", strings.Replace(err.Error(), ":"+form.AuthPassword+"@", ":<password>@", 1)), MIGRATE, &form) return } handleCreateError(ctx, err, "MigratePost", MIGRATE, &form) }
func NewTeamPost(ctx *middleware.Context, form auth.CreateTeamForm) { ctx.Data["Title"] = ctx.Org.Organization.FullName ctx.Data["PageIsOrgTeams"] = true ctx.Data["PageIsOrgTeamsNew"] = true ctx.Data["Team"] = &models.Team{} if ctx.HasError() { ctx.HTML(200, TEAM_NEW) return } // Validate permission level. var auth models.AccessMode switch form.Permission { case "read": auth = models.ACCESS_MODE_READ case "write": auth = models.ACCESS_MODE_WRITE case "admin": auth = models.ACCESS_MODE_ADMIN default: ctx.Error(401) return } org := ctx.Org.Organization t := &models.Team{ OrgID: org.Id, Name: form.TeamName, Description: form.Description, Authorize: auth, } if err := models.NewTeam(t); err != nil { switch err { case models.ErrTeamNameIllegal: ctx.Data["Err_TeamName"] = true ctx.RenderWithErr(ctx.Tr("form.illegal_team_name"), TEAM_NEW, &form) case models.ErrTeamAlreadyExist: ctx.Data["Err_TeamName"] = true ctx.RenderWithErr(ctx.Tr("form.team_name_been_taken"), TEAM_NEW, &form) default: ctx.Handle(500, "NewTeam", err) } return } log.Trace("Team created: %s/%s", org.Name, t.Name) ctx.Redirect(ctx.Org.OrgLink + "/teams/" + t.LowerName) }
func SlackHooksNewPost(ctx *middleware.Context, form auth.NewSlackHookForm) { ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["PageIsSettingsHooks"] = true ctx.Data["PageIsSettingsHooksNew"] = true ctx.Data["Webhook"] = models.Webhook{HookEvent: &models.HookEvent{}} orCtx, err := getOrgRepoCtx(ctx) if err != nil { ctx.Handle(500, "getOrgRepoCtx", err) return } if ctx.HasError() { ctx.HTML(200, orCtx.NewTemplate) return } meta, err := json.Marshal(&models.SlackMeta{ Channel: form.Channel, Username: form.Username, IconURL: form.IconURL, Color: form.Color, }) if err != nil { ctx.Handle(500, "Marshal", err) return } w := &models.Webhook{ RepoID: orCtx.RepoID, URL: form.PayloadURL, ContentType: models.JSON, HookEvent: ParseHookEvent(form.WebhookForm), IsActive: form.Active, HookTaskType: models.SLACK, Meta: string(meta), OrgID: orCtx.OrgID, } if err := w.UpdateEvent(); err != nil { ctx.Handle(500, "UpdateEvent", err) return } else if err := models.CreateWebhook(w); err != nil { ctx.Handle(500, "CreateWebhook", err) return } ctx.Flash.Success(ctx.Tr("repo.settings.add_hook_success")) ctx.Redirect(orCtx.Link + "/settings/hooks") }
func EditAuthSource(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("admin.auths.edit") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminAuthentications"] = true ctx.Data["SMTPAuths"] = models.SMTPAuths source, err := models.GetLoginSourceByID(ctx.ParamsInt64(":authid")) if err != nil { ctx.Handle(500, "GetLoginSourceByID", err) return } ctx.Data["Source"] = source ctx.HTML(200, AUTH_EDIT) }
func Webhooks(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings.hooks") ctx.Data["PageIsSettingsHooks"] = true ctx.Data["BaseLink"] = ctx.Repo.RepoLink ctx.Data["Description"] = ctx.Tr("repo.settings.hooks_desc", "https://github.com/gogits/go-gogs-client/wiki/Repositories---Webhooks") ws, err := models.GetWebhooksByRepoId(ctx.Repo.Repository.ID) if err != nil { ctx.Handle(500, "GetWebhooksByRepoId", err) return } ctx.Data["Webhooks"] = ws ctx.HTML(200, HOOKS) }
func Authentications(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("admin.authentication") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminAuthentications"] = true var err error ctx.Data["Sources"], err = models.LoginSources() if err != nil { ctx.Handle(500, "LoginSources", err) return } ctx.Data["Total"] = models.CountLoginSources() ctx.HTML(200, AUTHS) }
func Config(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("admin.config") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminConfig"] = true ctx.Data["AppUrl"] = setting.AppUrl ctx.Data["Domain"] = setting.Domain ctx.Data["OfflineMode"] = setting.OfflineMode ctx.Data["DisableRouterLog"] = setting.DisableRouterLog ctx.Data["RunUser"] = setting.RunUser ctx.Data["RunMode"] = strings.Title(macaron.Env) ctx.Data["RepoRootPath"] = setting.RepoRootPath ctx.Data["StaticRootPath"] = setting.StaticRootPath ctx.Data["LogRootPath"] = setting.LogRootPath ctx.Data["ScriptType"] = setting.ScriptType ctx.Data["ReverseProxyAuthUser"] = setting.ReverseProxyAuthUser ctx.Data["Service"] = setting.Service ctx.Data["DbCfg"] = models.DbCfg ctx.Data["Webhook"] = setting.Webhook ctx.Data["MailerEnabled"] = false if setting.MailService != nil { ctx.Data["MailerEnabled"] = true ctx.Data["Mailer"] = setting.MailService } ctx.Data["CacheAdapter"] = setting.CacheAdapter ctx.Data["CacheInternal"] = setting.CacheInternal ctx.Data["CacheConn"] = setting.CacheConn ctx.Data["SessionConfig"] = setting.SessionConfig ctx.Data["PictureService"] = setting.PictureService ctx.Data["DisableGravatar"] = setting.DisableGravatar type logger struct { Mode, Config string } loggers := make([]*logger, len(setting.LogModes)) for i := range setting.LogModes { loggers[i] = &logger{setting.LogModes[i], setting.LogConfigs[i]} } ctx.Data["Loggers"] = loggers ctx.HTML(200, CONFIG) }
func ActivateEmail(ctx *middleware.Context) { code := ctx.Query("code") email_string := ctx.Query("email") // Verify code. if email := models.VerifyActiveEmailCode(code, email_string); email != nil { if err := email.Activate(); err != nil { ctx.Handle(500, "ActivateEmail", err) } log.Trace("Email activated: %s", email.Email) ctx.Flash.Success(ctx.Tr("settings.add_email_successs")) } ctx.Redirect(setting.AppSubUrl + "/user/settings/email") return }