Exemplo n.º 1
0
        public async Task <IAppUsers> ResolveUser(IPasswordHasher <SpecialAppUsers> hasher, string password)
        {
            var ggg = DbSetss(() => hasher.HashPassword(new SpecialAppUsers {
                Id = "12121SSS"
            }, "11212"));
            var ggf = DbSetss(() => 1);

            if (userResultType is UnauthorisedUser || userResultType is AnonymousUser)
            {
                return(userResultType);
            }

            var user = userResultType;

            var result = hasher.VerifyHashedPassword((SpecialAppUsers)user, user.PasswordHash, password);

            if (result == PasswordVerificationResult.Failed)
            {
                userResultType = UnauthorisedUser.Instance;
                return(UnauthorisedUser.Instance);
            }

            if (result == PasswordVerificationResult.SuccessRehashNeeded)
            {
                userResultType    = (SpecialAppUsers)user;
                user.PasswordHash = hasher.HashPassword((SpecialAppUsers)user, password);
                await usrMngService.UpdateAsync((SpecialAppUsers)user);
            }

            return(userResultType);
        }
Exemplo n.º 2
0
        private void CreateToken(IConfigurationRoot config, IAppUsers user, bool rememberMe = false)
        {
            var claims = new[]
            {
                //keep this sub at top this order is required. This sets the current user when getting instance of context
                new Claim(JwtRegisteredClaimNames.Sub, user.Email),
            };

            var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("AWESOMEKEYS!@#$%123456"));

            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);

            this.tokenExpiry = SetExpiry(rememberMe);

            var token = new JwtSecurityToken(
                issuer: "https://specialapp.com",
                audience: "https://specialapp.com",
                claims: claims,
                expires: tokenExpiry,
                signingCredentials: creds
                );

            this.token = token;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Public constructor to initialize product service instance
 /// </summary>
 public AppUsersController(IAppUsers appUserRepository)
 {
     _appUserRepository = appUserRepository;
 }
Exemplo n.º 4
0
 public ResolvedUser(IAppUsers userResultType, IUserManagerService usrMngService, ISpecialUOW uow)
 {
     this.userResultType = userResultType ?? UnauthorisedUser.Instance;
     this.usrMngService  = usrMngService;
     this.uow            = uow;
 }
Exemplo n.º 5
0
 public ResolvedUser()
 {
     this.userResultType = UnauthorisedUser.Instance;
 }