public IActionResult GetPhotoShare(DataFile data) { var db = new ConMySQL(); try { Request.Headers.TryGetValue("Authorization", out var token); token = ((string)token).Replace("Bearer ", ""); var handler = new JwtSecurityTokenHandler(); JwtSecurityToken decodedValue = handler.ReadJwtToken(token); List <Claim> claimsList = decodedValue.Claims.ToList(); var id = claimsList.Find(x => x.Type == "unique_name").Value; string sql = string.Format("SELECT * FROM DataFile WHERE wwwPath like '%{0}'and Share = '{1}'", data.Path, id); DataTable SqlDataSet = db.getData(sql); Console.WriteLine(sql); DataFile obj = new DataFile(); foreach (DataRow dr in SqlDataSet.Rows) { obj.wwwPath = dr["wwwpath"].ToString(); } return(Ok(obj)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult checkRegister([FromBody] User data) { ResponseErr res = new ResponseErr(); try { var db = new ConMySQL(); string sql = $"SELECT * FROM User WHERE UserName = '******'"; DataTable dataTable = db.getData(sql); // Console.WriteLine(dataTable.Rows); User obj = new User(); foreach (DataRow dr in dataTable.Rows) { obj.userName = dr["userName"].ToString(); } // Console.WriteLine(obj.userName); if (obj.userName != null) { return(Ok("notEmpty")); } else { res.msg = "empty"; return(Ok("empty")); } } catch (Exception ex) { res.msg = ex.Message; res.data = data; // return res; return(BadRequest(res)); } }
public IActionResult login([FromBody] User data) { ResponseErr res = new ResponseErr(); try { var db = new ConMySQL(); string sql = $"SELECT * FROM User WHERE UserName = '******' and PassWord = '******'"; DataTable dataTable = db.getData(sql); // Console.WriteLine(dataTable.Rows); User obj = new User(); foreach (DataRow dr in dataTable.Rows) { obj.id = Convert.ToInt32(dr["id"]); obj.userName = dr["userName"].ToString(); // obj.passWord = dr["passWord"].ToString(); } // foreach (DataRow dataRow in dataTable.Rows) // { // foreach(var item in dataRow.ItemArray) // { // Console.WriteLine(item); // } // } data.id = obj.id; // Console.WriteLine(obj.userName); IActionResult response = Unauthorized(); if (obj.userName != null) { res.msg = "okay"; var tokenString = GenerateJSONWebToken(data); response = Ok(new { token = tokenString, Username = obj.userName }); return(Ok(response)); } else { res.msg = "empty"; return(Ok("empty")); } } catch (Exception ex) { res.msg = ex.Message; res.data = data; // return res; return(BadRequest(res)); } }
// IEnumerable<DataFile> public IEnumerable <DataFile> GetDataFiles([FromBody] DataFile GetData) { ResponseErr res = new ResponseErr(); DataFile data = new DataFile(); var db = new ConMySQL(); List <DataFile> list_result = new List <DataFile>(); try { Request.Headers.TryGetValue("Authorization", out var token); token = ((string)token).Replace("Bearer ", ""); var handler = new JwtSecurityTokenHandler(); JwtSecurityToken decodedValue = handler.ReadJwtToken(token); List <Claim> claimsList = decodedValue.Claims.ToList(); var id = claimsList.Find(x => x.Type == "unique_name").Value; // Console.WriteLine(claimsList); int share = 0; // int id = 23; // string sql = $"SELECT * FROM DataFile"; // string sql = string.Format("SELECT * FROM DataFile WHERE Path = '{0}'and IdUser = '******'", datafile.Path, id); string sql = string.Format("SELECT * FROM DataFile WHERE Path = '{0}'and IdUser = '******' and Share = '{2}'", GetData.Path, id, share); // Console.WriteLine(sql); DataTable SqlDataSet = db.getData(sql); foreach (DataRow dr in SqlDataSet.Rows) { DataFile obj = new DataFile(); obj.Id = Convert.ToInt32(dr["id"]); obj.NameFile = dr["namefile"].ToString(); obj.Path = dr["path"].ToString(); obj.Type = dr["type"].ToString(); obj.wwwPath = dr["wwwpath"].ToString(); obj.IdUser = Convert.ToInt32(dr["iduser"]); obj.MainFolder = Convert.ToInt32(dr["MainFolder"]); list_result.Add(obj); } // return Ok(claimsList); } catch (Exception ex) { res.msg = ex.Message; res.listdata = list_result; Console.WriteLine(ex.Message); // return BadRequest(); } // Console.WriteLine(JsonConvert.SerializeObject(list_result, Formatting.Indented)); return(list_result); }
public IActionResult Register([FromBody] User data) { ResponseErr res = new ResponseErr(); try { var db = new ConMySQL(); var pathsql = "/uploads/" + data.userName; string sqluser = $"INSERT INTO User(UserName, Password, Email) VALUES ('{data.userName}','{data.passWord}','{data.email}')"; db.executeQuery(sqluser); string sqlgetuser = $"SELECT * FROM User WHERE UserName = '******'"; DataTable dataTableGet = db.getData(sqlgetuser); User obj = new User(); foreach (DataRow dr in dataTableGet.Rows) { obj.id = Convert.ToInt32(dr["id"]); } Console.WriteLine(obj.id); // Console.WriteLine(pathsql); // string sqlfile = $"INSERT INTO DataFile(NameFile, Path, Type ,IdUser) VALUES ('{data.userName}','{pathsql}', 'Folder', '{obj.id}')"; // Console.WriteLine(sqlfile); // db.executeQuery(sqlfile); var pathFristFolder = "/" + data.userName; fristFolder(data.userName, obj.id); // Console.WriteLine(data.userName); string startupPath = Environment.CurrentDirectory; string path = startupPath + "/wwwroot/uploads/" + data.userName; Directory.CreateDirectory(path); res.msg = "okay"; return(Ok(res)); } catch (Exception ex) { res.msg = ex.Message; res.data = data; // return res; return(BadRequest(res)); } }