示例#1
0
        public Either <UserServicesStatus, bool> CreateUser(Domain.Entity.User user)

        {
            var checkemail = _userServices.Login(user.email);

            if (!checkemail.IsNull())
            {
                return(UserServicesStatus.EmailExisting);
            }
            var res = _userServices.Add(user);

            if (!res)
            {
                return(UserServicesStatus.ServicesFailed);
            }
            return(res);
        }
示例#2
0
        public static string GenerateToken(Domain.Entity.User identityUser)
        {
            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = Encoding.ASCII.GetBytes("!@@!789456");
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim("ID", identityUser.id),
                    new Claim("Name", identityUser.name),
                    new Claim("Role", identityUser.name)
                }),

                Expires = DateTime.UtcNow.AddDays(10),
                //SigningCredentials = new
                //SigningCredentials(
                //    new SymmetricSecurityKey(key),
                //    SecurityAlgorithms.HmacSha256Signature),
            };

            var token = tokenHandler.CreateToken(tokenDescriptor);

            return(tokenHandler.WriteToken(token));
        }