public IActionResult DeletePicByArticle([FromForm] ArticlePic source) { _logger.LogInformation(String.Format(@"****** PictureController DeletePicByArticle fired!! ******")); string rootdir = Directory.GetCurrentDirectory(); var localStr = _config.GetSection("AppSettings:ArticleUrl").Value; var pathToSave = rootdir + localStr + source.Article; pathToSave = pathToSave.Replace("DKS-API", "DKS-SPA"); var fileName = source.Article + "_" + source.No + ".jpg"; //新增檔名的全路徑 var fullPath = Path.Combine(pathToSave, fileName); bool isExist = System.IO.File.Exists(fullPath); if (isExist) { string birdUrl = rootdir + "\\Resources\\article_null.jpg"; //讀取API的那張鳥圖 using (var stream = new FileStream(fullPath, FileMode.Create)) { var fileStream = System.IO.File.OpenRead(birdUrl); fileStream.CopyTo(stream); fileStream.Close(); } var staff = _dksDao.SearchStaffByLOGIN(source.User); UserLog userlog = new UserLog(); userlog.PROGNAME = "F205"; userlog.LOGINNAME = staff.Result.LOGIN; userlog.HISTORY = "Delete Picture " + fileName; userlog.UPDATETIME = DateTime.Now; _dksDao.AddUserLogAsync(userlog); } return(Ok()); }
public async Task <IActionResult> Login(UserDto userForLoginDto) { var userFromRepo = await _dksDAO.SearchStaffByLOGIN(userForLoginDto.Account); if (userFromRepo == null) { return(Unauthorized()); } var claims = new[] { new Claim(ClaimTypes.NameIdentifier, userFromRepo.LOGINNAME.ToString()), new Claim(ClaimTypes.Name, userFromRepo.PROGNAME) }; var tokenName = _config.GetSection("AppSettings:Token").Value; var key = new SymmetricSecurityKey(Encoding.UTF8 .GetBytes(tokenName)); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha512Signature); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(claims), Expires = DateTime.Now.AddDays(1), SigningCredentials = creds }; var tokenHandler = new JwtSecurityTokenHandler(); var token = tokenHandler.CreateToken(tokenDescriptor); return(Ok(new { token = tokenHandler.WriteToken(token) })); }