示例#1
0
        public async Task <ICommandResult <TUser> > GetForgotPasswordUserAsync(string userIdentifier)
        {
            var result = new CommandResult <TUser>();

            if (string.IsNullOrWhiteSpace(userIdentifier))
            {
                return(result.Failed());
            }

            var user = await FindByUsernameOrEmailAsync(userIdentifier);

            if (user == null)
            {
                return(result.Failed());
            }

            // Generate password reset token
            user.ResetToken = await _userManager.GeneratePasswordResetTokenAsync(user);

            // Persist the password reset token
            var updatedUser = await _platoUserStore.UpdateAsync(user);

            if (updatedUser != null)
            {
                return(result.Success(updatedUser));
            }

            return(result.Failed());
        }
示例#2
0
        public async Task <ISpamOperatorResult <Reply> > UpdateModelAsync(ISpamOperatorContext <Reply> context)
        {
            // Perform validation
            var validation = await ValidateModelAsync(context);

            // Create result
            var result = new SpamOperatorResult <Reply>();

            // 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));
            }

            // Get reply author
            var user = await BuildUserAsync(context.Model);

            if (user == null)
            {
                return(null);
            }

            // Flag user as SPAM?
            if (context.Operation.FlagAsSpam)
            {
                var bot = await _platoUserStore.GetPlatoBotAsync();

                // Mark user as SPAM
                if (!user.IsSpam)
                {
                    user.IsSpam = true;
                    user.IsSpamUpdatedUserId = bot?.Id ?? 0;
                    user.IsSpamUpdatedDate   = DateTimeOffset.UtcNow;
                    await _platoUserStore.UpdateAsync(user);
                }

                // Mark reply as SPAM
                if (!context.Model.IsSpam)
                {
                    context.Model.IsSpam = true;
                    await _replyStore.UpdateAsync(context.Model);
                }
            }

            // 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));
        }
示例#3
0
        public async Task OnActionExecutingAsync(ResultExecutingContext context)
        {
            // Not a view result
            if (!(context.Result is ViewResult))
            {
                return;
            }

            // Tracking cookie already exists, simply execute the controller result
            if (_active)
            {
                return;
            }

            // Get authenticated user
            var user = await _contextFacade.GetAuthenticatedUserAsync();

            // Not authenticated, simply execute the controller result
            if (user == null)
            {
                return;
            }

            user.Visits           += 1;
            user.VisitsUpdatedDate = DateTimeOffset.UtcNow;
            user.LastLoginDate     = DateTimeOffset.UtcNow;

            var result = await _userStore.UpdateAsync(user);

            if (result != null)
            {
                // Award visit reputation
                await _userReputationAwarder.AwardAsync(new Reputation("Visit", 1), result.Id, "Unique Visit");

                // Set client cookie to ensure update does not
                // occur again for as long as the cookie exists
                _cookieBuilder
                .Contextulize(context.HttpContext)
                .Append(
                    _cookieName,
                    true.ToString(),
                    new CookieOptions
                {
                    HttpOnly = true,
                    Expires  = DateTime.Now.AddMinutes(_sessionLength)
                });
            }
        }
示例#4
0
        public override async Task <IViewProviderResult> BuildUpdateAsync(User user, IViewProviderContext context)
        {
            var model = new EditUserViewModel();

            if (!await context.Updater.TryUpdateModelAsync(model))
            {
                return(await BuildEditAsync(user, context));
            }

            if (context.Updater.ModelState.IsValid)
            {
                user.ApiKey = model.ApiKey;
                await _platoUserStore.UpdateAsync(user);
            }

            return(await BuildEditAsync(user, context));
        }
示例#5
0
文件: UserStore.cs 项目: turenc/Plato
        public async Task <IdentityResult> UpdateAsync(User user, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            try
            {
                await _platoUserStore.UpdateAsync(user);
            }
            catch
            {
                return(IdentityResult.Failed());
            }

            return(IdentityResult.Success);
        }
示例#6
0
        public override async Task <IViewProviderResult> BuildUpdateAsync(User user, IViewProviderContext context)
        {
            var model = new EditSocialViewModel();

            if (!await context.Updater.TryUpdateModelAsync(model))
            {
                return(await BuildEditAsync(user, context));
            }

            if (context.Updater.ModelState.IsValid)
            {
                // Store social links in generic UserData store
                var data = user.GetOrCreate <SocialLinks>();
                data.FacebookUrl = model.FacebookUrl;
                data.TwitterUrl  = model.TwitterUrl;
                data.YouTubeUrl  = model.YouTubeUrl;
                user.AddOrUpdate <SocialLinks>(data);

                // Update user
                await _platoUserStore.UpdateAsync(user);
            }

            return(await BuildEditAsync(user, context));
        }