Пример #1
0
        public async Task <LoginResultDto> Login(LoginDto model)
        {
            var result = new LoginResultDto();

            try
            {
                var signInResult = await _signInManager.PasswordSignInAsync(model.Username, model.Password, false, true);

                if (signInResult.Succeeded)
                {
                    var appUser = _userManager.Users.SingleOrDefault(r => r.UserName == model.Username);
                    if (appUser.EmailConfirmed)
                    {
                        result.SetInfo(true, "Login successfully");
                        result.User = _mapper.Map <IdentityUser, UserDto>(appUser);
                    }
                    else
                    {
                        result.SetInfo(false, "Email not confirmed yet");
                    }
                }
                else
                {
                    if (!signInResult.IsLockedOut)
                    {
                        result.SetInfo(false, "Username or password is incorrect");
                    }
                    else
                    {
                        result.SetInfo(false, "User has been locked out");
                    }
                }
            }
            catch (Exception ex)
            {
                result.SetInfo(false, ex.Message);
            }
            return(result);
        }
Пример #2
0
        public async Task <ActionResultDto> Register([FromBody] RegisterDto model)
        {
            ActionResultDto result = null;

            try
            {
                result = await _userMngService.Register(model, GenerateVerificationLink);

                return(result);
            }
            catch (Exception ex)
            {
                result = new LoginResultDto();
                result.SetInfo(false, ex.Message);
            }
            return(result);
        }
Пример #3
0
        public async Task <LoginResultDto> Login([FromBody] LoginDto model)
        {
            LoginResultDto result = null;

            try
            {
                result = await _userMngService.Login(model);

                if (result.IsSuccess)
                {
                    DateTime expiredTime = DateTime.MinValue;
                    result.Token          = _userMngService.GenerateJwtToken(result.User, out expiredTime);
                    result.ExpiredTimeUTC = expiredTime.ToUniversalTime();
                }
            }
            catch (Exception ex)
            {
                result = new LoginResultDto();
                result.SetInfo(false, ex.Message);
            }
            return(result);
        }