Example #1
0
File: repo.go Project: noikiy/gitea
func getForkRepository(ctx *middleware.Context) (*models.Repository, error) {
	forkId := ctx.QueryInt64("fork_id")
	ctx.Data["ForkId"] = forkId

	forkRepo, err := models.GetRepositoryById(forkId)
	if err != nil {
		return nil, fmt.Errorf("GetRepositoryById: %v", err)
	}
	ctx.Data["repo_name"] = forkRepo.Name
	ctx.Data["desc"] = forkRepo.Description

	if err = forkRepo.GetOwner(); err != nil {
		return nil, fmt.Errorf("GetOwner: %v", err)
	}
	ctx.Data["ForkFrom"] = forkRepo.Owner.Name + "/" + forkRepo.Name
	return forkRepo, nil
}
Example #2
0
File: repo.go Project: noikiy/gitea
func Migrate(ctx *middleware.Context) {
	ctx.Data["Title"] = ctx.Tr("new_migrate")

	ctxUser, err := checkContextUser(ctx, ctx.QueryInt64("org"))
	if err != nil {
		ctx.Handle(500, "checkContextUser", err)
		return
	}
	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, MIGRATE)
}
Example #3
0
File: repo.go Project: noikiy/gitea
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, err := checkContextUser(ctx, ctx.QueryInt64("org"))
	if err != nil {
		ctx.Handle(500, "checkContextUser", err)
		return
	}
	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)
}
Example #4
0
func SettingsEmailPost(ctx *middleware.Context, form auth.AddEmailForm) {
	ctx.Data["Title"] = ctx.Tr("settings")
	ctx.Data["PageIsUserSettings"] = true
	ctx.Data["PageIsSettingsEmails"] = true

	emails, err := models.GetEmailAddresses(ctx.User.Id)
	if err != nil {
		ctx.Handle(500, "GetEmailAddresses", err)
		return
	}
	ctx.Data["Emails"] = emails

	// Delete E-mail address.
	if ctx.Query("_method") == "DELETE" {
		id := ctx.QueryInt64("id")
		if id <= 0 {
			return
		}

		if err = models.DeleteEmailAddress(&models.EmailAddress{Id: id}); err != nil {
			ctx.Handle(500, "DeleteEmail", err)
		} else {
			log.Trace("Email address deleted: %s", ctx.User.Name)
			ctx.Redirect(setting.AppSubUrl + "/user/settings/email")
		}
		return
	}

	// Make emailaddress primary.
	if ctx.Query("_method") == "PRIMARY" {
		id := ctx.QueryInt64("id")
		if id <= 0 {
			return
		}

		if err = models.MakeEmailPrimary(&models.EmailAddress{Id: id}); err != nil {
			ctx.Handle(500, "MakeEmailPrimary", err)
		} else {
			log.Trace("Email made primary: %s", ctx.User.Name)
			ctx.Redirect(setting.AppSubUrl + "/user/settings/email")
		}
		return
	}

	// Add Email address.
	if ctx.HasError() {
		ctx.HTML(200, SETTINGS_EMAILS)
		return
	}

	cleanEmail := strings.Replace(form.Email, "\n", "", -1)
	e := &models.EmailAddress{
		Uid:         ctx.User.Id,
		Email:       cleanEmail,
		IsActivated: !setting.Service.RegisterEmailConfirm,
	}

	if err := models.AddEmailAddress(e); err != nil {
		if err == models.ErrEmailAlreadyUsed {
			ctx.RenderWithErr(ctx.Tr("form.email_been_used"), SETTINGS_EMAILS, &form)
			return
		}
		ctx.Handle(500, "AddEmailAddress", err)
		return
	} else {
		// Send confirmation e-mail
		if setting.Service.RegisterEmailConfirm {
			mailer.SendActivateEmail(ctx.Render, ctx.User, e)

			if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil {
				log.Error(4, "Set cache(MailResendLimit) fail: %v", err)
			}
			ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", cleanEmail, setting.Service.ActiveCodeLives/60))
		} else {
			ctx.Flash.Success(ctx.Tr("settings.add_email_success"))
		}

		log.Trace("Email address added: %s", e.Email)
		ctx.Redirect(setting.AppSubUrl + "/user/settings/email")
		return
	}

	ctx.HTML(200, SETTINGS_EMAILS)
}