API endpoints for displayname and fullname

This commit is contained in:
Michael 2017-04-30 12:57:09 -04:00
parent a1185b8194
commit acfdbc8592

View file

@ -48,6 +48,78 @@ public ActionResult SetCodepoints(long id)
}
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;