// encoding token private async Task <string> BuildToken_MB(ObjLogin user) { var da = new Liste_UtilisateurDA(_context); var data = await da.Login(user.UserName, user.Password); if (data.IDUtilisateur > 0) { var claims = new[] { new Claim(JwtRegisteredClaimNames.Sub, user.UserName), new Claim(JwtRegisteredClaimNames.Sub, user.Password), }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"])); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken(_config["Jwt:Issuer"], _config["Jwt:Issuer"], claims, expires: DateTime.Now.AddMinutes(30), //expire time 30 min signingCredentials: creds); return(new JwtSecurityTokenHandler().WriteToken(token)); } else { return(new JwtSecurityTokenHandler().WriteToken(null)); } }
public async Task <IActionResult> Get(string id, string pass) { var da = new Liste_UtilisateurDA(_context); try { var data = await da.Login(id, pass); return(Ok(data)); } catch (System.Exception) { return(Forbid()); } }
// [Route("listevent")] public async Task <IActionResult> Login_MB([FromHeader] string strToken) { try { HttpClientHandler handler = new HttpClientHandler() { Proxy = new WebProxy(Commons.Http), UseProxy = true, }; // HttpClient client = new HttpClient(handler); // var byteArray = Encoding.ASCII.GetBytes(_config["Jwt:Key"]); // var objHeader = client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); // get string token var strtoken = strToken.Split("=="); var handlers = new JwtSecurityTokenHandler(); var decode = handlers.ReadToken(strtoken[0]) as JwtSecurityToken; var arrsub = decode.Payload.Sub.Replace("[", "").Replace("]", "").Replace("\\", "").Replace("\"", "").Trim().Split(','); string username = arrsub[0] + ""; string pass = arrsub[1] + ""; if (username.Trim() != "" && pass.Trim() != "") { var da = new Liste_UtilisateurDA(_context); var daEvent = new Enquete_SocieteDA(_context); var data = await da.Login(username, pass); if (data.IDUtilisateur > 0) { // return Ok(); return(Ok(new ApiResultDTO(data, strToken))); } else { return(NotFound(new ApiResultDTO(data, "404", "Not Found"))); } } else { return(BadRequest(new ApiResultDTO("", "400", ""))); } } catch (Exception err) { return(BadRequest(new ApiResultDTO("", "400", err.ToString()))); } }
public async Task <IActionResult> filter_EventMB(string societe, string strToken, string lieu = "", string idIntermediation = "") { try { var DA = new Enquete_SocieteDA(_context); List <string> str = new List <string>(); str.Add(strToken); // Decode char token var objUser = Commons.Decode(str.ToArray()); if (objUser.UserName.Trim() != "" && objUser.Password.Trim() != "") { var da = new Liste_UtilisateurDA(_context); var data = await da.Login(objUser.UserName, objUser.Password); if (data.IDUtilisateur > 0) { var obj = DA.LoadEvent(data.IDUtilisateur, Convert.ToInt32(societe), lieu, idIntermediation); await Task.WhenAll(obj); if (obj.Result.Count > 0) { return(Ok(new ApiResultDTO(obj.Result, strToken))); } else { return(NotFound(new ApiResultDTO(obj.Result, "404", "Not Found"))); } } else { return(NotFound(new ApiResultDTO(data, "404", "Not Found"))); } } else { return(NotFound(new ApiResultDTO("", "404", "Not Found"))); } } catch (Exception err) { return(BadRequest(new ApiResultDTO("", "400", err.ToString()))); } }
public async Task <IActionResult> List_IntermediationMB(string strToken) { try { var DA = new Enquete_SocieteDA(_context); List <string> str = new List <string>(); str.Add(strToken); // Decode char token var objUser = Commons.Decode(str.ToArray()); if (objUser.UserName.Trim() != "" && objUser.Password.Trim() != "") { var da = new Liste_UtilisateurDA(_context); var data = await da.Login(objUser.UserName, objUser.Password); if (data.IDUtilisateur > 0) { var obj = _context.Intermediation.Where(x => x.Intermediation1 != null).Select(x => x.Intermediation1).Distinct().ToListAsync(); await Task.WhenAll(obj); if (obj.Result.Count > 0) { return(Ok(new ApiResultDTO(obj.Result, strToken))); } else { return(NotFound(new ApiResultDTO(obj.Result, "404", "Not Found"))); } } else { return(NotFound(new ApiResultDTO(data, "404", "Not Found"))); } } else { return(NotFound(new ApiResultDTO("", "404", "Not Found"))); } } catch (Exception err) { return(BadRequest(new ApiResultDTO("", "400", err.ToString()))); } }
public async Task <IActionResult> InsertUpdate_Parametres(int IDParametreServicePrograme, int IDListeService, string Temps, string Titres, string Contenu, string strToken) { var DA = new Parametres_ServiceProgrameDA(_context); try { List <string> str = new List <string>(); str.Add(strToken); // Decode char token var objUser = Commons.Decode(str.ToArray()); if (objUser.UserName.Trim() != "" && objUser.Password.Trim() != "") { var da = new Liste_UtilisateurDA(_context); var data = await da.Login(objUser.UserName, objUser.Password); if (data.IDUtilisateur > 0) { var res = DA.InsertUpdate_Parametres(IDParametreServicePrograme, IDListeService, Temps, Titres, Contenu); await Task.WhenAll(res); if (res.Result > 0) { return(Ok(new ApiResultDTO(res.Result, strToken))); } else { return(BadRequest(new ApiResultDTO(0, "400", "Bad Request"))); } } else { return(NotFound(new ApiResultDTO(data, "404", "Not Found"))); } } else { return(NotFound(new ApiResultDTO("", "404", "Not Found"))); } } catch (Exception err) { return(BadRequest(new ApiResultDTO(0, "400", err.ToString()))); } }
public async Task <IActionResult> LoadData_Parameter(string idListeService, string strToken) { try { var DA = new Parametres_ServiceProgrameDA(_context); List <string> str = new List <string>(); str.Add(strToken); // Decode char token var objUser = Commons.Decode(str.ToArray()); if (objUser.UserName.Trim() != "" && objUser.Password.Trim() != "") { var da = new Liste_UtilisateurDA(_context); var data = await da.Login(objUser.UserName, objUser.Password); if (data.IDUtilisateur > 0) { var obj = DA.LoadData_Parametres(Convert.ToInt32(idListeService)); await Task.WhenAll(obj); if (obj.Result.Count > 0) { return(Ok(new ApiResultDTO(obj.Result, strToken))); } else { return(NotFound(new ApiResultDTO(obj.Result, "404", "Not Found"))); } } else { return(NotFound(new ApiResultDTO(data, "404", "Not Found"))); } } else { return(NotFound(new ApiResultDTO("", "404", "Not Found"))); } } catch (Exception err) { return(BadRequest(new ApiResultDTO("", "400", err.ToString()))); } }
public async Task <IActionResult> updateAvatarMB(string idDocument, string strToken) { try { var DA = new Parametres_ServiceProgrameDA(_context); List <string> str = new List <string>(); str.Add(strToken); // Decode char token var objUser = Commons.Decode(str.ToArray()); if (objUser.UserName.Trim() != "" && objUser.Password.Trim() != "") { var da = new Liste_UtilisateurDA(_context); var data = await da.Login(objUser.UserName, objUser.Password); if (data.IDUtilisateur > 0) { int intIdidDocument = Convert.ToInt32(idDocument); var file = Request.Form.Files[0]; string folderName = "FileUpload/Photodidentite"; string webRootPath = "wwwroot"; string newPath = Path.Combine(webRootPath, folderName); if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } if (file.Length < 1 && intIdidDocument < 1) { return(BadRequest(new ApiResultDTO(0, "400", "Bad Request"))); } // File name string fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); string name = fileName.Split('.')[0]; string fullPath = Path.Combine(newPath, fileName); string extension = fileName.Split('.')[1]; using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); } var res = new ContactDA(_context).Update_MediathequeDocument(intIdidDocument, name, extension); await Task.WhenAll(res); if (res.Result == 1) { _context.SaveChanges(); return(Ok(new ApiResultDTO(1, strToken))); } else { return(BadRequest(new ApiResultDTO(0, "400", "Bad Request"))); } } else { return(NotFound(new ApiResultDTO(data, "404", "Not Found"))); } } else { return(NotFound(new ApiResultDTO("", "404", "Not Found"))); } } catch (System.Exception err) { return(BadRequest(new ApiResultDTO(0, "400", err.ToString()))); } }