// ------------------------------------------------------------------------- // --- HELPERS --- /// <summary> /// Generates a secure token which will be sent to the users /// e-mail address together with account and instance information. /// This token is also set to cache as key together with the users /// UID as value to re-identify this token. /// After that, teh value for <see cref="UserModel.EmailConfirmStatus"/> /// will be set to <see cref="EmailConfirmStatus.UNCONFIRMED"/>. /// /// If the user has no valid e-mail address set, no mail will be sent /// and this function returns nothing without an error. /// </summary> /// <param name="user">user model</param> /// <returns></returns> private async Task SendMailConfirm(UserModel user) { if (publicAddress.IsNullOrEmpty()) { return; } var token = CryptoRandomUtil.GetBase64String(32); cache.Put($"{Constants.MAIL_CONFIRM_CACHE_KEY}:{token}", user.Uid, TimeSpan.FromHours(1)); var content = $"To confirm your mail address of your voidseeker account, please open the link below.\n" + $"\n" + $"Username: {user.UserName}\n" + $"UID: {user.Uid}\n" + $"Instance Host: {publicAddress}\n" + $"\n" + $"Confirmation Link:\n" + $"{publicAddress}{Constants.MAIL_CONFIRM_SUBDIR}?token={token}"; await mailService.SendMailAsync("voidseeker", user.EmailAddress, "E-Mail Confirmation | voidseeker", content, false); user.EmailConfirmStatus = EmailConfirmStatus.UNCONFIRMED; }
public async Task <DeadlinedToken> GenerateAsync <T>(T ident, TimeSpan lifetime) where T : AuthClaims { var token = new DeadlinedToken() { Token = CryptoRandomUtil.GetBase64String(64), Deadline = DateTime.Now.Add(lifetime), }; var dbToken = await database.GetRefreshTokenByUserUid(ident.UserUid); Func <RefreshTokenModel, Task> addOrUpdate = database.Update; if (dbToken == null) { dbToken = new RefreshTokenModel(token, ident.UserUid); addOrUpdate = database.Put; } await addOrUpdate(dbToken); return(token); }
// ------------------------------------------------------------------------- // --- HELPERS --- /// <summary> /// TODO: Summary /// </summary> /// <param name="user">user model</param> /// <returns></returns> private async Task SendPasswordResetMail(UserModel user) { if (publicAddress.IsNullOrEmpty()) { return; } var token = CryptoRandomUtil.GetBase64String(32); cache.Put($"{Constants.MAIL_PWRESET_CACHE_KEY}:{token}", user.Uid, TimeSpan.FromHours(1)); var content = $"To reset your password, please follow the link below.\n" + $"\n" + $"Username: {user.UserName}\n" + $"UID: {user.Uid}\n" + $"Instance Host: {publicAddress}\n" + $"\n" + $"Password Reset Link:\n" + $"{publicAddress}{Constants.MAIL_PWRESET_SUBDIR}?token={token}"; await mailService.SendMailAsync("voidseeker", user.EmailAddress, "Password Reset | voidseeker", content, false); }