public bool SaveUser(DWBIUser user) { try { using (var db = new DWContext()) { using (MySqlConnection conn = new MySqlConnection(db.ConnectionString)) { conn.Open(); MySqlCommand cmd = new MySqlCommand("insert into user(Name, CompanyID, UserRole, isAdmin, UserID) values('" + user.Name + "', '" + user.CompanyID + "', '" + (int)user.UserRole + "', '" + 0 + "', '" + user.UserID + "')", conn); cmd.ExecuteNonQuery(); } } return(true); } catch (Exception ex) { return(true); } }
public DWBIUser Login([FromBody] LoginDto model) { //RegistAll(); //Register("*****@*****.**", "dwbi11!!"); //return null; if (!model.Email.Contains("@")) { //string dEmail = HttpUtility.UrlDecode(model.Email); model.Email = model.Email; string loginID = Encryptor.Decrypt(model.Email, biKey, biIV); if (string.IsNullOrEmpty(loginID)) { return(null); } model.Email = loginID; model.Password = "******"; } try { //UserController uc = new UserController(); //20200109 김태규 수정 배포 UserController uc = new UserController(null, null, null); ApplicationDbContext context = new ApplicationDbContext(); var result = _signInManager.PasswordSignInAsync(model.Email, model.Password, false, false).Result; if (result.Succeeded) { var appUser = _userManager.Users.SingleOrDefault(r => r.Email == model.Email); DWBIUser userInfo = uc.GetByKey(model.Email, Request); userInfo.Token = GenerateJwtToken(model.Email, appUser).Result; var user = GetCurrentUserAsync().Result; Encryptor ec1 = new Encryptor(fineKey, fineIV); Encryptor ec2 = new Encryptor(fineKey, fineIV); userInfo.key = ec1.Encrypt(model.Email.Split('@')[0]); userInfo.RoleIDKey = ec2.Encrypt(userInfo.RoleID); //ClaimsPrincipal currentUser = this.User; //var currentUserName = currentUser.FindFirst(ClaimTypes.NameIdentifier).Value; //var user2 = await _userManager.FindByNameAsync(currentUserName); return(userInfo); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(">>>>" + ex.InnerException.Message + ex.Message); return(new DWBIUser { Token = ex.InnerException.Message + ex.Message }); } // finally { } throw new ApplicationException("INVALID_LOGIN_ATTEMPT"); }
public bool Update([FromBody] DWBIUser user) { // 세션이 끊긴 상태 if (DWUserInfo == null || DWUserInfo.ID == 0) { Response.StatusCode = 600; return(false); } using (var db = new DWContext()) { using (MySqlConnection conn = new MySqlConnection(db.ConnectionString)) { conn.Open(); string update_sql = $@" update user set name = '{user.Name}' , companyID = {user.CompanyID} , UserID = '{user.UserID}' , UserRole= {(int)user.UserRole} where id = '{user.ID}'"; if (!String.IsNullOrWhiteSpace(user.Password)) { Encryptor ec = new Encryptor(fineKey, fineIV); string encrypt_password = ec.Encrypt(user.Password); update_sql = $@" update user set name = '{user.Name}' , companyID = {user.CompanyID} , UserID = '{user.UserID}' , UserRole= {(int)user.UserRole} , PW = '{encrypt_password}' where id = '{user.ID}'"; } MySqlCommand cmd = new MySqlCommand(update_sql, conn); cmd.ExecuteNonQuery(); } } return(true); }
public bool Update([FromBody] DWBIUser user) { using (var db = new DWContext()) { using (MySqlConnection conn = new MySqlConnection(db.ConnectionString)) { conn.Open(); MySqlCommand cmd = new MySqlCommand("update user set name='" + user.Name + "', companyID= '" + user.CompanyID + "', UserID= '" + user.UserID + "', UserRole= '" + (int)user.UserRole + "' where id=" + user.ID, conn); cmd.ExecuteNonQuery(); } } return(true); }
public string ChangeUserCompanyInfo(string companyCode, string companyName) { // 세션이 끊긴 상태 if (DWUserInfo == null || DWUserInfo.ID == 0) { Response.StatusCode = 600; return(null); } DWBIUser dwbiUser = DWUserInfo; dwbiUser.CompanyCode = int.Parse(companyCode); dwbiUser.CompanyName = companyName; HttpContext.Session.SetObject("DWUserInfo", dwbiUser); return("success"); }
public async Task <object> Register([FromBody] DWBIUser model) { var user = new IdentityUser { UserName = model.UserID, Email = model.UserID }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { //UserController uc = new UserController(); //20200109 김태규 수정 배포 UserController uc = new UserController(null, null, null); uc.SaveUser(model); return(true); } throw new ApplicationException("UNKNOWN_ERROR"); }
//20200109 김태규 수정 배포 //public bool Delete() public bool DeleteUser([FromBody] DWBIUser user) { // 세션이 끊긴 상태 if (DWUserInfo == null || DWUserInfo.ID == 0) { Response.StatusCode = 600; return(false); } using (var db = new DWContext()) { using (MySqlConnection conn = new MySqlConnection(db.ConnectionString)) { conn.Open(); MySqlCommand cmd = new MySqlCommand("delete from user where id=" + user.ID, conn); cmd.ExecuteNonQuery(); } } return(true); }
public bool SaveUser(DWBIUser user) { // 세션이 끊긴 상태 if (DWUserInfo == null || DWUserInfo.ID == 0) { Response.StatusCode = 600; return(false); } try { using (var db = new DWContext()) { using (MySqlConnection conn = new MySqlConnection(db.ConnectionString)) { conn.Open(); Encryptor ec = new Encryptor(fineKey, fineIV); string encrypt_password = ec.Encrypt(user.Password); MySqlCommand cmd = new MySqlCommand( $@" insert into user (Name, CompanyID, UserRole, isAdmin, UserID, PW) values('{user.Name}', {user.CompanyID}, {(int)user.UserRole}, 0, '{user.UserID}', '{encrypt_password}')", conn); cmd.ExecuteNonQuery(); } } return(true); } catch (Exception ex) { return(true); } }
private List <KPI> GetKPIs(int v, KPIController c, DWBIUser user, string companyCode) { return(c.GetKpiByPage(v, companyCode)); }
public DWBIUser GetByKey(string id, HttpRequest Request) { id = "*****@*****.**"; try { List <DWBIUser> list = new List <DWBIUser>(); using (var db = new DWContext()) { using (MySqlConnection conn = new MySqlConnection(db.ConnectionString)) { conn.Open(); MySqlCommand cmd = new MySqlCommand("get_userByID", conn); //cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add(new MySqlParameter("@id", id)); using (var reader = cmd.ExecuteReader()) { //return new DWBIUser //{ // Name = "Test2" //}; if (!reader.HasRows) { return(null); } reader.Read(); DWBIUser user = new DWBIUser(); user.ID = Convert.ToInt32(reader["Id"]); user.Name = reader["Name"].ToString(); user.CompanyID = Convert.ToInt32(reader["CompanyID"]); user.CompanyCode = Convert.ToInt32(reader["Code"]); if (user.CompanyCode == 2000) { user.CompanyCode = 1100; } user.UserID = reader["UserID"].ToString(); user.RoleID = reader["RoleID"].ToString(); user.CompanyName = reader["CompanyName"].ToString(); user.IsAdmin = Convert.ToBoolean(reader["IsAdmin"]); user.UserRole = (Role)Convert.ToInt32(reader["UserRole"]); if (user.UserRole == Role.Manager) { if (Request != null && !string.IsNullOrEmpty(Request.Headers["company"])) { user.CompanyCode = int.Parse(Request.Headers["company"]); } } return(user); } } } } catch (MySqlProtocolException ex) { throw new Exception(ex.Message + ex.InnerException.Message); } }
public bool Post([FromBody] DWBIUser user) { return(SaveUser(user)); }
public DWBIUser Login([FromBody] LoginDto model) { if (!model.Email.Contains("@")) { //string dEmail = HttpUtility.UrlDecode(model.Email); model.Email = model.Email; string loginID = Encryptor.Decrypt(model.Email, biKey, biIV); if (string.IsNullOrEmpty(loginID)) { return(null); } model.Email = loginID; model.Password = "******"; } DWBIUser dwbiUser = new DWBIUser(); try { using (var db = new DWContext()) { using (MySqlConnection conn = new MySqlConnection(db.ConnectionString)) { conn.Open(); Encryptor ec = new Encryptor(fineKey, fineIV); string encrypt_password = ec.Encrypt(model.Password); MySqlCommand cmd = new MySqlCommand("get_userInfo", conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add(new MySqlParameter("@userID", model.Email)); cmd.Parameters.Add(new MySqlParameter("@pw", encrypt_password)); DataTable dt = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(cmd); adapter.Fill(dt); if (dt != null && dt.Rows.Count == 1) { dwbiUser.ID = Convert.ToInt32(dt.Rows[0]["ID"].ToString()); dwbiUser.Name = dt.Rows[0]["Name"].ToString(); dwbiUser.UserID = dt.Rows[0]["UserID"].ToString(); dwbiUser.IsAdmin = (dt.Rows[0]["IsAdmin"].ToString() == "0") ? false : true; dwbiUser.RoleID = dt.Rows[0]["RoleID"].ToString(); dwbiUser.UserRole = (Role)int.Parse(dt.Rows[0]["UserRole"].ToString()); dwbiUser.CompanyID = Convert.ToInt32(dt.Rows[0]["CompanyID"].ToString()); dwbiUser.CompanyCode = Convert.ToInt32(dt.Rows[0]["code"].ToString()); dwbiUser.CompanyName = dt.Rows[0]["companyName"].ToString(); dwbiUser.Companies = GetCompanies(dwbiUser.ID); dwbiUser.key = ec.Encrypt(dwbiUser.UserID.Split('@')[0]); dwbiUser.RoleIDKey = ec.Encrypt(dwbiUser.RoleID); // Admin, Manager인 경우 회사 코드를 변경해 주고, 회사 정보를 설정 if (dwbiUser.UserRole != Role.Member) { dwbiUser.CompanyCode = 1200; // 모든 회사 코드 조회해서 넘겨줌 //dwbiUser.Companies = GetAllCompanies(); } HttpContext.Session.SetObject("DWUserInfo", dwbiUser); } } } } catch (Exception ex) { dwbiUser.Token = ex.InnerException.Message + ex.Message; } return(dwbiUser); }