Пример #1
0
 public object UpdateMyInfo()
 {
     if (Request.Method == HttpMethod.Options)
     {
         return Request.CreateResponse(HttpStatusCode.OK);
     }
     try
     {
         var jsonString = Request.Content.ReadAsStringAsync().Result;
         var propertiesToUpdate = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonString);
         if (propertiesToUpdate == null)
         {
             return Request.CreateResponse(HttpStatusCode.BadRequest);
         }
         if (propertiesToUpdate.ContainsKey("userPassword"))
         {
             return Request.CreateResponse(HttpStatusCode.BadRequest,
                 "Use ChangeMyPassword api to change your password!");
         }
         var tr = new TokenRepository();
         var ur = new UserRepository();
         var origAuthRequst = tr.GetAuthRequestFromToken(Request.Headers.GetValues("Authorization").First());
         ur.ChangeUserInfo(origAuthRequst.User, origAuthRequst.Password, propertiesToUpdate);
         return Request.CreateResponse(HttpStatusCode.OK);
     }
     catch(Exception exc)
     {
         return Request.CreateResponse(HttpStatusCode.InternalServerError);
     }
 }
Пример #2
0
 public object GetInfo(string cnUser)
 {
     if (Request.Method == HttpMethod.Options)
     {
         return Request.CreateResponse(HttpStatusCode.OK);
     }
     try
     {
         var tr = new TokenRepository();
         var ur = new UserRepository();
         var origAuthRequst = tr.GetAuthRequestFromToken(Request.Headers.GetValues("Authorization").First());
         var userInfo = ur.GetUserInfo(origAuthRequst.User, origAuthRequst.Password, cnUser,
             new[] {"displayName", "telephoneNumber", "title", "mail"});
         return Request.CreateResponse(userInfo.Count > 1 ? HttpStatusCode.OK : HttpStatusCode.NotFound, userInfo);
     }
     catch
     {
         return Request.CreateResponse(HttpStatusCode.InternalServerError);
     }
 }
Пример #3
0
 public object ChangeMyPassword()
 {
     if (Request.Method == HttpMethod.Options)
     {
         return Request.CreateResponse(HttpStatusCode.OK);
     }
     var jsonString = Request.Content.ReadAsStringAsync().Result;
     var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonString);
     if (dict == null || !dict.ContainsKey("newPassword"))
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest);
     }
     var newPassword = dict["newPassword"];
     try
     {
         var tr = new TokenRepository();
         var ur = new UserRepository();
         var origAuthRequst = tr.GetAuthRequestFromToken(Request.Headers.GetValues("Authorization").First());
         if (ur.ChangeUserInfo(origAuthRequst.User, origAuthRequst.Password,
             new Dictionary<string, string> {{"userPassword", newPassword}}))
         {
             tr.InvalidateTokensForUser(origAuthRequst.User,
                 Request.Headers.GetValues("Authorization").FirstOrDefault());
         }
         return Request.CreateResponse(HttpStatusCode.OK);
     }
     catch(Exception exc)
     {
         return Request.CreateResponse(HttpStatusCode.InternalServerError);
     }
 }