Exemple #1
0
        public UserByLoginOutputModel ConvertUserByLoginDTOToListUserByLoginOutputModel(string login)
        {
            UserManager            manager = new UserManager();
            List <UserByLoginDTO>  list    = manager.GetUserAndItRole(login);
            UserByLoginOutputModel userInf = null;

            foreach (UserByLoginDTO a in list)
            {
                if (userInf == null)
                {
                    userInf = new UserByLoginOutputModel()
                    {
                        FirstName = a.FirstName,
                        LastName  = a.LastName,
                        BirthDate = a.BirthDate,
                        Login     = a.Login,
                        Password  = a.Password,
                        Email     = a.Email,
                        Phone     = a.Phone,
                        Role      = new List <string>()
                    };
                    userInf.Role.Add(a.Role);
                }
                else
                {
                    userInf.Role.Add(a.Role);
                }
            }
            return(userInf);
        }
Exemple #2
0
        private ClaimsIdentity GetIdentity(string login, string password, string role)
        {
            Mapper mapper = new Mapper();
            UserByLoginOutputModel user = mapper.ConvertUserByLoginDTOToListUserByLoginOutputModel(login);

            if (user != null)
            {
                if (user.Role.Contains(role) == true && user.Password == password)
                {
                    List <Claim> claims = new List <Claim>()
                    {
                        new Claim(ClaimsIdentity.DefaultNameClaimType, user.Login),
                        new Claim(ClaimsIdentity.DefaultRoleClaimType, role)
                    };

                    ClaimsIdentity claimsIdentity = new ClaimsIdentity(claims, "Token", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);
                    return(claimsIdentity);
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }