Example #1
0
        // [ValidationAspect(typeof(UserValidator))]
        public async Task <IResult> AddUser(User user)
        {
            try
            {
                await _dal.AddUserAsync(user);

                user.isManager = true;
                user.Password  = EncryptionPassword.Encrypt(user.Password);
                await _unitOfWork.CompleteAsync();

                return(new SuccessResult(BasicCrudOperationMessages.SUCCESS_ADD));
            }
            catch (Exception ex)
            {
                return(new FailResult($"{BasicCrudOperationMessages.FAIL_ADD} : \n Error Exception Message : {ex.Message}"));
            }
        }
        public async Task <IDataResult <AccessToken> > CreateAccessToken(string LoginName, string password)
        {
            string EncryptPassword = EncryptionPassword.Encrypt(password);

            IDataResult <User> user = await _userService.FindLoginNameAndPassword(LoginName, EncryptPassword);

            if (user.Success)
            {
                AccessToken accessToken = _tokenHandler.CreateAccessToken(user.Data);
                user.Data.RefreshToken        = accessToken.RefreshToken;
                user.Data.RefreshTokenEndDate = DateTime.Now.AddMinutes(_tokenOptions.RefreshTokenExpiration);
                await _unitOfWork.CompleteAsync();

                //await _userService.SaveRefreshToken(user.Data.ID, accessToken.RefreshToken);
                return(new SuccessDataResult <AccessToken>(accessToken, BasicCrudOperationMessages.CREATE_TOKEN));
            }
            else
            {
                return(new FailDataResult <AccessToken>(BasicCrudOperationMessages.FAIL_CREATE_TOKEN + $" \n {user.Message}"));
            }
        }