private void SaveUser(UserDataDTO userProfile)
 {
     _unitOfWork.Users.Add(new User
     {
         Email        = userProfile.Email,
         PasswordHash = HashcodeUtil.HashPassword(userProfile.Password),
         Name         = userProfile.Name,
         SurName      = userProfile.Surname,
         Info         = new UserInfo()
     });
     _unitOfWork.Complete();
 }
예제 #2
0
        public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            DatabaseContext contextDB = new DatabaseContext();

            UnitOfWork unitOfWork = new UnitOfWork(contextDB);

            Console.WriteLine($"name: {context.UserName} pass: {context.Password}==============================================");

            User user = null;

            bool isValidCredential = false;

            try {
                //user = unitOfWork.Users.LoginUser(context.UserName, HashcodeUtil.GetHashCodeString( context.Password ) );
                //unitOfWork.Complete();

                user = unitOfWork.Users.GetAll().First(u => u.Email.Equals(context.UserName));
                isValidCredential = HashcodeUtil.VerifyHashedPassword(user.PasswordHash, context.Password);
            } catch (InvalidOperationException e)
            {
                Console.WriteLine(e);
            }
            if (!isValidCredential)
            {
                Console.WriteLine("ResourcePasswordOwnerValidator:  User is null !!!!!!!!!!!!!");
                context.Result = null;
            }
            else
            {
                Console.WriteLine("ResourcePasswordOwnerValidator:  User is NOT NOT NOT null !!!!!!!!!!!!!");

                context.Result = new GrantValidationResult(user.UserId.ToString(), "password");
            }

            return(Task.FromResult(0));
        }