Beispiel #1
0
        public async Task <(Result Result, AppUserDTO AppUserDTO)> FindAppUserByIdAsync(string appUserId)
        {
            var user = await _userManager.FindByIdAsync(appUserId);

            return(user != null
               ? (Result.Success(), _mapper.Map <AppUserDTO>(user))
               : (IdentityResultExtensions.AppUserNotFound(), new AppUserDTO()));
        }
Beispiel #2
0
        public async Task <Result> SignInAsync(string appUserId, bool isPasrsistent)
        {
            var user = await _userManager.FindByIdAsync(appUserId);

            if (user != null)
            {
                await SignInManager.SignInAsync(user, isPasrsistent);
            }

            return(IdentityResultExtensions.AppUserNotFound());
        }
Beispiel #3
0
        public async Task <Result> RemoveAppUserAsync(string appUserId)
        {
            AppUser appUser = await _userManager.FindByIdAsync(appUserId);

            if (appUser != null)
            {
                var result = await _userManager.DeleteAsync(appUser);

                return(result.Succeeded ? Result.Success() : result.ToApplicationResult());
            }

            return(IdentityResultExtensions.AppUserNotFound());
        }
Beispiel #4
0
        public async Task <Result> PasswordSignInAsync(string email, string password, bool isParsistent)
        {
            var user = await _userManager.FindByEmailAsync(email);

            if (user != null)
            {
                var result = await SignInManager.PasswordSignInAsync(user, password, isParsistent, false);

                return(result.Succeeded ? Result.Success() : IdentityResultExtensions.IncorrectlyEnteredEmailOrPassword());
            }

            return(IdentityResultExtensions.AppUserNotFound());
        }
Beispiel #5
0
        public async Task <(Result Result, string AppUserId)> CreateAppUserAsync(string userName, string email, string password)
        {
            var user = await _userManager.FindByEmailAsync(email);

            if (user != null)
            {
                return(IdentityResultExtensions.EmailAreadyUse(), "");
            }

            user = new AppUser()
            {
                UserName = userName,
                Email    = email
            };
            var result = await _userManager.CreateAsync(user, password);

            return(result.ToApplicationResult(), user.Id);
        }