Ejemplo n.º 1
0
func adminSupportOpen(w http.ResponseWriter, r *http.Request, session *lobster.Session, frameParams lobster.FrameParams) {
	userId, err := strconv.Atoi(mux.Vars(r)["id"])
	if err != nil {
		lobster.RedirectMessage(w, r, "/admin/support", L.FormattedError("invalid_user"))
		return
	}
	user := lobster.UserDetails(userId)
	if user == nil {
		lobster.RedirectMessage(w, r, "/admin/support", L.FormattedError("user_not_found"))
		return
	}

	if r.Method == "POST" {
		form := new(AdminSupportOpenForm)
		err := decoder.Decode(form, r.PostForm)
		if err != nil {
			http.Redirect(w, r, fmt.Sprintf("/admin/support/open/%d", userId), 303)
			return
		}

		ticketId, err := ticketOpen(form.UserId, form.Name, form.Message, true)
		if err != nil {
			lobster.RedirectMessage(w, r, fmt.Sprintf("/admin/support/open/%d", userId), L.FormatError(err))
		} else {
			http.Redirect(w, r, fmt.Sprintf("/admin/support/%d", ticketId), 303)
		}
		return
	}

	params := new(AdminSupportOpenParams)
	params.Frame = frameParams
	params.User = user
	params.Token = lobster.CSRFGenerate(session)
	lobster.RenderTemplate(w, "admin", "support_open", params)
}
Ejemplo n.º 2
0
func panelSupportOpen(w http.ResponseWriter, r *http.Request, session *lobster.Session, frameParams lobster.FrameParams) {
	if r.Method == "POST" {
		form := new(SupportOpenForm)
		err := decoder.Decode(form, r.PostForm)
		if err != nil {
			http.Redirect(w, r, "/panel/support/open", 303)
			return
		}

		ticketId, err := ticketOpen(session.UserId, form.Name, form.Message, false)
		if err != nil {
			lobster.RedirectMessage(w, r, "/panel/support/open", L.FormatError(err))
		} else {
			lobster.LogAction(session.UserId, lobster.ExtractIP(r.RemoteAddr), "Open ticket", fmt.Sprintf("Subject: %s; Ticket ID: %d", form.Name, ticketId))
			http.Redirect(w, r, fmt.Sprintf("/panel/support/%d", ticketId), 303)
		}
		return
	}

	lobster.RenderTemplate(
		w,
		"panel",
		"support_open",
		lobster.PanelFormParams{Frame: frameParams, Token: lobster.CSRFGenerate(session)},
	)
}
Ejemplo n.º 3
0
func (sp *StripePayment) form(w http.ResponseWriter, r *http.Request, session *lobster.Session, frameParams lobster.FrameParams) {
	cents, _ := strconv.ParseInt(r.URL.Query().Get("cents"), 10, 64)
	user := lobster.UserDetails(session.UserId)
	cfg := lobster.GetConfig()
	params := &StripeTemplateParams{
		Frame:    frameParams,
		Token:    lobster.CSRFGenerate(session),
		Key:      sp.publishableKey,
		Cents:    cents,
		Currency: cfg.Billing.Currency,
		Amount:   float64(cents) / 100,
		Email:    user.Email,
	}
	lobster.RenderTemplate(w, "panel", "stripe", params)
}
Ejemplo n.º 4
0
func adminSupportTicket(w http.ResponseWriter, r *http.Request, session *lobster.Session, frameParams lobster.FrameParams) {
	ticketId, err := strconv.Atoi(mux.Vars(r)["id"])
	if err != nil {
		lobster.RedirectMessage(w, r, "/admin/support", L.FormattedError("invalid_ticket"))
		return
	}
	ticket := TicketDetails(session.UserId, ticketId, true)
	if ticket == nil {
		lobster.RedirectMessage(w, r, "/admin/support", L.FormattedError("ticket_not_found"))
		return
	}

	params := AdminSupportTicketParams{}
	params.Frame = frameParams
	params.Ticket = ticket
	params.Token = lobster.CSRFGenerate(session)
	lobster.RenderTemplate(w, "admin", "support_ticket", params)
}