public async Task GenerateUsernameAsync(ApplicationUser user, DeviceParser device) { if (!(string.IsNullOrWhiteSpace(user?.UserName))) { await SendEmailWithUsernameAsync(user, device); } }
/// <summary> /// Sends an email to a client with a link to reset their password. /// </summary> /// <param name="user"> </param> /// <param name="computer"> </param> /// <param name="ip"> </param> /// <param name="token"> </param> /// <returns> </returns> private async Task SendForgotPasswordTokenAsync(ApplicationUser user, DeviceParser device, string token) { // Get the information required to send the email from the appsettings.json. string appDomain = _config["Application:AppDomain"]; string verifyLink = _config["Application:ForgotPassword"]; // Send an email while replacing all placeholders. await _emailService.SendForgotPasswordEmailAsync(new() { ToEmails = new List <string>() { user.Email }, Placeholders = new Dictionary <string, string> { { "{{Username}}", user.UserName }, { "{{Email}}", user.Email }, { "{{IPAddress}}", device.IPv4 }, { "{{ComputerInfo}}", device.ToSimpleString() }, { "{{Link}}", string.Format(appDomain + verifyLink, user.Id, token) }, { "{{DateTime}}", DateTime.UtcNow.ToString() } } }); }
private async Task SendEmailWithUsernameAsync(ApplicationUser user, DeviceParser device) { // Generate email with placeholders. await _emailService.SendForgotUsernameEmailAsync(new() { ToEmails = new List <string>() { user.Email }, Placeholders = new Dictionary <string, string> { { "{{Username}}", user.UserName }, { "{{Email}}", user.Email }, { "{{IPAddress}}", device.IPv4 }, { "{{ComputerInfo}}", device.ToSimpleString() }, { "{{DateTime}}", DateTime.UtcNow.ToString() } } }); }
private async Task SendDataEncryptionEmailAsync(ApplicationUser user, DeviceParser device, string key, string link) { // Check if the phone number is null. string phone; if (string.IsNullOrWhiteSpace(user.PhoneNumber)) { phone = "Not Specified."; } else { phone = user.PhoneNumber; } // Generate email with placeholders. await _emailService.SendDataEncryptionEmailAsync(new() { ToEmails = new List <string>() { user.Email }, Placeholders = new Dictionary <string, string> { { "{{Username}}", user.UserName }, { "{{Email}}", user.Email }, { "{{IPAddress}}", device.IPv4 }, { "{{ComputerInfo}}", device.ToSimpleString() }, { "{{DateTime}}", DateTime.UtcNow.ToString() }, { "{{PhoneNumber}}", phone }, { "{{NewPhone}}", user.UnverifiedNewPhone }, { "{{AccountCreationDate}}", user.AccountCreationDate }, { "{{LastLogin}}", user.LastUserLogin }, { "{{Link}}", link }, { "{{PrivateKey}}", key } } }); }
/// <summary> /// Sends an email to a user's new email address when they update their email address asking /// them to verify. /// </summary> /// <param name="signUpModel"> </param> /// <param name="user"> </param> /// <param name="device"> </param> /// <param name="token"> </param> /// <returns> </returns> private async Task SendNewEmailConfirmationTokenAsync(ApplicationUser user, DeviceParser device, string token) { // Get values from appsettings.json string appDomain = _config["Application:AppDomain"]; string verifyLink = _config["Application:EmailConfirmation"]; string phone; if (string.IsNullOrWhiteSpace(user.PhoneNumber)) { phone = "Not Specified."; } else { phone = user.PhoneNumber; } // Generate email with placeholders. await _emailService.SendConfirmNewEmailAsync(new() { // send the token to the user's new unverified email. ToEmails = new List <string>() { user.UnverifiedNewEmail }, Placeholders = new Dictionary <string, string> { { "{{Username}}", user.UserName }, { "{{Email}}", user.Email }, { "{{IPAddress}}", device.IPv4 }, { "{{ComputerInfo}}", device.ToSimpleString() }, { "{{Link}}", string.Format(appDomain + verifyLink, user.Id, token) }, { "{{DateTime}}", DateTime.UtcNow.ToString() }, { "{{PhoneNumber}}", phone }, { "{{AccountCreationDate}}", user.AccountCreationDate }, { "{{LastLogin}}", user.LastUserLogin }, } }); }
public static IEnumerator GetDeviceModelForCode(string code, Action <DeviceModel> resultAction) { var qry = string.Format(SelectDeviceQuery, code); var response = PostRequest(WebAPIEndpoint, qry); yield return(response); string result = "Waiting..."; if (response.webRequest.isNetworkError) { result = "Error While Sending: " + response.webRequest.error; } else { result = /*"Received: " +*/ response.webRequest.downloadHandler.text; } Debug.Log(result); var parser = new DeviceParser(result); parser.Device.DeviceId = code; resultAction(parser.Device); }
public static void AddDevice(string reading) { DeviceList.Add(DeviceParser.FromTsv(reading)); }
public DeviceParserTests() { deviceCatalog.LoadDeviceListFromPath(@"..\..\..\..\ChatWeb\"); deviceParser = new DeviceParser(deviceCatalog); }
/// <summary> /// Send an email to a user with a confirmation token as well as information about the /// computer sending the email. /// </summary> /// <param name="signUpModel"> Register Model. </param> /// <param name="user"> Current client. </param> /// <param name="computer"> UserAgent info. </param> /// <param name="ip"> Mapped IPv4 address. </param> /// <param name="token"> Generated .NET Core token. </param> /// <returns> </returns> private async Task SendEmailConfirmationTokenAsync(SignUpUserModel signUpModel, ApplicationUser user, DeviceParser device, string token) { // Get values from appsettings.json string appDomain = _config["Application:AppDomain"]; string verifyLink = _config["Application:EmailConfirmation"]; // Generate email with placeholders. await _emailService.SendConfirmationEmailAsync(new() { ToEmails = new List <string>() { user.Email }, Placeholders = new Dictionary <string, string> { { "{{Username}}", user.UserName }, { "{{Email}}", user.Email }, { "{{Password}}", ConvertToAstrisk(signUpModel.Password) }, { "{{IPAddress}}", device.IPv4 }, { "{{ComputerInfo}}", device.ToSimpleString() }, { "{{Link}}", string.Format(appDomain + verifyLink, user.Id, token) }, { "{{DateTime}}", DateTime.UtcNow.ToString() } } }); }
public async Task GenerateForgotPasswordTokenAsync(ApplicationUser userModel, DeviceParser device) { // Generate a token using Identity Core. string token = await _userManager.GeneratePasswordResetTokenAsync(userModel); // If the token is valid. if (!string.IsNullOrWhiteSpace(token)) { await SendForgotPasswordTokenAsync(userModel, device, token); } }
public async Task GenerateNewDataEncryptionEmailAsync(ApplicationUser userModel, DeviceParser device, string key, string link) { await SendDataEncryptionEmailAsync(userModel, device, key, link); }
public async Task GenerateNewPhoneConfirmationTokenAsync(ApplicationUser userModel, DeviceParser device) { string token = await _userManager.GenerateChangePhoneNumberTokenAsync(userModel, userModel.UnverifiedNewPhone); if (!string.IsNullOrWhiteSpace(token)) { await _twilio.SendSmsAsync(new SMSTextModel() { To = userModel.UnverifiedNewPhone, Message = $"This number has been request to be the new phone number for Goliath Account: {userModel.UserName}. Enter this number in the userpanel to confirm it: {token}" }); await SendNewPhoneEmailAsync(userModel, device); } }
public async Task GenerateNewEmailConfirmationTokenAsync(ApplicationUser userModel, DeviceParser device) { // Generate a token using Identity Core. string token = await _userManager.GenerateEmailConfirmationTokenAsync(userModel); // If the token is valid. if (!string.IsNullOrWhiteSpace(token)) { await SendNewEmailConfirmationTokenAsync(userModel, device, token); await SendNotifyOldEmailAsync(userModel, device); } }
public async Task <IdentityResult> CreateUserAsync(SignUpUserModel userModel, DeviceParser device) { try { #region Create a user with some default values. // Create a new application user. ApplicationUser user = new() { BackgroundColor = "#FFFFFF", DarkTheme = "false", UserData = string.Empty, PendingNotifications = string.Empty, UserName = userModel.Username, Email = userModel.Email, LogoutThreshold = 0, AccountCreationDate = DateTime.UtcNow.ToString(), LastPasswordUpdate = DateTime.UtcNow.ToString() }; #endregion Create a user with some default values. // Use Identity Core to create the user. IdentityResult result = await(_userManager.CreateAsync(user, userModel.Password)); if (result.Succeeded) { // add them to default role. await _userManager.AddToRoleAsync(user, GoliathRoles.Default); // Send them a token. await GenerateEmailConfirmationTokenAsync(userModel, user, device); } _logger.LogInformation($"Created user \"{user.Id}\" with username \"{user.UserName}\" and email \"{user.Email}\"."); return(result); } catch (Exception e) { _logger.LogError("Failed to create new user."); return(IdentityResult.Failed( new IdentityError() { Code = e.TargetSite.Name, Description = "Could not create account." })); } }
public PciDevicesProvider() { _deviceParser = new DeviceParser(new PciDatabase()); }