コード例 #1
0
ファイル: UserAppService.cs プロジェクト: yuaruel/Monivault
        public async Task <UserDto> UpdateUser(EditUserDto input)
        {
            CheckUpdatePermission();

            if (string.IsNullOrEmpty(input.EmailAddress))
            {
                input.EmailAddress = RandomStringGeneratorUtil.GenerateFakeEmail();
            }

            var user = await _userManager.GetUserByIdAsync(input.Id);

            //MapEditUserDtoToEntity(input, user);
            user.EmailAddress = input.EmailAddress;
            user.Name         = input.Name;
            user.Surname      = input.Surname;
            user.UserName     = input.UserName;
            user.PhoneNumber  = input.PhoneNumber;
            user.IsActive     = input.IsActive;

            //Logger.Info("email for user: " + user.EmailAddress);
            CheckErrors(await _userManager.UpdateAsync(user));

            if (input.RoleNames != null)
            {
                CheckErrors(await _userManager.SetRoles(user, input.RoleNames));
            }

            return(await Get(input));
        }
コード例 #2
0
        public async Task UpdatePersonalDetail(PersonalDetailDto input)
        {
            var user = await GetCurrentUserAsync();

            user.Name         = input.FirstName;
            user.Surname      = input.LastName;
            user.PhoneNumber  = input.PhoneNumber;
            user.EmailAddress = input.Email ?? RandomStringGeneratorUtil.GenerateFakeEmail();

            await _userManager.UpdateAsync(user);
        }
コード例 #3
0
        public async Task <User> SignUpAsync(string name, string surname, string emailAddress, string phone, string userName, string plainPassword, bool isEmailConfirmed)
        {
            CheckForTenant();

            var tenant = await GetActiveTenantAsync();

            var user = new User
            {
                TenantId         = tenant.Id,
                Name             = name,
                Surname          = surname,
                EmailAddress     = emailAddress ?? RandomStringGeneratorUtil.GenerateFakeEmail(),
                PhoneNumber      = phone,
                IsActive         = true,
                UserName         = userName,
                IsEmailConfirmed = isEmailConfirmed,
                Roles            = new List <UserRole>()
            };

            user.SetNormalizedNames();

            foreach (var defaultRole in await _roleManager.Roles.Where(r => r.IsDefault).ToListAsync())
            {
                user.Roles.Add(new UserRole(tenant.Id, user.Id, defaultRole.Id));
            }

            await _userManager.InitializeOptionsAsync(tenant.Id);

            try
            {
                Logger.Info("About to save new user...");
                CheckErrors(await _userManager.CreateAsync(user, plainPassword));
                Logger.Info("Created new user, and next is to save...");
                await CurrentUnitOfWork.SaveChangesAsync();

                Logger.Info("S|aved new user.");
            }
            catch (Exception exc)
            {
                Logger.Error($"Err Message: {exc.Message}");
                Logger.Error($"StackTrace: {exc.StackTrace}");
            }

            return(user);
        }