/// <summary> /// Create and Update a new userProfile and return the AuthToken that can be used for subsequent web api calls for that userProfile /// The passed in http client will be updated with relevant AuthToken (same as being returned) /// </summary> /// <param name="client"></param> /// <param name="callerMemberName"></param> /// <param name="assemblyFilePath"></param> /// <returns></returns> public async Task <string> CreateDevUserProfile(HttpClient client, [CallerMemberName] string callerMemberName = null, [CallerFilePath] string assemblyFilePath = null) { //Add clientKey token to header BaseWebApiTest.SetAuthToken(client, ClientKey, false); //Create Dev user var newEmail = $"Test-{assemblyFilePath.ExGetFileNameFromAssemblyPath()}.{callerMemberName}@lifecouple.net"; var userProfileRequestInfo = new UserProfileRequestInfo { Email = newEmail }; var postCreateUserResponse = await client.PostAsync($"api/userprofiles/devuser", BaseWebApiTest.GetJsonContent(userProfileRequestInfo)); postCreateUserResponse.EnsureSuccessStatusCode(); //Create Token var tokenRequestInfo = new TokenRequestInfo { Email = newEmail, Password = newEmail.Split('@')[0] + "@" }; var postResponse = await client.PostAsync($"api/tokens", BaseWebApiTest.GetJsonContent(tokenRequestInfo)); postResponse.EnsureSuccessStatusCode(); var tokenResponseInfo = BaseWebApiTest.Deserialize <TokenResponseInfo>(await postResponse.Content.ReadAsStringAsync()); //Add token to header BaseWebApiTest.SetAuthToken(client, tokenResponseInfo.Token, true); // Set User profile var reqPayload = new UserProfileRegAboutYouRequestInfo { DateOfBirth = DateTime.Now.AddYears(-20), FirstName = "Tester", LastName = "Testlastname", Gender = "m", MobilePhone = "7605006125", NotificationOption = "True" }; postResponse = await client.PutAsync(ApiEndpoints.userprofiles_me_registration_aboutyou, BaseWebApiTest.GetJsonContent(reqPayload)); postResponse.EnsureSuccessStatusCode(); return(tokenResponseInfo.Token); }
public async Task <IActionResult> SetAboutYou([FromBody] UserProfileRegAboutYouRequestInfo usrProRegAboYouReqInfo) { try { if (!ModelState.IsValid) { return(this.ApiErrorMessage400BadRequest(this.ModelState)); } var jwtPayloadInfo = this.GetJwtPayloadInfo(); var userProfileId = await _bl.GetCachedUserId_byExternalReferenceIdAsync(jwtPayloadInfo.ExtReferenceId); if (userProfileId == null) { return(this.ApiErrorMessage400BadRequestUserIdInTokenNotFound(jwtPayloadInfo.ExtReferenceId)); } var bl_usrProReg = new BL_UserProfile { Id = userProfileId, PrimaryEmail = usrProRegAboYouReqInfo.Email, DateOfBirth = usrProRegAboYouReqInfo.DateOfBirth, FirstName = usrProRegAboYouReqInfo.FirstName, Gender = usrProRegAboYouReqInfo.Gender, NotificationOption = usrProRegAboYouReqInfo.NotificationOption, LastName = usrProRegAboYouReqInfo.LastName, PrimaryMobileNr = usrProRegAboYouReqInfo.MobilePhone, }; await _bl.SetUserAsync(bl_usrProReg); return(this.ApiPutMessage204NotContent()); } catch (Exception exc) { return(this.ApiErrorMessage400BadRequest(exc)); } }