private string GenerateUniqueName(Mime mime) { var dinfo = new DirectoryInfo(RootDirecotry); string fname = null; do { fname = Path.Combine(dinfo.FullName, $"{RandomAlphaNumericGenerator.RandomAlphaNumeric(40)}{mime.Extension}"); }while (File.Exists(fname)); return(fname); }
public Operation RequestCredentialReset(CredentialMetadata metadata, string targetUser) => _authorizer.AuthorizeAccess(UserContext.CurrentProcessPermissionProfile(), () => { var user = _query.GetUserById(targetUser); if (user.Status != (int)AccountStatus.Active) { throw new Exception("invalid account state"); } var verification = _query.GetLatestContextVerification(user, Constants.VerificationContext_CredentialReset); //if no unverified context still exists in the db, create a new one if (verification == null || verification.Verified || verification.ExpiresOn <= DateTime.Now) { var expiry = _settingsManager.GetSetting(Constants.Settings_DefaultContextVerificationExpirationTime) .Resolve() .ParseData <TimeSpan>(); verification = new ContextVerification { Context = Constants.VerificationContext_CredentialReset, Target = user, ExpiresOn = DateTime.Now + expiry, VerificationToken = RandomAlphaNumericGenerator.RandomAlphaNumeric(50) }; _pcommand.Add(verification).Resolve(); } return(_backgroundProcessor.EnqueueOperation <IEmailPush>(_mp => _mp.SendMail(new AccountActivation { From = "*****@*****.**", Subject = "Password Reset", Target = user.UserId, Link = _apiProvider.GeneratePasswordUpdateVerificationUrl(verification.VerificationToken, targetUser).Result, LogoUrl = _apiProvider.LogoUri().Result, LogoTextUrl = _apiProvider.LogoTextUri().Result })) .Then(opr => { })); });
private string GenerateToken() => RandomAlphaNumericGenerator.RandomAlphaNumeric(50);