Ejemplo n.º 1
0
        public async Task<SignInInfoDto> SignInAsync(SignInDto signInDto)
        {
            var user = await _userRepository.FindUserByAsync(new Filter("Login", signInDto.Login));

            if (user == null || !PasswordHash.ValidatePassword(signInDto.Password, user.Password))
            {
                return new SignInInfoDto() { State = UserState.NotFound };
            }
            else
            {
                var result = new SignInInfoDto() { Sid = user.Sid, Name = user.Name, Login = user.Login, State = UserState.Success };
                if (!user.Activated) result.State = UserState.NotActivated;
                if (!user.Enabled) result.State = UserState.Locked;
                return result;
            }

        }
Ejemplo n.º 2
0
        private void SignIn(SignInInfoDto userInfo, bool rememberMe)
        {
            var claims = new List<Claim>
            {
                new Claim(ClaimTypes.NameIdentifier, userInfo.Login),
                new Claim(ClaimTypes.Sid, userInfo.Sid),
            };

            if (userInfo.Name != null)
            {
                claims.Add(new Claim(ClaimTypes.Name, userInfo.Name));
            }
            // create required claims
            var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

            AuthenticationManager.SignIn(new AuthenticationProperties()
            {
                AllowRefresh = true,
                IsPersistent = rememberMe,
                ExpiresUtc = DateTime.UtcNow.AddDays(7)
            }, identity);
        }