public static void UpdateUser(Entity.CMS_Account account) { if (account.password != null) { var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(account.password); account.password = System.Convert.ToBase64String(plainTextBytes); } using (var context = new Entity.OiWeb()) { var query = (from c in context.CMS_Account where c.idAccount == account.idAccount select c).First(); query.name = account.name; if (account.password == "" || account.password == null) { account.password = query.password; } query.password = account.password; query.email = account.email; query.isActive = account.isActive; context.SaveChanges(); } }
public static Entity.CMS_Account IsValidEmail(Entity.CMS_Account account) { using (var context = new Entity.OiWeb()) { var query = from o in context.CMS_Account where o.email == account.email select o; return(query.FirstOrDefault()); } }
public static void SaveUser(Entity.CMS_Account account) { using (var context = new Entity.OiWeb()) { account.dtCreate = DateTime.Now; var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(account.password); account.password = System.Convert.ToBase64String(plainTextBytes); context.CMS_Account.Add(account); context.SaveChanges(); } }
public static Entity.CMS_Account IsValid(Entity.CMS_Account account) { //Convert String to 64 var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(account.password); account.password = System.Convert.ToBase64String(plainTextBytes); //Convert 64 to String //var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData); //return System.Text.Encoding.UTF8.GetString(base64EncodedBytes); using (var context = new Entity.OiWeb()) { var query = from o in context.CMS_Account where o.email == account.email && o.password == account.password select o; return(query.FirstOrDefault()); } }
public async Task <ActionResult> LoginIsValid(LoginViewModel model) { if (ModelState.IsValid) { Entity.CMS_Account account = new Entity.CMS_Account(); Entity.CMS_AccountLoginLog accountLoginLog = new Entity.CMS_AccountLoginLog(); account.email = model.Email; account.password = model.Password; var user = Business.CMS_Account.IsValid(account); if (user != null) { if (model.returnUrl == null) { model.returnUrl = "Dashboard"; } #region Registra Acesso accountLoginLog.idAccount = user.idAccount; accountLoginLog.IsValid = true; accountLoginLog.dtRegister = DateTime.Now; Business.CMS_AccountLoginLog.Create(accountLoginLog); #endregion Session.Add("User", user); Response.Redirect("/Grupos"); } else { #region Registra Acesso Falho account = Business.CMS_Account.IsValidEmail(account); if (account != null) { accountLoginLog.idAccount = account.idAccount; accountLoginLog.IsValid = false; accountLoginLog.dtRegister = DateTime.Now; Business.CMS_AccountLoginLog.Create(accountLoginLog); } #endregion ViewBag.Error = "has-error"; return(View("/Views/Account/Login.cshtml", model)); } } ViewBag.Error = "has-error"; return(View("/Views/Account/Login.cshtml", model)); }
public RedirectResult SaveUpdateUser(Entity.CMS_Account user) { Business.CMS_Account.UpdateUser(user); return(Redirect("/Usuarios/")); }