public async Task <IActionResult> Register(RegisterViewModel userInfo) { if (ModelState.IsValid) { var user = new Bodeguero { UserName = userInfo.RUC, Email = userInfo.Email, FirstName = userInfo.FirstName, LastName = userInfo.LastName, Address = userInfo.Address, DNI = userInfo.DNI, RUC = userInfo.RUC, RazonSocial = userInfo.RazonSocial }; var result = await _userManager.CreateAsync(user, userInfo.Password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, "Bodeguero"); return(RedirectToAction("Login", new LoginViewModel { RUC = user.RUC, Password = userInfo.Password })); } ViewBag.Errores = result.Errors.Select(d => d.Description).ToList(); return(View(userInfo)); } return(View(userInfo)); }
protected void btnIngresar_Click(object sender, EventArgs e) { try { Usuario u = contexto.Usuario.Find(txtRut.Text); if (u != null) { if (u.Rol == "Administrador") { Administrador a = contexto.Administrador.Find(txtRut.Text); if (u.Clave == txtClave.Text) { Session["Rut"] = a.RutA; Session["Nombre"] = a.Nombre; Session["Rol"] = "Administrador"; Session.Timeout = 20; // tiempo en minutos Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Redirect(@"~/Vistas/PrincipalAdmin.aspx"); } } else if (u.Rol == "Bodeguero") { Bodeguero b = contexto.Bodeguero.Find(txtRut.Text); if (u.Clave == txtClave.Text) { Session["Rut"] = b.RutB; Session["Nombre"] = b.Nombre; Session["Rol"] = "Bodeguero"; Session.Timeout = 20; // tiempo en minutos Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Redirect(@"~/Vistas/PrincipalBodeguero.aspx"); } } else if (u.Rol == "Vendedor") { Vendedor v = contexto.Vendedor.Find(txtRut.Text); if (u.Clave == txtClave.Text) { Session["Rut"] = v.RutV; Session["Nombre"] = v.Nombre; Session["Rol"] = "Vendedor"; Session.Timeout = 20; // tiempo en minutos Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Redirect(@"~/Vistas/PrincipalVendedor.aspx"); } } } else { Panel_error.CssClass = "alert alert-danger"; } } catch (Exception) { Panel_error.CssClass = "alert alert-danger"; } }
public async Task <IActionResult> Login(LoginViewModel userInfo) { if (ModelState.IsValid) { Bodeguero signedUser = await _userManager.FindByNameAsync(userInfo.RUC); if (signedUser != null) { var result = await _signInManager.PasswordSignInAsync(userInfo.RUC, userInfo.Password, isPersistent : false, lockoutOnFailure : false); if (!result.Succeeded) { ViewBag.Error = "Credenciales incorrectas"; return(View(userInfo)); } return(RedirectToAction("Index", "Home")); } ViewBag.Error = "Numero de RUC no encontrado"; return(View(userInfo)); } return(View(userInfo)); }