Exemplo n.º 1
0
        private void SetBandIdCookie(RequestContext requestContext)
        {
            const string cookieNameBandId = "BandId";

            CatalogsConsumerHelper.ExecuteWithCatalogScope(
                container =>
            {
                Guid bandId;

                var bandCookie = requestContext.HttpContext.Request.Cookies[cookieNameBandId];
                if (bandCookie != null && !string.IsNullOrEmpty(bandCookie.Value))
                {
                    bandId = Guid.Parse(bandCookie.Value);
                }
                else
                {
                    var bandProcess = CatalogsConsumerHelper.ResolveCatalogsConsumer <IBandProcess>(container);
                    bandId          = bandProcess.EnsureBandExists().Id;

                    requestContext.HttpContext.Response.Cookies[cookieNameBandId].Value = bandId.ToString();
                }

                var bandIdInstaller = DependencyConfiguration.DependencyResolver.Resolve <IBandIdInstaller>();
                bandIdInstaller.SetBandId(bandId);
            });
        }
Exemplo n.º 2
0
        public ActionResult Create(AddBlogArticleModel model)
        {
            try
            {
                return(CatalogsConsumerHelper.ExecuteWithCatalogScope(
                           container =>
                {
                    var membershipUser = Membership.GetUser();
                    var userId = (Guid)membershipUser.ProviderUserKey;

                    var blogArticleMapper = CatalogsConsumerHelper.ResolveCatalogsConsumer <IBlogArticleMapper>(container);
                    var blogArticle = blogArticleMapper.Map(model, userId);

                    var blogProcess = CatalogsConsumerHelper.ResolveCatalogsConsumer <IBlogProcess>(container);
                    blogProcess.AddBlogArticle(blogArticle);

                    return RedirectToAction("Index");
                }));
            }
            catch (Exception)
            {
                ModelState.AddModelError("", ExceptionMessages.GenericExceptionMessage);
                return(View(model));
            }
        }
Exemplo n.º 3
0
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            var statusCode = MembershipCreateStatus.Success;

            var membershipUser = CatalogsConsumerHelper.ExecuteWithCatalogScope(
                container =>
            {
                var userProcess = CatalogsConsumerHelper.ResolveCatalogsConsumer <IUserProcess>(container);
                var user        = userProcess.GetUserByLoginName(username);
                if (user != null)
                {
                    statusCode = MembershipCreateStatus.DuplicateUserName;
                    return(null);
                }

                user = userProcess.GetUserByEmailAddress(email);
                if (user != null)
                {
                    statusCode = MembershipCreateStatus.DuplicateEmail;
                    return(null);
                }

                var bandProcess = CatalogsConsumerHelper.ResolveCatalogsConsumer <IBandProcess>(container);
                var band        = bandProcess.EnsureBandExists();

                InstallBandId(band.Id);

                var cryptographyProcess = CatalogsConsumerHelper.ResolveCatalogsConsumer <ICryptographyProcess>(container);
                var encryptedPassword   = cryptographyProcess.Encrypt(password);

                user = new User
                {
                    Login = new LoginAccount
                    {
                        LoginName               = username,
                        Password                = encryptedPassword,
                        EmailAddress            = email,
                        IsApproved              = isApproved,
                        IsOnline                = true,
                        LastLoginDate           = DateTime.UtcNow,
                        LastActivityDate        = DateTime.UtcNow,
                        LastPasswordChangedDate = DateTime.UtcNow
                    },
                };

                user = userProcess.AddUser(user);

                var userMapper = CatalogsConsumerHelper.ResolveCatalogsConsumer <IUserMapper>(container);
                return(userMapper.Map(user));
            });

            status = statusCode;
            return(membershipUser);
        }
Exemplo n.º 4
0
        public override MembershipUser GetUser(string userName, bool userIsOnline)
        {
            return(CatalogsConsumerHelper.ExecuteWithCatalogScope(
                       container =>
            {
                var process = CatalogsConsumerHelper.ResolveCatalogsConsumer <IUserProcess>(container);
                var user = process.GetUserByLoginName(userName);

                InstallBandId(user.BandId);

                var userMapper = CatalogsConsumerHelper.ResolveCatalogsConsumer <IUserMapper>(container);
                return userMapper.Map(user);
            }));
        }
Exemplo n.º 5
0
        public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
        {
            return(CatalogsConsumerHelper.ExecuteWithCatalogScope(
                       container =>
            {
                var process = CatalogsConsumerHelper.ResolveCatalogsConsumer <IUserProcess>(container);
                var user = process.GetUserByLoginAccount((Guid)providerUserKey);

                InstallBandId(user.BandId);

                var userMapper = CatalogsConsumerHelper.ResolveCatalogsConsumer <IUserMapper>(container);
                return userMapper.Map(user);
            }));
        }
