예제 #1
0
파일: UserService.cs 프로젝트: stylkyn/ess
        public async Task <Response <UserResponse> > AuthentificationAdmin(AuthentificationRequest request)
        {
            var user = await _uow.Users.GetUser(request.Email);

            if (user == null)
            {
                return(new Response <UserResponse>(ResponseStatus.NotFound, null, ResponseMessagesConstans.NotFound));
            }

            if (!user.HasAdminAccess)
            {
                return(new Response <UserResponse>(ResponseStatus.NotFound, null, ResponseMessagesConstans.NotFound));
            }

            if (user.Password == null)
            {
                return(new Response <UserResponse>(ResponseStatus.BadRequest, null, ResponseMessagesConstans.PasswordIsNotValid));
            }

            var passwordRequestHashed = _cryptographyLibrary.CalculateHash(request.Password);

            if (passwordRequestHashed != user.Password)
            {
                return(new Response <UserResponse>(ResponseStatus.BadRequest, null, ResponseMessagesConstans.PasswordIsNotValid));
            }


            var token = _authentificationLibrary.GenerateJWT(user);

            return(new Response <UserResponse>(ResponseStatus.Ok, _mapService.MapUser(user, token)));
        }
예제 #2
0
        public AuthenticationResult Authenticate(AuthentificationRequest authenticationRequest)
        {
            var user = GetUserByIdPassword(authenticationRequest.Identifier, authenticationRequest.Password);

            AuthenticationResult authResult = new AuthenticationResult();

            if (user == null)
            {
                authResult.IsSuccess = false;
            }
            else
            {
                authResult.User      = user;
                authResult.IsSuccess = true;
            }

            return(authResult);
        }
예제 #3
0
        public async Task <IHttpActionResult> AuthentificationAdmin([FromBody] AuthentificationRequest request)
        {
            var response = await _userService.AuthentificationAdmin(request);

            return(new CreateResult(response));
        }
 public AuthenticationResult Authenticate([FromBody] AuthentificationRequest authentificationRequest)
 {
     return(dal.Authenticate(authentificationRequest));
 }