public ActionResult Login(AppUser user, bool permanecerLogado) { try { var pwd = new PasswordEncoder(); var hash = pwd.Encode(pwd.DefaultSalt[5] + user.Password, EncryptType.SHA_512); AppUser u = db.AppUsers.FirstOrDefault(o => o.Email.Equals(user.Email) && o.Password.Equals(hash)); if (u != null) { FormsAuthentication.SetAuthCookie(u.Email, permanecerLogado); return(RedirectToAction("Index", "Products")); } else { ModelState.AddModelError("", "Usuario ou senha inváidos"); } return(View()); } catch (Exception ex) { ApplicationLog.Save(ex, ApplicationLog.ImpactLevel.High); return(View()); } }
public async Task <ActionResult> CreateAccount(AppUser user) { try { if (ModelState.IsValid) { var pwd = new PasswordEncoder(); var hash = pwd.Encode(pwd.DefaultSalt[5] + user.Password, EncryptType.SHA_512); user.Password = hash; var role = db.UserRoles.FirstOrDefault(x => x.Id.ToString() == "822f4875-0aca-11e8-bbbb-7a79195ecca3"); user.UserRoleId = role.Id; db.AppUsers.Add(user); await db.SaveChangesAsync(); AppUser u = db.AppUsers.FirstOrDefault(o => o.Name.Equals(user.Name) && o.Password.Equals(hash)); if (u != null) { FormsAuthentication.SetAuthCookie(u.Email, true); return(RedirectToAction("Index", "Products")); } else { ModelState.AddModelError("", "Erro"); } return(RedirectToAction("Index", "Products")); } return(View(user)); } catch (Exception ex) { ApplicationLog.Save(ex, ApplicationLog.ImpactLevel.High); return(View()); } }
public void Insert(Guid Guid, string Host, DateTime Timestamp, string LogLevel, string Thread, string Message, string Exception) { var item = new ApplicationLog(); item.Guid = Guid; item.Host = Host; item.Timestamp = Timestamp; item.LogLevel = LogLevel; item.Thread = Thread; item.Message = Message; item.Exception = Exception; item.Save(UserName); }