Beispiel #1
0
        public async Task <SecurityResult> ChangePasswordAsync(string name, string oldPassword, string newPassword)
        {
            IdentityResult result = null;

            var user = await _userManager.FindByNameAsync(name);

            if (user != null)
            {
                result = await _userManager.ChangePasswordAsync(user.Id, oldPassword, newPassword);
            }

            return(result == null ? null : result.ToCoreModel());
        }
Beispiel #2
0
        public async Task <SecurityResult> CreateAsync(ApplicationUserExtended user)
        {
            IdentityResult result = null;

            if (user != null)
            {
                var dbUser = user.ToDataModel();

                using (var userManager = _userManagerFactory())
                {
                    if (string.IsNullOrEmpty(user.Password))
                    {
                        result = await userManager.CreateAsync(dbUser);
                    }
                    else
                    {
                        result = await userManager.CreateAsync(dbUser, user.Password);
                    }
                }
                if (result.Succeeded)
                {
                    using (var repository = _platformRepository())
                    {
                        var account = new AccountEntity
                        {
                            Id           = dbUser.Id,
                            UserName     = user.UserName,
                            MemberId     = user.MemberId,
                            AccountState = AccountState.Approved,
                            RegisterType = (RegisterType)user.UserType,
                            StoreId      = user.StoreId
                        };

                        if (user.Roles != null)
                        {
                            foreach (var role in user.Roles)
                            {
                                account.RoleAssignments.Add(new RoleAssignmentEntity {
                                    RoleId = role.Id, AccountId = account.Id
                                });
                            }
                        }

                        repository.Add(account);
                        repository.UnitOfWork.Commit();
                    }
                }
            }

            return(result == null ? null : result.ToCoreModel());
        }
        public async Task <SecurityResult> CreateAsync(ApplicationUserExtended user)
        {
            IdentityResult result = null;

            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            //Update ASP.NET indentity user
            using (var userManager = _userManagerFactory())
            {
                var dbUser = user.ToIdentityModel();
                user.Id = dbUser.Id;
                if (string.IsNullOrEmpty(user.Password))
                {
                    result = await userManager.CreateAsync(dbUser);
                }
                else
                {
                    result = await userManager.CreateAsync(dbUser, user.Password);
                }
            }

            if (result.Succeeded)
            {
                using (var repository = _platformRepository())
                {
                    var dbAcount = user.ToDataModel();
                    dbAcount.AccountState = AccountState.Approved.ToString();

                    repository.Add(dbAcount);
                    repository.UnitOfWork.Commit();
                }
            }

            return(result == null ? null : result.ToCoreModel());
        }