func SettingsApplications(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["PageIsUserSettings"] = true ctx.Data["PageIsSettingsApplications"] = true // Delete access token. remove, _ := com.StrTo(ctx.Query("remove")).Int64() if remove > 0 { if err := models.DeleteAccessTokenById(remove); err != nil { ctx.Handle(500, "DeleteAccessTokenById", err) return } ctx.Flash.Success(ctx.Tr("settings.delete_token_success")) ctx.Redirect(setting.AppSubUrl + "/user/settings/applications") return } tokens, err := models.ListAccessTokens(ctx.User.Id) if err != nil { ctx.Handle(500, "ListAccessTokens", err) return } ctx.Data["Tokens"] = tokens ctx.HTML(200, SETTINGS_APPLICATIONS) }
func UpdateIssueTitle(ctx *middleware.Context) { issue := getActionIssue(ctx) if ctx.Written() { return } if !ctx.IsSigned || (ctx.User.Id != issue.PosterID && !ctx.Repo.IsAdmin()) { ctx.Error(403) return } issue.Name = ctx.Query("title") if len(issue.Name) == 0 { ctx.Error(204) return } if err := models.UpdateIssue(issue); err != nil { ctx.Handle(500, "UpdateIssue", err) return } ctx.JSON(200, map[string]interface{}{ "title": issue.Name, }) }
func UpdateCommentContent(ctx *middleware.Context) { comment, err := models.GetCommentByID(ctx.ParamsInt64(":id")) if err != nil { if models.IsErrCommentNotExist(err) { ctx.Error(404, "GetCommentByID") } else { ctx.Handle(500, "GetCommentByID", err) } return } if !ctx.IsSigned || (ctx.User.Id != comment.PosterID && !ctx.Repo.IsAdmin()) { ctx.Error(403) return } else if comment.Type != models.COMMENT_TYPE_COMMENT { ctx.Error(204) return } comment.Content = ctx.Query("content") if len(comment.Content) == 0 { ctx.JSON(200, map[string]interface{}{ "content": "", }) return } if err := models.UpdateComment(comment); err != nil { ctx.Handle(500, "UpdateComment", err) return } ctx.JSON(200, map[string]interface{}{ "content": string(base.RenderMarkdown([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())), }) }
func SettingsDelete(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["PageIsSettingsDelete"] = true if ctx.Req.Method == "POST" { if _, err := models.UserSignIn(ctx.User.Name, ctx.Query("password")); err != nil { if models.IsErrUserNotExist(err) { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), SETTINGS_DELETE, nil) } else { ctx.Handle(500, "UserSignIn", err) } return } if err := models.DeleteUser(ctx.User); err != nil { switch { case models.IsErrUserOwnRepos(err): ctx.Flash.Error(ctx.Tr("form.still_own_repo")) ctx.Redirect(setting.AppSubUrl + "/user/settings/delete") case models.IsErrUserHasOrgs(err): ctx.Flash.Error(ctx.Tr("form.still_has_org")) ctx.Redirect(setting.AppSubUrl + "/user/settings/delete") default: ctx.Handle(500, "DeleteUser", err) } } else { log.Trace("Account deleted: %s", ctx.User.Name) ctx.Redirect(setting.AppSubUrl + "/") } return } ctx.HTML(200, SETTINGS_DELETE) }
func Dashboard(ctx *middleware.Context) { ctx.Data["Title"] = "Admin Dashboard" ctx.Data["PageIsDashboard"] = true // Run operation. op, _ := base.StrTo(ctx.Query("op")).Int() if op > 0 { var err error var success string switch AdminOperation(op) { case CLEAN_UNBIND_OAUTH: success = "All unbind OAuthes have been deleted." err = models.CleanUnbindOauth() case CLEAN_INACTIVATE_USER: success = "All inactivate accounts have been deleted." err = models.DeleteInactivateUsers() } if err != nil { ctx.Flash.Error(err.Error()) } else { ctx.Flash.Success(success) } ctx.Redirect("/admin") return } ctx.Data["Stats"] = models.GetStatistic() updateSystemStatus() ctx.Data["SysStatus"] = sysStatus ctx.HTML(200, DASHBOARD) }
func Milestones(ctx *middleware.Context) { ctx.Data["Title"] = "Milestones" ctx.Data["IsRepoToolbarIssues"] = true ctx.Data["IsRepoToolbarIssuesList"] = true isShowClosed := ctx.Query("state") == "closed" miles, err := models.GetMilestones(ctx.Repo.Repository.Id, isShowClosed) if err != nil { ctx.Handle(500, "issue.Milestones(GetMilestones)", err) return } for _, m := range miles { m.RenderedContent = string(base.RenderMarkdown([]byte(m.Content), ctx.Repo.RepoLink)) m.CalOpenIssues() } ctx.Data["Milestones"] = miles if isShowClosed { ctx.Data["State"] = "closed" } else { ctx.Data["State"] = "open" } ctx.HTML(200, MILESTONE) }
func Webhooks(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("org.settings") ctx.Data["PageIsSettingsHooks"] = true ctx.Data["BaseLink"] = ctx.Org.OrgLink ctx.Data["Description"] = ctx.Tr("org.settings.hooks_desc") // Delete web hook. remove := com.StrTo(ctx.Query("remove")).MustInt64() if remove > 0 { if err := models.DeleteWebhook(remove); err != nil { ctx.Handle(500, "DeleteWebhook", err) return } ctx.Flash.Success(ctx.Tr("repo.settings.remove_hook_success")) ctx.Redirect(ctx.Org.OrgLink + "/settings/hooks") return } ws, err := models.GetWebhooksByOrgId(ctx.Org.Organization.Id) if err != nil { ctx.Handle(500, "GetWebhooksByOrgId", err) return } ctx.Data["Webhooks"] = ws ctx.HTML(200, SETTINGS_HOOKS) }
func Delete(ctx *middleware.Context) { ctx.Data["Title"] = "Delete Account" ctx.Data["PageIsUserSetting"] = true ctx.Data["IsUserPageSettingDelete"] = true if ctx.Req.Method == "GET" { ctx.HTML(200, "user/delete") return } tmpUser := models.User{Passwd: ctx.Query("password")} tmpUser.EncodePasswd() if len(tmpUser.Passwd) == 0 || tmpUser.Passwd != ctx.User.Passwd { ctx.Data["HasError"] = true ctx.Data["ErrorMsg"] = "Password is not correct. Make sure you are owner of this account." } else { if err := models.DeleteUser(ctx.User); err != nil { ctx.Data["HasError"] = true switch err { case models.ErrUserOwnRepos: ctx.Data["ErrorMsg"] = "Your account still have ownership of repository, you have to delete or transfer them first." default: ctx.Handle(200, "user.Delete", err) return } } else { ctx.Redirect("/") return } } ctx.HTML(200, "user/delete") }
func Profile(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = "Profile" // TODO: Need to check view self or others. user, err := models.GetUserByName(params["username"]) if err != nil { ctx.Handle(200, "user.Profile", err) return } ctx.Data["Owner"] = user tab := ctx.Query("tab") ctx.Data["TabName"] = tab switch tab { case "activity": feeds, err := models.GetFeeds(user.Id, 0, true) if err != nil { ctx.Handle(200, "user.Profile", err) return } ctx.Data["Feeds"] = feeds default: repos, err := models.GetRepositories(user) if err != nil { ctx.Handle(200, "user.Profile", err) return } ctx.Data["Repos"] = repos } ctx.Data["PageIsUserProfile"] = true ctx.HTML(200, "user/profile") }
func SearchUsers(ctx *middleware.Context) { opt := models.SearchOption{ Keyword: ctx.Query("q"), Limit: com.StrTo(ctx.Query("limit")).MustInt(), } if opt.Limit == 0 { opt.Limit = 10 } us, err := models.SearchUserByName(opt) if err != nil { ctx.JSON(500, map[string]interface{}{ "ok": false, "error": err.Error(), }) return } results := make([]*api.User, len(us)) for i := range us { results[i] = &api.User{ UserName: us[i].Name, AvatarUrl: us[i].AvatarLink(), FullName: us[i].FullName, } } ctx.Render.JSON(200, map[string]interface{}{ "ok": true, "data": results, }) }
func Create(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("new_repo") // Give default value for template to render. ctx.Data["gitignore"] = "0" ctx.Data["license"] = "0" ctx.Data["Gitignores"] = models.Gitignores ctx.Data["Licenses"] = models.Licenses ctxUser := ctx.User if orgId := com.StrTo(ctx.Query("org")).MustInt64(); orgId > 0 { org, err := models.GetUserById(orgId) if err != nil && err != models.ErrUserNotExist { ctx.Handle(500, "GetUserById", err) return } ctxUser = org } ctx.Data["ContextUser"] = ctxUser if err := ctx.User.GetOrganizations(); err != nil { ctx.Handle(500, "GetOrganizations", err) return } ctx.Data["Orgs"] = ctx.User.Orgs ctx.HTML(200, CREATE) }
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 { 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): %v", ctx.Params(":action"), err) ctx.JSON(200, map[string]interface{}{ "ok": false, "err": err.Error(), }) return } ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName + "/repositories") }
func SettingsSocial(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["PageIsUserSettings"] = true ctx.Data["PageIsSettingsSocial"] = true // Unbind social account. remove, _ := com.StrTo(ctx.Query("remove")).Int64() if remove > 0 { if err := models.DeleteOauth2ById(remove); err != nil { ctx.Handle(500, "DeleteOauth2ById", err) return } ctx.Flash.Success(ctx.Tr("settings.unbind_success")) ctx.Redirect("/user/settings/social") return } socials, err := models.GetOauthByUserId(ctx.User.Id) if err != nil { ctx.Handle(500, "GetOauthByUserId", err) return } ctx.Data["Socials"] = socials ctx.HTML(200, SETTINGS_SOCIAL) }
// FIXME: split to two different functions and pages to handle access token and oauth2 func SettingsApplicationsPost(ctx *middleware.Context, form auth.NewAccessTokenForm) { ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["PageIsUserSettings"] = true ctx.Data["PageIsSettingsApplications"] = true switch ctx.Query("type") { case "token": if ctx.HasError() { ctx.HTML(200, SETTINGS_APPLICATIONS) return } t := &models.AccessToken{ UID: ctx.User.Id, Name: form.Name, } if err := models.NewAccessToken(t); err != nil { ctx.Handle(500, "NewAccessToken", err) return } ctx.Flash.Success(ctx.Tr("settings.generate_token_succees")) ctx.Flash.Info(t.Sha1) } ctx.Redirect(setting.AppSubUrl + "/user/settings/applications") }
func Action(ctx *middleware.Context) { u := GetUserByParams(ctx) if ctx.Written() { return } var err error switch ctx.Params(":action") { case "follow": err = models.FollowUser(ctx.User.Id, u.Id) case "unfollow": err = models.UnfollowUser(ctx.User.Id, u.Id) } if err != nil { ctx.Handle(500, fmt.Sprintf("Action (%s)", ctx.Params(":action")), err) return } redirectTo := ctx.Query("redirect_to") if len(redirectTo) == 0 { redirectTo = u.HomeLink() } ctx.Redirect(redirectTo) }
func Collaboration(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["PageIsSettingsCollaboration"] = true // Delete collaborator. remove := strings.ToLower(ctx.Query("remove")) if len(remove) > 0 && remove != ctx.Repo.Owner.LowerName { u, err := models.GetUserByName(remove) if err != nil { ctx.Handle(500, "GetUserByName", err) return } if err := ctx.Repo.Repository.DeleteCollaborator(u); err != nil { ctx.Handle(500, "DeleteCollaborator", err) return } ctx.Flash.Success(ctx.Tr("repo.settings.remove_collaborator_success")) ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration") return } users, err := ctx.Repo.Repository.GetCollaborators() if err != nil { ctx.Handle(500, "GetCollaborators", err) return } ctx.Data["Collaborators"] = users ctx.HTML(200, COLLABORATION) }
func Action(ctx *middleware.Context, params martini.Params) { var err error switch params["action"] { case "watch": err = models.WatchRepo(ctx.User.Id, ctx.Repo.Repository.Id, true) case "unwatch": err = models.WatchRepo(ctx.User.Id, ctx.Repo.Repository.Id, false) case "desc": if !ctx.Repo.IsOwner { ctx.Error(404) return } ctx.Repo.Repository.Description = ctx.Query("desc") ctx.Repo.Repository.Website = ctx.Query("site") err = models.UpdateRepository(ctx.Repo.Repository) } if err != nil { log.Error("repo.Action(%s): %v", params["action"], err) ctx.JSON(200, map[string]interface{}{ "ok": false, "err": err.Error(), }) return } ctx.JSON(200, map[string]interface{}{ "ok": true, }) }
func Dashboard(ctx *middleware.Context) { ctx.Data["Title"] = "Admin Dashboard" ctx.Data["PageIsDashboard"] = true // Run operation. op, _ := base.StrTo(ctx.Query("op")).Int() if op > 0 { var err error var success string switch op { case OT_CLEAN_OAUTH: success = "All unbind OAuthes have been deleted." err = models.CleanUnbindOauth() } if err != nil { ctx.Flash.Error(err.Error()) } else { ctx.Flash.Success(success) } ctx.Redirect("/admin") return } ctx.Data["Stats"] = models.GetStatistic() updateSystemStatus() ctx.Data["SysStatus"] = sysStatus ctx.HTML(200, "admin/dashboard") }
func SearchCommits(ctx *middleware.Context, params martini.Params) { ctx.Data["IsSearchPage"] = true ctx.Data["IsRepoToolbarCommits"] = true keyword := ctx.Query("q") if len(keyword) == 0 { ctx.Redirect(ctx.Repo.RepoLink + "/commits/" + ctx.Repo.BranchName) return } userName := params["username"] repoName := params["reponame"] brs, err := ctx.Repo.GitRepo.GetBranches() if err != nil { ctx.Handle(500, "repo.SearchCommits(GetBranches)", err) return } else if len(brs) == 0 { ctx.Handle(404, "repo.SearchCommits(GetBranches)", nil) return } commits, err := ctx.Repo.Commit.SearchCommits(keyword) if err != nil { ctx.Handle(500, "repo.SearchCommits(SearchCommits)", err) return } ctx.Data["Keyword"] = keyword ctx.Data["Username"] = userName ctx.Data["Reponame"] = repoName ctx.Data["CommitCount"] = commits.Len() ctx.Data["Commits"] = commits ctx.HTML(200, "repo/commits") }
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 err == models.ErrUserNotExist { 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 SettingsDelete(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("org.settings") ctx.Data["PageIsSettingsDelete"] = true org := ctx.Org.Organization if ctx.Req.Method == "POST" { if _, err := models.UserSignIn(ctx.User.Name, ctx.Query("password")); err != nil { if models.IsErrUserNotExist(err) { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), SETTINGS_DELETE, nil) } else { ctx.Handle(500, "UserSignIn", err) } return } if err := models.DeleteOrganization(org); err != nil { if models.IsErrUserOwnRepos(err) { ctx.Flash.Error(ctx.Tr("form.org_still_own_repo")) ctx.Redirect(ctx.Org.OrgLink + "/settings/delete") } else { ctx.Handle(500, "DeleteOrganization", err) } } else { log.Trace("Organization deleted: %s", org.Name) ctx.Redirect(setting.AppSubUrl + "/") } return } ctx.HTML(200, SETTINGS_DELETE) }
func Collaboration(ctx *middleware.Context) { repoLink := strings.TrimPrefix(ctx.Repo.RepoLink, "/") ctx.Data["IsRepoToolbarCollaboration"] = true ctx.Data["Title"] = repoLink + " - collaboration" // Delete collaborator. remove := strings.ToLower(ctx.Query("remove")) if len(remove) > 0 && remove != ctx.Repo.Owner.LowerName { if err := models.DeleteAccess(&models.Access{UserName: remove, RepoName: repoLink}); err != nil { ctx.Handle(500, "setting.Collaboration(DeleteAccess)", err) return } ctx.Flash.Success("Collaborator has been removed.") ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration") return } names, err := models.GetCollaboratorNames(repoLink) if err != nil { ctx.Handle(500, "setting.Collaboration(GetCollaborators)", err) return } us := make([]*models.User, len(names)) for i, name := range names { us[i], err = models.GetUserByName(name) if err != nil { ctx.Handle(500, "setting.Collaboration(GetUserByName)", err) return } } ctx.Data["Collaborators"] = us ctx.HTML(200, "repo/collaboration") }
func Webhooks(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings") ctx.Data["PageIsSettingsHooks"] = true // Delete web hook. remove := com.StrTo(ctx.Query("remove")).MustInt64() if remove > 0 { if err := models.DeleteWebhook(remove); err != nil { ctx.Handle(500, "DeleteWebhook", err) return } ctx.Flash.Success(ctx.Tr("repo.settings.remove_hook_success")) ctx.Redirect(ctx.Repo.RepoLink + "/settings/hooks") return } 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 WebHooks(ctx *middleware.Context) { ctx.Data["IsRepoToolbarWebHooks"] = true ctx.Data["Title"] = strings.TrimPrefix(ctx.Repo.RepoLink, "/") + " - Webhooks" // Delete webhook. remove, _ := base.StrTo(ctx.Query("remove")).Int64() if remove > 0 { if err := models.DeleteWebhook(remove); err != nil { ctx.Handle(500, "setting.WebHooks(DeleteWebhook)", err) return } ctx.Flash.Success("Webhook has been removed.") ctx.Redirect(ctx.Repo.RepoLink + "/settings/hooks") return } ws, err := models.GetWebhooksByRepoId(ctx.Repo.Repository.Id) if err != nil { ctx.Handle(500, "setting.WebHooks(GetWebhooksByRepoId)", err) return } ctx.Data["Webhooks"] = ws ctx.HTML(200, "repo/hooks") }
func DeletePost(ctx *middleware.Context) { ctx.Data["Title"] = "Delete Account" ctx.Data["PageIsUserSetting"] = true ctx.Data["IsUserPageSettingDelete"] = true tmpUser := models.User{ Passwd: ctx.Query("password"), Salt: ctx.User.Salt, } tmpUser.EncodePasswd() if tmpUser.Passwd != ctx.User.Passwd { ctx.Flash.Error("Password is not correct. Make sure you are owner of this account.") } else { if err := models.DeleteUser(ctx.User); err != nil { switch err { case models.ErrUserOwnRepos: ctx.Flash.Error("Your account still have ownership of repository, you have to delete or transfer them first.") default: ctx.Handle(500, "user.Delete", err) return } } else { ctx.Redirect("/") return } } ctx.Redirect("/user/delete") }
func SearchCommits(ctx *middleware.Context) { ctx.Data["PageIsCommits"] = true keyword := ctx.Query("q") if len(keyword) == 0 { ctx.Redirect(ctx.Repo.RepoLink + "/commits/" + ctx.Repo.BranchName) return } commits, err := ctx.Repo.Commit.SearchCommits(keyword) if err != nil { ctx.Handle(500, "SearchCommits", err) return } commits = RenderIssueLinks(commits, ctx.Repo.RepoLink) commits = models.ValidateCommitsWithEmails(commits) ctx.Data["Commits"] = commits ctx.Data["Keyword"] = keyword ctx.Data["Username"] = ctx.Repo.Owner.Name ctx.Data["Reponame"] = ctx.Repo.Repository.Name ctx.Data["CommitCount"] = commits.Len() ctx.Data["Branch"] = ctx.Repo.BranchName ctx.HTML(200, COMMITS) }
func Profile(ctx *middleware.Context) { ctx.Data["Title"] = "Profile" ctx.Data["PageIsUserProfile"] = true uname := ctx.Params(":username") // Special handle for FireFox requests favicon.ico. if uname == "favicon.ico" { ctx.Redirect(setting.AppSubUrl + "/img/favicon.png") return } else if strings.HasSuffix(uname, ".png") { ctx.Error(404) return } isShowKeys := false if strings.HasSuffix(uname, ".keys") { isShowKeys = true uname = strings.TrimSuffix(uname, ".keys") } u, err := models.GetUserByName(uname) if err != nil { if models.IsErrUserNotExist(err) { ctx.Handle(404, "GetUserByName", err) } else { ctx.Handle(500, "GetUserByName", err) } return } // Show SSH keys. if isShowKeys { ShowSSHKeys(ctx, u.Id) return } if u.IsOrganization() { showOrgProfile(ctx) return } ctx.Data["Owner"] = u tab := ctx.Query("tab") ctx.Data["TabName"] = tab switch tab { case "activity": retrieveFeeds(ctx, u.Id, 0, true) if ctx.Written() { return } default: ctx.Data["Repos"], err = models.GetRepositories(u.Id, ctx.IsSigned && ctx.User.Id == u.Id) if err != nil { ctx.Handle(500, "GetRepositories", err) return } } ctx.HTML(200, PROFILE) }
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 SettingSocial(ctx *middleware.Context) { ctx.Data["Title"] = "Social Account" ctx.Data["PageIsUserSetting"] = true ctx.Data["IsUserPageSettingSocial"] = true // Unbind social account. remove, _ := base.StrTo(ctx.Query("remove")).Int64() if remove > 0 { if err := models.DeleteOauth2ById(remove); err != nil { ctx.Handle(500, "user.SettingSocial(DeleteOauth2ById)", err) return } ctx.Flash.Success("OAuth2 has been unbinded.") ctx.Redirect("/user/settings/social") return } socials, err := models.GetOauthByUserId(ctx.User.Id) if err != nil { ctx.Handle(500, "user.SettingSocial(GetOauthByUserId)", err) return } ctx.Data["Socials"] = socials ctx.HTML(200, "user/social") }
func FileHistory(ctx *middleware.Context) { ctx.Data["IsRepoToolbarCommits"] = true fileName := ctx.Params("*") if len(fileName) == 0 { Commits(ctx) return } userName := ctx.Repo.Owner.Name repoName := ctx.Repo.Repository.Name branchName := ctx.Params(":branchname") brs, err := ctx.Repo.GitRepo.GetBranches() if err != nil { ctx.Handle(500, "GetBranches", err) return } else if len(brs) == 0 { ctx.Handle(404, "GetBranches", nil) return } commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName) if err != nil { ctx.Handle(500, "repo.FileHistory(GetCommitsCount)", err) return } else if commitsCount == 0 { ctx.Handle(404, "repo.FileHistory", nil) return } // Calculate and validate page number. page := com.StrTo(ctx.Query("p")).MustInt() if page < 1 { page = 1 } lastPage := page - 1 if lastPage < 0 { lastPage = 0 } nextPage := page + 1 if nextPage*50 > commitsCount { nextPage = 0 } ctx.Data["Commits"], err = ctx.Repo.GitRepo.CommitsByFileAndRange( branchName, fileName, page) if err != nil { ctx.Handle(500, "repo.FileHistory(CommitsByRange)", err) return } ctx.Data["Username"] = userName ctx.Data["Reponame"] = repoName ctx.Data["FileName"] = fileName ctx.Data["CommitCount"] = commitsCount ctx.Data["LastPageNum"] = lastPage ctx.Data["NextPageNum"] = nextPage ctx.HTML(200, COMMITS) }