async Task <User> GetUserViaCookieAuthAsync() { var user = _httpContextAccessor.HttpContext.User; var identity = user?.Identity; if ((identity != null) && (identity.IsAuthenticated)) { return(await _platoUserStore.GetByUserNameAsync(identity.Name)); } return(null); }
public async Task <ICommandResult <TUser> > GetAuthenticatedUserAsync(ClaimsPrincipal principal) { var result = new CommandResult <TUser>(); var identity = principal?.Identity; if ((identity != null) && (identity.IsAuthenticated)) { var user = await _platoUserStore.GetByUserNameAsync(identity.Name); return(result.Success(user)); } return(result.Failed()); }
async Task <User> BuildUserAsync(LoginPage userLogin) { var user = await _platoUserStore.GetByUserNameAsync(userLogin.UserName); if (user == null) { return(null); } // Ensure we check against the IP address being used at the time of the login user.IpV4Address = _clientIpAddress.GetIpV4Address(); user.IpV6Address = _clientIpAddress.GetIpV6Address(); return(user); }
public async Task <ISpamOperatorResult <User> > UpdateModelAsync(ISpamOperatorContext <User> context) { // Perform validation var validation = await ValidateModelAsync(context); // Create result var result = new SpamOperatorResult <User>(); // Not an operator of interest if (validation == null) { return(result.Success(context.Model)); } // If validation succeeded no need to perform further actions if (validation.Succeeded) { return(result.Success(context.Model)); } // Flag user as SPAM? if (context.Operation.FlagAsSpam) { var bot = await _platoUserStore.GetPlatoBotAsync(); var user = await _platoUserStore.GetByUserNameAsync(context.Model.UserName); if (user != null) { if (!user.IsSpam) { user.IsSpam = true; user.IsSpamUpdatedUserId = bot?.Id ?? 0; user.IsSpamUpdatedDate = DateTimeOffset.UtcNow; await _platoUserStore.UpdateAsync(user); } } } // Defer notifications for execution after request completes _deferredTaskManager.AddTask(async ctx => { await NotifyAsync(context); }); // Return failed with our updated model and operation // This provides the calling code with the operation error message return(result.Failed(context.Model, context.Operation)); }
// ---------------------- async Task <bool> InvalidateIdentityNameAsync(IIdentity identity) { // Attempt to find the user by the identity.Name value var user = await _platoUserStore.GetByUserNameAsync(identity.Name); // User no longer exists or name has changed if (user == null) { // Sign out await _signInManager.SignOutAsync(); // Indicate user was invalidated return(true); } return(false); }
async Task <IEnumerable <User> > GetUsersByUsernamesAsync(string[] usernames) { var users = new List <User>(); foreach (var username in usernames) { if (!String.IsNullOrEmpty(username)) { var user = await _platoUserStore.GetByUserNameAsync(username); if (user != null) { users.Add(user); } } } return(users); }
public async Task <User> GetAuthenticatedUserAsync(IIdentity identity) { if (identity == null) { return(null); } if (!identity.IsAuthenticated) { return(null); } if (string.IsNullOrEmpty(identity.Name)) { return(null); } return(await _platoUserStore.GetByUserNameAsync(identity.Name)); }
public override async Task <IViewProviderResult> BuildUpdateAsync(UserRegistration registration, IViewProviderContext context) { // We need a valid view model if (!context.Updater.ModelState.IsValid) { return(await BuildIndexAsync(registration, context)); } // If we reach the BuildUpdateAsync method the user has // been validated & created so retrieve full user from database var user = await _platoUserStore.GetByUserNameAsync(registration.UserName); // User not found if (user == null) { return(await BuildIndexAsync(registration, context)); } // Execute UpdateModel within registered spam operators await _spamOperatorManager.UpdateModelAsync(SpamOperations.Login, user); // Return view return(await BuildIndexAsync(registration, context)); }