diff options
| author | Michael <[email protected]> | 2017-04-30 12:57:09 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-04-30 12:57:09 -0400 |
| commit | acfdbc859254e4471ae55f44022de5ec98603577 (patch) | |
| tree | 79c918efce59de10e3faa7702dd33220ddeb8dee /Project-Unite | |
| parent | a1185b8194e0a2bcea77a509179ec2b37ffea002 (diff) | |
| download | project-unite-acfdbc859254e4471ae55f44022de5ec98603577.tar.gz project-unite-acfdbc859254e4471ae55f44022de5ec98603577.tar.bz2 project-unite-acfdbc859254e4471ae55f44022de5ec98603577.zip | |
API endpoints for displayname and fullname
Diffstat (limited to 'Project-Unite')
| -rw-r--r-- | Project-Unite/Controllers/APIController.cs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/Project-Unite/Controllers/APIController.cs b/Project-Unite/Controllers/APIController.cs index e8512ff..438050e 100644 --- a/Project-Unite/Controllers/APIController.cs +++ b/Project-Unite/Controllers/APIController.cs @@ -48,6 +48,78 @@ namespace Project_Unite.Controllers } + public ActionResult GetDisplayName() + { + 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.DisplayName); + } + catch + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + } + + public ActionResult SetDisplayName(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.DisplayName = id; + db.SaveChanges(); + return new HttpStatusCodeResult(200); + } + catch + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + } + + public ActionResult GetFullName() + { + 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.FullName); + } + catch + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + } + + public ActionResult SetFullName(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.FullName = id; + db.SaveChanges(); + return new HttpStatusCodeResult(200); + } + catch + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + } + + + public JavaScriptSerializer Serializer { get; set; |
