public LoginResult Authenticate(UserAuthen user) { if (user == null) throw new HttpResponseException(new HttpResponseMessage() { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("Please provide the credentials.") }); if (IoTUserMrg.IsValidUser(user,false)) { UGToken token = new UGToken(user); var status = new LoginResult() { Successeded = true, UGToken = token.Encrypt(), Message = "Successfully signed in." }; //Get data attach (List<int> storesId) - List store by User var lst = new List<int>() { 1 }; Profile p = new Profile(); p.Stores = lst; string profile = p.SerializeJson(); //Update profile IoTUserMrg.UpdateProfile(user.UserName, profile); //status attach data status.ProfileJson = profile; return status; } else { throw new HttpResponseException(new HttpResponseMessage() { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("Invalid user name or password.") }); } }
public override async Task<HttpResponseMessage> ExecuteAsync(System.Web.Http.Controllers.HttpControllerContext controllerContext, System.Threading.CancellationToken cancellationToken) { var request = controllerContext.Request; object obj; if (request.Properties.TryGetValue(UGConstants.HTTPHeaders.TOKEN_NAME, out obj)) { UGToken = obj as UGToken; if (UGToken != null) { UGUser = IoTUserManager.GetUser(UGToken); if (UGUser != null && string.IsNullOrWhiteSpace(UGUser.JsonProfile)) { //Get data attach (List<int> storesId) - List store by User var lst = new List<int>() { 1 }; Profile p = new Profile(); p.Stores = lst; //Update profile IoTUserManager.UpdateProfile(UGUser.UserName, p.SerializeJson()); } } } return await base.ExecuteAsync(controllerContext, cancellationToken); }