mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-01-22 17:22:15 +00:00
API endpoints for displayname and fullname
This commit is contained in:
parent
a1185b8194
commit
acfdbc8592
1 changed files with 72 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue