mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-01-22 17:22:15 +00:00
User-submitted quotes.
This commit is contained in:
parent
1dcba9a688
commit
82c0215b97
5 changed files with 198 additions and 0 deletions
82
Project-Unite/Controllers/QuotesController.cs
Normal file
82
Project-Unite/Controllers/QuotesController.cs
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using Microsoft.AspNet.Identity;
|
||||||
|
using Project_Unite.Models;
|
||||||
|
|
||||||
|
namespace Project_Unite.Controllers
|
||||||
|
{
|
||||||
|
[Authorize]
|
||||||
|
public class QuotesController : Controller
|
||||||
|
{
|
||||||
|
// GET: Quotes
|
||||||
|
public ActionResult Index()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public ActionResult Index(Models.Quote model)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
return View(model);
|
||||||
|
|
||||||
|
var db = new Models.ApplicationDbContext();
|
||||||
|
model.Id = (db.Quotes.Count() + 1).ToString();
|
||||||
|
model.IsApproved = false;
|
||||||
|
db.Quotes.Add(model);
|
||||||
|
db.SaveChanges();
|
||||||
|
|
||||||
|
var users = db.Users.ToArray();
|
||||||
|
foreach (var user in users)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (user.HighestRole.IsAdmin)
|
||||||
|
{
|
||||||
|
NotificationDaemon.NotifyUser(User.Identity.GetUserId(), user.Id, "New quote submitted.", "Please review user-submitted quotes.", Url.Action("ReviewAll"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
return View(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
[RequiresModerator]
|
||||||
|
public ActionResult ReviewAll()
|
||||||
|
{
|
||||||
|
var db = new ApplicationDbContext();
|
||||||
|
return View(db.Quotes.Where(x => x.IsApproved == false));
|
||||||
|
}
|
||||||
|
|
||||||
|
[RequiresModerator]
|
||||||
|
public ActionResult Deny(string id)
|
||||||
|
{
|
||||||
|
var db = new ApplicationDbContext();
|
||||||
|
var quote = db.Quotes.FirstOrDefault(x => x.Id == id);
|
||||||
|
if (quote == null)
|
||||||
|
return new HttpStatusCodeResult(404);
|
||||||
|
if (quote.IsApproved == true)
|
||||||
|
return new HttpStatusCodeResult(403);
|
||||||
|
db.Quotes.Remove(quote);
|
||||||
|
db.SaveChanges();
|
||||||
|
return RedirectToAction("ReviewAll");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[RequiresModerator]
|
||||||
|
public ActionResult Approve(string id)
|
||||||
|
{
|
||||||
|
var db = new ApplicationDbContext();
|
||||||
|
var quote = db.Quotes.FirstOrDefault(x => x.Id == id);
|
||||||
|
if (quote == null)
|
||||||
|
return new HttpStatusCodeResult(404);
|
||||||
|
quote.IsApproved = true;
|
||||||
|
db.SaveChanges();
|
||||||
|
return RedirectToAction("ReviewAll");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -228,10 +228,20 @@ public UserFollow[] Followers
|
||||||
public class Quote
|
public class Quote
|
||||||
{
|
{
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage ="Your quote must have an author name.", AllowEmptyStrings =false)]
|
||||||
|
[MaxLength(50, ErrorMessage ="Your author name must not exceed 50 characters.")]
|
||||||
public string AuthorId { get; set; }
|
public string AuthorId { get; set; }
|
||||||
|
|
||||||
|
[AllowHtml]
|
||||||
|
[Required(AllowEmptyStrings =false, ErrorMessage ="Trying to submit an empty quote, I see?")]
|
||||||
public string Body { get; set; }
|
public string Body { get; set; }
|
||||||
|
|
||||||
public string AuthorAvatar { get; set; }
|
public string AuthorAvatar { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage ="We must know what year this quote was said in.")]
|
||||||
public long Year { get; set; }
|
public long Year { get; set; }
|
||||||
|
public bool IsApproved { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BannedIP
|
public class BannedIP
|
||||||
|
|
|
@ -638,6 +638,7 @@
|
||||||
<Compile Include="Controllers\ModeratorController.cs" />
|
<Compile Include="Controllers\ModeratorController.cs" />
|
||||||
<Compile Include="Controllers\OAuth2Controller.cs" />
|
<Compile Include="Controllers\OAuth2Controller.cs" />
|
||||||
<Compile Include="Controllers\ProfilesController.cs" />
|
<Compile Include="Controllers\ProfilesController.cs" />
|
||||||
|
<Compile Include="Controllers\QuotesController.cs" />
|
||||||
<Compile Include="Controllers\SkinsController.cs" />
|
<Compile Include="Controllers\SkinsController.cs" />
|
||||||
<Compile Include="Controllers\StatsController.cs" />
|
<Compile Include="Controllers\StatsController.cs" />
|
||||||
<Compile Include="Controllers\WikiControllerController.cs" />
|
<Compile Include="Controllers\WikiControllerController.cs" />
|
||||||
|
@ -981,6 +982,8 @@
|
||||||
<Content Include="Views\Contests\Disqualify.cshtml" />
|
<Content Include="Views\Contests\Disqualify.cshtml" />
|
||||||
<Content Include="Views\Home\AboutUnite.cshtml" />
|
<Content Include="Views\Home\AboutUnite.cshtml" />
|
||||||
<Content Include="Views\Legal\Privacy.cshtml" />
|
<Content Include="Views\Legal\Privacy.cshtml" />
|
||||||
|
<Content Include="Views\Quotes\Index.cshtml" />
|
||||||
|
<Content Include="Views\Quotes\ReviewAll.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="App_Data\" />
|
<Folder Include="App_Data\" />
|
||||||
|
|
67
Project-Unite/Views/Quotes/Index.cshtml
Normal file
67
Project-Unite/Views/Quotes/Index.cshtml
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
@model Project_Unite.Models.Quote
|
||||||
|
@{
|
||||||
|
ViewBag.Title = "Quotes";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>Quotes</h2>
|
||||||
|
|
||||||
|
<p>Welcome to the ShiftOS Quotes Database! This page allows you to submit a quote to our Discord bot.</p>
|
||||||
|
|
||||||
|
@if (User.Identity.IsModerator())
|
||||||
|
{
|
||||||
|
<p>Click here to <a href="@Url.Action("ReviewAll")">review all quotes.</a></p>
|
||||||
|
}
|
||||||
|
|
||||||
|
<h3>Submit a quote</h3>
|
||||||
|
|
||||||
|
@using (Html.BeginForm())
|
||||||
|
{
|
||||||
|
@Html.AntiForgeryToken()
|
||||||
|
<div class="panel panel-danger">
|
||||||
|
<div class="panel-body">
|
||||||
|
@Html.ValidationSummary()
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<dl>
|
||||||
|
<dt>Quote Author</dt>
|
||||||
|
<dd>@Html.TextBoxFor(Model=>Model.AuthorId, new{@class="form-control"})</dd>
|
||||||
|
<dt>Quote Author Image URL (requires http:// or https://)</dt>
|
||||||
|
<dd>@Html.TextBoxFor(Model => Model.AuthorAvatar, new { @class = "form-control" })</dd>
|
||||||
|
<dt>Year</dt>
|
||||||
|
<dd>@Html.TextBoxFor(Model=>Model.Year, new { @type = "number", @class = "form-control" })</dd>
|
||||||
|
<dt>Quote body</dt>
|
||||||
|
<dd>@Html.TextAreaFor(Model => Model.AuthorId, new { @class = "form-control" })</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<input type="submit" value="Submit!" class="btn btn-primary" />
|
||||||
|
}
|
||||||
|
|
||||||
|
<hr/>
|
||||||
|
|
||||||
|
<h3>How to use the quote bot in Discord:</h3>
|
||||||
|
|
||||||
|
@Html.Markdown(@"To use the quote bot in our Discord server, simply join `#bot`, then type in `!quoteoftheday` and send it as a message and the moderator bot will show you the quote of the day.
|
||||||
|
|
||||||
|
To force a new quote of the day, simply type `!forcequote`. This pulls a random quote from the database, and will keep the quote for 24 hours.")
|
||||||
|
|
||||||
|
<h4>Bot rules</h4>
|
||||||
|
|
||||||
|
<p>Here is a quick reminder of the rules regarding both spam and bot usage inside our Discord server.</p>
|
||||||
|
|
||||||
|
<dl>
|
||||||
|
<dt>Section 2: Spam</dt>
|
||||||
|
<dd>
|
||||||
|
2A. Rapid-fire of messages whether they be different, similar, long or short, is not permitted, and the bot will shun you if you continue.<br/>
|
||||||
|
2B. Disrupting an on-going conversation is not genuinely appreciated. Please move to a different channel, preferrably #off-topic.<br/>
|
||||||
|
2C. Emoji and reaction spam is not appreciated.<br/>
|
||||||
|
2D. Mention-spamming staff and dev roles is not appreciated.<br/>
|
||||||
|
</dd>
|
||||||
|
<dt>Section 4: Bots</dt>
|
||||||
|
<dd>
|
||||||
|
4A. Selfbots must follow the Discord TOS, or we will boot you off the server.<br/>
|
||||||
|
4B. Use of bots must be done in #bot.<br/>
|
||||||
|
4C. If you want your bot on the server, please contact me.<br/>
|
||||||
|
4D. We reserve the right to boot your bot off the server if it breaks any server rules.<br/>
|
||||||
|
</dd>
|
||||||
|
</dl>
|
36
Project-Unite/Views/Quotes/ReviewAll.cshtml
Normal file
36
Project-Unite/Views/Quotes/ReviewAll.cshtml
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
@model IEnumerable<Project_Unite.Models.Quote>
|
||||||
|
@{
|
||||||
|
ViewBag.Title = "Review quotes";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2>Review Quotes</h2>
|
||||||
|
|
||||||
|
<p>Below is a list of all quotes that need moderator review.</p>
|
||||||
|
|
||||||
|
@if(Model.Count() == 0)
|
||||||
|
{
|
||||||
|
<p><em>No quotes to show!</em></p>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var quote in Model)
|
||||||
|
{
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-body">
|
||||||
|
<p><strong>
|
||||||
|
@if (!String.IsNullOrWhiteSpace(quote.AuthorAvatar))
|
||||||
|
{
|
||||||
|
<img src="@quote.AuthorAvatar" width="24" height="24" style="border-radius:100%" />
|
||||||
|
}
|
||||||
|
@quote.AuthorId </strong></p>
|
||||||
|
|
||||||
|
<p>@Html.Markdown(quote.Body)</p>
|
||||||
|
|
||||||
|
<p><em> - @quote.Year</em></p>
|
||||||
|
|
||||||
|
<a href="@Url.Action("Approve", new { id = quote.Id })" class="btn btn-primary"><span class="glyphicon glyphicon-ok"></span> Approve</a>
|
||||||
|
<a href="@Url.Action("Deny", new { id = quote.Id })" class="btn btn-danger"><span class="glyphicon glyphicon-ban-circle"></span> Deny & delete</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue