diff options
| author | Michael <[email protected]> | 2017-04-30 11:34:16 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-04-30 11:34:16 -0400 |
| commit | a1185b8194e0a2bcea77a509179ec2b37ffea002 (patch) | |
| tree | 06b3cb90daa9266d6e9ba40338b9b504b1372cfd | |
| parent | 7581a7b2fdacd4325132baf0bec4973092449977 (diff) | |
| download | project-unite-a1185b8194e0a2bcea77a509179ec2b37ffea002.tar.gz project-unite-a1185b8194e0a2bcea77a509179ec2b37ffea002.tar.bz2 project-unite-a1185b8194e0a2bcea77a509179ec2b37ffea002.zip | |
getting and setting of Codepoints
| -rw-r--r-- | Project-Unite/ACL.cs | 9 | ||||
| -rw-r--r-- | Project-Unite/Controllers/APIController.cs | 37 |
2 files changed, 46 insertions, 0 deletions
diff --git a/Project-Unite/ACL.cs b/Project-Unite/ACL.cs index 6764a20..cc1c511 100644 --- a/Project-Unite/ACL.cs +++ b/Project-Unite/ACL.cs @@ -23,6 +23,15 @@ namespace Project_Unite 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(); diff --git a/Project-Unite/Controllers/APIController.cs b/Project-Unite/Controllers/APIController.cs index 10d0c9c..e8512ff 100644 --- a/Project-Unite/Controllers/APIController.cs +++ b/Project-Unite/Controllers/APIController.cs @@ -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; |
