Beispiel #1
0
        public ContentResult Login(UsuarioRequest req)
        {
            ContentResult response = new ContentResult {
                ContentType = "application/json"
            };

            try
            {
                var result = _service.Login(req);
                response.StatusCode = (int)HttpStatusCode.OK;
                response.Content    = JsonConvert.SerializeObject(result);
                return(response);
            }
            catch (Exception ex)
            {
                response.StatusCode = (int)HttpStatusCode.BadRequest;
                response.Content    = JsonConvert.SerializeObject(ex.Message);
                return(response);
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Index(LoginVMO vmo)
        {
            if (ModelState.IsValid)
            {
                var model = _serviceUsuario.Login(vmo.Nickname, vmo.Password);
                if (model != null)
                {
                    var claims = new List <Claim> {
                        new Claim(ClaimTypes.Name, model.Nombre), new Claim(ClaimTypes.Role, "Administrator")
                    };
                    var claimsIdentity = new ClaimsIdentity(claims, "User");
                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity));

                    return(RedirectToAction("Index", "Home"));
                }

                ViewData["ErrorLogin"] = "******";
            }

            return(View(vmo));
        }
 public Usuario Login(string username, string password)
 {
     return(_serviceUsuario.Login(username, password));
 }
Beispiel #4
0
 public UsuarioDTO Login(LoginUsarioDTO dto)
 {
     return(_mapper.Map <UsuarioDTO>(_serviceUsuario.Login(dto.Username, dto.Password)));
 }