From 99398e9326a393b8b3fcd72a8cc40f215d672672 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 30 Apr 2017 18:50:20 -0400 Subject: [PATCH] email and sysname endpoints --- Project-Unite/Controllers/APIController.cs | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/Project-Unite/Controllers/APIController.cs b/Project-Unite/Controllers/APIController.cs index 438050e..9d22a75 100644 --- a/Project-Unite/Controllers/APIController.cs +++ b/Project-Unite/Controllers/APIController.cs @@ -48,6 +48,60 @@ public ActionResult SetCodepoints(long id) } + public ActionResult GetEmail() + { + 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.Email); + } + catch + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + } + + public ActionResult GetSysName() + { + 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.SystemName); + } + catch + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + } + + public ActionResult SetSysName(string 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.SystemName = id; + db.SaveChanges(); + return new HttpStatusCodeResult(200); + } + catch + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + } + + + + public ActionResult GetDisplayName() { try