public bool EditProfileUserName(string userName, string newUserName, string password, int securityKey) { EditProfileResult result = profileService.EditProfile(new EditProfileRequest() { UserName = userName, NewUserName = newUserName, Password = password, SecurityKey = securityKey, NewAvatar = null }); if (!result.Success.HasValue || !result.Success.Value) { return(false); } return(true); }
public bool EditProfilePassword(string userName, string oldPassword, string Password, int securityKey) { EditProfileResult result = profileService.EditProfile(new EditProfileRequest() { UserName = userName, NewUserName = userName, Password = oldPassword, NewPassword = Password, NewAvatar = null, SecurityKey = securityKey }); if (!result.Success.HasValue || !result.Success.Value) { string e = result.ErrorMessage; return(false); } return(true); }
public HttpResponseMessage EditProfile(EditProfileRequest request) { var result = new EditProfileResult(); try { result = service.EditProfile(request); } catch (Exception e) { result.ErrorMessage = e.Message; result.Success = false; return(Request.CreateResponse(HttpStatusCode.InternalServerError, result)); } return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public EditProfileResult EditProfile(EditProfileRequest request) { var result = new EditProfileResult(); result.newUserName = request.UserName; try { var user = _cache.RefreshAndGet( Users, request.UserName, new UserNotFoundException(string.Format("user id: {0} not found, please re-login", request.UserName)) ); UserManager.SecurityCheck(request.SecurityKey, user); // call domain action - if null don't update (?? operator) UserManager.EditProfile( user, request.NewUserName ?? request.UserName, request.NewPassword ?? request.Password, request.NewAvatar ?? user.Avatar); // update result // parse byte[] to JSON (using int[] as a cleaver KOMBINA) result.newAvatar = request.NewAvatar?.Select(b => (int)b).ToArray(); result.newPassword = request.NewPassword; result.newUserName = request.NewUserName; result.Success = true; } catch (PokerException e) { result.Success = false; result.ErrorMessage = e.Message; Logger.Error(e, this); } return(result); }
public void EditProfileTest() { //Arrange var request = new EditProfileRequest() { UserName = user.UserName, NewUserName = "******", NewPassword = "******", NewAvatar = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, SecurityKey = _seqkey, }; var exStatus = HttpStatusCode.OK; var exResult = new EditProfileResult() { ErrorMessage = "", Success = true, newUserName = "******", newAvatar = (new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }).Select(b => (int)b).ToArray(), newPassword = "******" }; //Act var act = ctrl.EditProfile(request); EditProfileResult actContent; var hasContent = act.TryGetContentValue(out actContent); //Assert Assert.AreEqual(exStatus, act.StatusCode, "status code"); Assert.IsTrue(hasContent, "has content"); Assert.AreEqual(exResult.ErrorMessage, actContent.ErrorMessage, "error message"); Assert.AreEqual(exResult.Success, actContent.Success, "success bool"); Assert.AreEqual(exResult.newUserName, actContent.newUserName, "user not default"); Assert.AreEqual(exResult.newPassword, actContent.newPassword, "user not default"); CollectionAssert.AreEquivalent(exResult.newAvatar, actContent.newAvatar, "user not default"); }