Ejemplo n.º 1
0
        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)));
        }
Ejemplo n.º 2
0
        public async Task <UserModel> Add(string email, string password = null)
        {
            if (email == null)
            {
                return(null);
            }

            var userExist = await _uow.Users.GetUser(email);

            if (userExist != null)
            {
                return(null);
            }

            var user = new UserModel();

            user.Email    = email;
            user.Password = password != null?_cryptographyLibrary.CalculateHash(password) : null;

            user = await _uow.Users.InsertAsync(user);

            return(user);
        }