Esempio n. 1
0
        public async Task <IDataResult <TokenModel> > SignInAsync(SignInModel signInModel)
        {
            var validation = new SignInModelValidator().Valid(signInModel);

            if (!validation.Success)
            {
                return(new ErrorDataResult <TokenModel>(validation.Message));
            }

            var userDomain = UserDomainFactory.Create(signInModel);

            userDomain.SignIn();

            signInModel = userDomain.Map <SignInModel>();

            var signedInModel = await UserRepository.SignInAsync(signInModel).ConfigureAwait(false);

            validation = new SignedInModelValidator().Valid(signedInModel);

            if (!validation.Success)
            {
                return(new ErrorDataResult <TokenModel>(validation.Message));
            }

            await AddUserLogAsync(signedInModel.UserId, LogType.SignIn).ConfigureAwait(false);

            var tokenModel = CreateJsonWebToken(signedInModel);

            return(new SuccessDataResult <TokenModel>(tokenModel));
        }
Esempio n. 2
0
        public async Task <IDataResult <TokenModel> > SignInAsync(SignInModel signInModel)
        {
            var validation = new SignInModelValidator().Valid(signInModel);

            if (!validation.Success)
            {
                return(new ErrorDataResult <TokenModel>(validation.Message));
            }

            UserDomainService.GenerateHash(signInModel);

            var signedInModel = await UserRepository.SignInAsync(signInModel);

            validation = new SignedInModelValidator().Valid(signedInModel);

            if (!validation.Success)
            {
                return(new ErrorDataResult <TokenModel>(validation.Message));
            }

            var addUserLogModel = new AddUserLogModel(signedInModel.UserId, LogType.SignIn);

            await UserLogApplicationService.AddAsync(addUserLogModel);

            var tokenModel = UserDomainService.GenerateToken(signedInModel);

            return(new SuccessDataResult <TokenModel>(tokenModel));
        }
Esempio n. 3
0
        public Task <IResult <string> > SignInAsync(SignInModel signInModel)
        {
            var validation = new SignInModelValidator().Valid(signInModel);

            if (!validation.Success)
            {
                return(Task.FromResult(validation));
            }

            var signedInModel = UserRepository.SignInAsync(signInModel).Result;

            validation = new SignedInModelValidator().Valid(signedInModel);
            if (!validation.Success)
            {
                return(Task.FromResult(validation));
            }

            var userLogModel = new UserLogModel(signedInModel.UserId, LogType.Login);

            UserLogDomain.SaveAsync(userLogModel);

            var jwt = CreateJwt(signedInModel);

            IResult <string> successResult = new SuccessResult <string>(jwt);

            return(Task.FromResult(successResult));
        }
        public IResult <string> SignIn(SignInModel signInModel)
        {
            var signInModelValidator = new SignInModelValidator().Valid(signInModel);

            if (!signInModelValidator.Success)
            {
                return(signInModelValidator);
            }

            var signedInModel = UserRepository.SignIn(signInModel);

            var signedInModelValidator = new SignedInModelValidator().Valid(signedInModel);

            if (!signedInModelValidator.Success)
            {
                return(signedInModelValidator);
            }

            var userLogModel = new UserLogModel(signedInModel.UserId, LogType.Login);

            UserLogDomain.Save(userLogModel);

            var jwt = CreateJwt(signedInModel);

            return(new SuccessResult <string>(jwt));
        }
Esempio n. 5
0
        public async Task <IDataResult <SignedInModel> > SignInAsync(SignInModel signInModel)
        {
            var validation = new SignInModelValidator().Valid(signInModel);

            if (!validation.Success)
            {
                return(new ErrorDataResult <SignedInModel>(validation.Message));
            }

            signInModel.Login = UserDomainService.GenerateHash(signInModel.Login);

            signInModel.Password = UserDomainService.GenerateHash(signInModel.Password);

            var signedInModel = await UserRepository.SignInAsync(signInModel);

            validation = new SignedInModelValidator().Valid(signedInModel);

            if (!validation.Success)
            {
                return(new ErrorDataResult <SignedInModel>(validation.Message));
            }

            await AddUserLogAsync(signedInModel.UserId, LogType.SignIn).ConfigureAwait(false);

            return(new SuccessDataResult <SignedInModel>(signedInModel));
        }
        public async Task <IDataResult <SignedInModel> > SignInAsync(SignInModel signInModel)
        {
            var validation = new SignInModelValidator().Valid(signInModel);

            if (!validation.Success)
            {
                return(ErrorDataResult <SignedInModel>(validation.Message));
            }

            UserDomainService.GenerateHash(signInModel);

            var signedInModel = await UserRepository.SignInAsync(signInModel);

            validation = new SignedInModelValidator().Valid(signedInModel);

            if (!validation.Success)
            {
                return(ErrorDataResult <SignedInModel>(validation.Message));
            }

            return(SuccessDataResult(signedInModel));
        }
Esempio n. 7
0
        public async Task <IDataResult <string> > SignInAsync(SignInModel signInModel)
        {
            var validation = new SignInModelValidator().Valid(signInModel);

            if (!validation.Success)
            {
                return(new ErrorDataResult <string>(validation.Message));
            }

            var signedInModel = await UserRepository.SignInAsync(signInModel);

            validation = new SignedInModelValidator().Valid(signedInModel);

            if (!validation.Success)
            {
                return(new ErrorDataResult <string>(validation.Message));
            }

            await AddUserLogAsync(signedInModel.UserId, LogType.SignIn);

            var jwt = CreateJwt(signedInModel);

            return(new SuccessDataResult <string>(jwt));
        }