Exemplo n.º 6
0
        public override string GetPassword(string username, string answer)
        {
            return(CatalogsConsumerHelper.ExecuteWithCatalogScope(
                       container =>
            {
                var userProcess = CatalogsConsumerHelper.ResolveCatalogsConsumer <IUserProcess>(container);
                var user = userProcess.GetUserByLoginName(username);

                InstallBandId(user.BandId);

                var cryptographyProcess = CatalogsConsumerHelper.ResolveCatalogsConsumer <ICryptographyProcess>(container);

                return cryptographyProcess.Decrypt(user.Login.Password);
            }));
        }
Exemplo n.º 7
0
        public void Post(Guid bandId, [FromBody] AddBlogArticleModel model)
        {
            CatalogsConsumerHelper.ExecuteWithCatalogScope(
                container =>
            {
                var membershipUser = Membership.GetUser();
                var userId         = (Guid)membershipUser.ProviderUserKey;

                var blogArticleMapper = CatalogsConsumerHelper.ResolveCatalogsConsumer <IBlogArticleMapper>(container);
                var blogArticle       = blogArticleMapper.Map(model, userId);

                var blogProcess = CatalogsConsumerHelper.ResolveCatalogsConsumer <IBlogProcess>(container);
                blogProcess.AddBlogArticle(blogArticle);
            });
        }
Exemplo n.º 8
0
        public override bool UnlockUser(string userName)
        {
            return(CatalogsConsumerHelper.ExecuteWithCatalogScope(
                       container =>
            {
                var process = CatalogsConsumerHelper.ResolveCatalogsConsumer <IUserProcess>(container);
                var user = process.GetUserByLoginName(userName);

                InstallBandId(user.BandId);

                user.Login.IsLockedOut = false;
                process.UpdateUser(user);

                return true;
            }));
        }
Exemplo n.º 9
0
        public override void UpdateUser(MembershipUser membershipUser)
        {
            CatalogsConsumerHelper.ExecuteWithCatalogScope(
                container =>
            {
                var userMapper = CatalogsConsumerHelper.ResolveCatalogsConsumer <IUserMapper>(container);
                var user       = userMapper.Map(membershipUser);

                InstallBandId(user.BandId);

                var userProcess = CatalogsConsumerHelper.ResolveCatalogsConsumer <IUserProcess>(container);
                userProcess.UpdateUser(user);

                return(true);
            });
        }
Exemplo n.º 10
0
        public override bool ValidateUser(string username, string password)
        {
            return(CatalogsConsumerHelper.ExecuteWithCatalogScope(
                       container =>
            {
                var userProcess = CatalogsConsumerHelper.ResolveCatalogsConsumer <IUserProcess>(container);
                var user = userProcess.GetUserByLoginName(username);
                if (user == null)
                {
                    return false;
                }

                InstallBandId(user.BandId);

                var cryptographyProcess = CatalogsConsumerHelper.ResolveCatalogsConsumer <ICryptographyProcess>(container);
                var currentPassword = cryptographyProcess.Decrypt(user.Login.Password);

                return password == currentPassword;
            }));
        }
Exemplo n.º 11
0
        public ActionResult Edit(Guid id, UpdateBlogArticleModel model)
        {
            try
            {
                return(CatalogsConsumerHelper.ExecuteWithCatalogScope(
                           container =>
                {
                    var blogArticleMapper = CatalogsConsumerHelper.ResolveCatalogsConsumer <IBlogArticleMapper>(container);
                    var blogArticle = blogArticleMapper.Map(model, id);

                    var blogProcess = CatalogsConsumerHelper.ResolveCatalogsConsumer <IBlogProcess>(container);
                    blogProcess.UpdateBlogArticle(blogArticle);

                    return RedirectToAction("Index");
                }));
            }
            catch
            {
                ModelState.AddModelError("", ExceptionMessages.GenericExceptionMessage);
                return(View(model));
            }
        }
Exemplo n.º 12
0
        public override bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            return(CatalogsConsumerHelper.ExecuteWithCatalogScope(
                       container =>
            {
                var userProcess = CatalogsConsumerHelper.ResolveCatalogsConsumer <IUserProcess>(container);
                var user = userProcess.GetUserByLoginName(username);

                InstallBandId(user.BandId);

                var cryptographyProcess = CatalogsConsumerHelper.ResolveCatalogsConsumer <ICryptographyProcess>(container);
                var currentPassword = cryptographyProcess.Decrypt(user.Login.Password);
                if (oldPassword != currentPassword)
                {
                    return false;
                }

                user.Login.Password = cryptographyProcess.Encrypt(newPassword);
                userProcess.UpdateUser(user);

                return true;
            }));
        }