示例#1
0
        public virtual async Task HandleRegisterPostSuccess(
            ISiteContext site,
            RegisterViewModel viewModel,
            HttpContext httpContext,
            UserLoginResult loginResult,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            await EnsureProps();

            // we "could" re-validate here but
            // the method above gets called just before this in the same postback
            // so we know there were no validation errors or this method would not be invoked
            SiteUser siteUser = null;

            if (_userPropertyService.HasAnyNativeProps(_props.Properties))
            {
                siteUser = await _userPropertyService.GetUser(loginResult.User.Id.ToString());
            }
            if (loginResult.User != null)
            {
                foreach (var p in _props.Properties)
                {
                    if (p.VisibleOnRegistration)
                    {
                        if (!_userPropertyService.IsNativeUserProperty(p.Key))
                        {
                            var postedValue = httpContext.Request.Form[p.Key];
                            // persist to kvp storage
                            await _userPropertyService.CreateOrUpdate(
                                site.Id.ToString(),
                                loginResult.User.Id.ToString(),
                                p.Key,
                                postedValue);
                        }
                    }
                }
            }
            else
            {
                _log.LogError("user was null in HandleRegisterPostSuccess, unable to update user with custom data");
            }
        }
        public virtual async Task HandleUserEditGet(
            ISiteContext site,
            EditUserViewModel viewModel,
            HttpContext httpContext,
            ViewDataDictionary viewData,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            await EnsureProps();

            // add user props to viewData to pass them to the view
            var userProps = await _userPropertyService.FetchByUser(site.Id.ToString(), viewModel.UserId.ToString());

            SiteUser siteUser = null;

            if (_userPropertyService.HasAnyNativeProps(_props.Properties))
            {
                siteUser = await _userPropertyService.GetUser(viewModel.UserId.ToString());
            }

            foreach (var p in _props.Properties)
            {
                if (p.VisibleOnAdminUserEdit)
                {
                    if (_userPropertyService.IsNativeUserProperty(p.Key))
                    {
                        viewData[p.Key] = _userPropertyService.GetNativeUserProperty(siteUser, p.Key);
                    }
                    else
                    {
                        var found = userProps.Where(x => x.Key == p.Key).FirstOrDefault();
                        if (found != null)
                        {
                            viewData[p.Key] = found.Value;
                        }
                    }
                }
            }
        }