예제 #1
0
        /// <summary>
        /// 更新用户
        /// </summary>
        /// <param name="userDto"></param>
        /// <param name="name"></param>
        /// <param name="email"></param>
        /// <param name="mobile"></param>
        /// <param name="username"></param>
        /// <param name="pwd"></param>
        private async Task <long> UpdateUser(WX_UserListDto userDto, string name, string email, string mobile, string username, string pwd)
        {
            var user = new WX_CreateOrUpdateUserInput();

            user.SendActivationEmail = false;
            user.SetRandomPassword   = false;
            user.User         = new WX_UserEditDto();
            user.User.Id      = userDto.Id;
            user.User.Name    = name;
            user.User.Surname = name;
            if (string.IsNullOrEmpty(email))
            {
                user.User.EmailAddress = username + "@jiangxi-isuzu.cn";
            }
            else
            {
                user.User.EmailAddress = email;
            }
            user.User.PhoneNumber = mobile;
            user.User.UserName    = username;
            user.User.Password    = pwd;
            user.User.IsActive    = true;
            user.User.ShouldChangePasswordOnNextLogin = false;
            user.User.IsTwoFactorEnabled = false;
            user.User.IsLockoutEnabled   = true;
            user.User.WeiXinUserId       = username;

            user.AssignedRoleNames   = new string[] { "User" };
            user.SendActivationEmail = false;
            user.SetRandomPassword   = false;

            return(await _wx_UserAppService.CreateOrUpdateUser(user));
        }
예제 #2
0
        protected virtual async Task <long> UpdateUserAsync(WX_CreateOrUpdateUserInput input)
        {
            Debug.Assert(input.User.Id != null, "input.User.Id should be set.");

            var user = await _wx_UserRepository.GetAsync(input.User.Id.Value);

            //Update user properties
            input.User.MapTo(user); //Passwords is not mapped (see mapping configuration)
            user.WeiXinUserId = input.User.WeiXinUserId;

            if (input.SetRandomPassword)
            {
                input.User.Password = User.CreateRandomPassword();
            }

            if (!input.User.Password.IsNullOrEmpty())
            {
                CheckErrors(await UserManager.ChangePasswordAsync(user, input.User.Password));
            }

            CheckErrors(await UserManager.UpdateAsync(user));

            //Update roles
            CheckErrors(await UserManager.SetRoles(user, input.AssignedRoleNames));

            if (input.SendActivationEmail)
            {
                user.SetNewEmailConfirmationCode();
                await _userEmailer.SendEmailActivationLinkAsync(user, input.User.Password);
            }

            return(input.User.Id.Value);
        }
예제 #3
0
 public async Task <long> CreateOrUpdateUser(WX_CreateOrUpdateUserInput input)
 {
     if (input.User.Id.HasValue)
     {
         return(await UpdateUserAsync(input));
     }
     else
     {
         return(await CreateUserAsync(input));
     }
 }
예제 #4
0
        protected virtual async Task <long> CreateUserAsync(WX_CreateOrUpdateUserInput input)
        {
            if (AbpSession.TenantId.HasValue)
            {
                await _userPolicy.CheckMaxUserCountAsync(AbpSession.GetTenantId());
            }
            var user = new WX_User();

            input.User.MapTo(user); //Passwords is not mapped (see mapping configuration)
            user.TenantId     = AbpSession.TenantId;
            user.WeiXinUserId = input.User.WeiXinUserId;

            //Set password
            if (!input.User.Password.IsNullOrEmpty())
            {
                CheckErrors(await UserManager.PasswordValidator.ValidateAsync(input.User.Password));
            }
            else
            {
                input.User.Password = User.CreateRandomPassword();
            }
            user.Password = new PasswordHasher().HashPassword(input.User.Password);
            user.ShouldChangePasswordOnNextLogin = input.User.ShouldChangePasswordOnNextLogin;

            //Assign roles
            user.Roles = new Collection <UserRole>();
            foreach (var roleName in input.AssignedRoleNames)
            {
                var role = await _roleManager.GetRoleByNameAsync(roleName);

                user.Roles.Add(new UserRole(AbpSession.TenantId, user.Id, role.Id));
            }

            var newuser = await _wx_UserRepository.InsertAsync(user);

            //CheckErrors(await UserManager.CreateAsync(user));
            await CurrentUnitOfWork.SaveChangesAsync(); //To get new user's Id.



            //Notifications
            await _notificationSubscriptionManager.SubscribeToAllAvailableNotificationsAsync(user.ToUserIdentifier());

            await _appNotifier.WelcomeToTheApplicationAsync(user);

            //Send activation email
            if (input.SendActivationEmail)
            {
                user.SetNewEmailConfirmationCode();
                await _userEmailer.SendEmailActivationLinkAsync(user, input.User.Password);
            }

            return(user.Id);
        }