mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-01-22 17:22:15 +00:00
getting and setting of Codepoints
This commit is contained in:
parent
7581a7b2fd
commit
a1185b8194
2 changed files with 46 additions and 0 deletions
|
@ -23,6 +23,15 @@ public static IHtmlString NotificationCount(this HtmlHelper hpr, string uid)
|
|||
return hpr.Raw(usr.UnreadNotifications.ToString());
|
||||
}
|
||||
|
||||
internal static ApplicationUser GetUserFromToken(string token)
|
||||
{
|
||||
var db = new ApplicationDbContext();
|
||||
var t = db.OAuthTokens.FirstOrDefault(x => x.Id == token);
|
||||
if (t == null)
|
||||
return null;
|
||||
return db.Users.FirstOrDefault(x => x.Id == t.UserId);
|
||||
}
|
||||
|
||||
public static IHtmlString NewestUser(this HtmlHelper hpr)
|
||||
{
|
||||
var db = new ApplicationDbContext();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Script.Serialization;
|
||||
|
@ -11,6 +12,42 @@ namespace Project_Unite.Controllers
|
|||
{
|
||||
public class APIController : Controller
|
||||
{
|
||||
public ActionResult GetCodepoints()
|
||||
{
|
||||
try
|
||||
{
|
||||
string token = Request.Headers["Authentication"].Remove(0, 6);
|
||||
var user = ACL.GetUserFromToken(token);
|
||||
if (user == null)
|
||||
return new HttpStatusCodeResult(HttpStatusCode.Forbidden);
|
||||
return Content(user.Codepoints.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult SetCodepoints(long id)
|
||||
{
|
||||
try
|
||||
{
|
||||
string token = Request.Headers["Authentication"].Remove(0, 6);
|
||||
|
||||
var db = new ApplicationDbContext();
|
||||
var t = db.OAuthTokens.FirstOrDefault(x => x.Id == token);
|
||||
var user = db.Users.FirstOrDefault(x => x.Id == t.UserId);
|
||||
user.Codepoints = id;
|
||||
db.SaveChanges();
|
||||
return new HttpStatusCodeResult(200);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public JavaScriptSerializer Serializer
|
||||
{
|
||||
get; set;
|
||||
|
|
Loading…
Reference in a new issue