/** * Set user phone number. */ private async Task <APIGatewayProxyResponse> SetUserPhoneNumber(IDataStores dataStores, IDictionary <string, string> requestHeaders, JObject requestBody) { Debug.Untested(); Debug.AssertValid(dataStores); Debug.AssertValid(requestHeaders); Debug.AssertValidOrNull(requestBody); try { // Log call LoggingHelper.LogMessage($"UserIdentityService::SetUserPhoneNumber()"); // Get the NoSQL DB client AmazonDynamoDBClient dbClient = (AmazonDynamoDBClient)dataStores.GetNoSQLDataStore().GetDBClient(); Debug.AssertValid(dbClient); // Check inputs SetUserPhoneNumberRequest setUserPhoneNumberRequest = UserIdentityService_SetUserPhoneNumber_LogicLayer.CheckValidSetUserPhoneNumberRequest(requestBody); Debug.AssertValid(setUserPhoneNumberRequest); // Check authenticated endpoint security string loggedInUserId = await APIHelper.CheckLoggedIn(dbClient, requestHeaders); Debug.AssertID(loggedInUserId); // Perform logic await UserIdentityService_SetUserPhoneNumber_LogicLayer.SetUserPhoneNumber(dbClient, loggedInUserId, setUserPhoneNumberRequest); // Respond return(new APIGatewayProxyResponse { StatusCode = APIHelper.STATUS_CODE_NO_CONTENT }); } catch (Exception exception) { Debug.Tested(); return(APIHelper.ResponseFromException(exception)); } }
/** * Set user phone number. */ public static async Task SetUserPhoneNumber(AmazonDynamoDBClient dbClient, string loggedInUserId, SetUserPhoneNumberRequest setUserPhoneNumberRequest) { Debug.Tested(); Debug.AssertValid(dbClient); Debug.AssertID(loggedInUserId); Debug.AssertValid(setUserPhoneNumberRequest); Debug.AssertString(setUserPhoneNumberRequest.phoneNumber); // Load the user User user = await IdentityServiceLogicLayer.FindUserByID(dbClient, loggedInUserId); Debug.AssertValid(user); // Make changes (if necessary) if (user.PhoneNumber != setUserPhoneNumberRequest.phoneNumber) { // Set the new phone number user.PhoneNumber = setUserPhoneNumberRequest.phoneNumber; // Mark it as not verified user.PhoneNumberVerified = null; // Save the user await IdentityServiceDataLayer.SaveUser(dbClient, user); // Send the OTP via SMS string oneTimePassword = "******";//??++GENERATE OTP Link link = await IdentityServiceLogicLayer.CreateLink(dbClient, IdentityServiceLogicLayer.LINK_TYPE_VERIFY_PHONE_NUMBER, loggedInUserId, oneTimePassword); Debug.AssertValid(link); //??++SMS OTP LoggingHelper.LogMessage($"PHONE NUMBER VERIFICATION LINK ID: {link.ID}"); } }