コード例 #1
0
        public ActionResult Giris(string username, string password, User user)
        {
            LoginValidation  loginValidation = new LoginValidation();
            ValidationResult result          = loginValidation.Validate(user);

            if (result.IsValid == false)
            {
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                }
                return(View(user));
            }
            else
            {
                var loginuser = _userService.CheckUser(username, password);
                if (loginuser != null)
                {
                    AuthenticationHelper.CreateAuthCookie(loginuser.UserId, loginuser.Username, loginuser.Email, DateTime.Now.AddDays(15), _userService.GetUserRole(username).Select(x => x.RoleName).ToArray(), false, loginuser.FirstName, loginuser.LastName);
                    return(RedirectToAction("Index", "AnaSayfa"));
                }
                ViewBag.LoginError = "Kullanıcı adı veya şifre yanlış!";
                return(View());
            }
        }
コード例 #2
0
        public bool CanExecute(object parameter)
        {
            if (parameter != null)
            {
                var param = parameter as LoginModel;
                param.Errors = string.Join(" ", Validations.Validate(param).Errors);

                if (Validations.Validate(param).IsValid)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }
コード例 #3
0
        public async Task <ActionResult <dynamic> > Authenticate([FromBody] UserRequest model)
        {
            LoginValidation  validator = new LoginValidation(model, _userBusiness);
            ValidationResult result    = validator.Validate(model);

            if (!result.IsValid)
            {
                return(BadRequest(result.Errors[0].ErrorMessage));
            }

            var user = _userBusiness.Validate(model.Username, model.Password);

            return(Ok(new Login(user)));
        }
コード例 #4
0
        public IActionResult Logar([FromBody] LoginDTO loginDTO)
        {
            LoginValidation  validation       = new LoginValidation();
            ValidationResult validationResult = validation.Validate(loginDTO);

            if (!validationResult.IsValid)
            {
                return(ResponseValidationResult(validationResult));
            }

            try
            {
                var usuario = _usuarioService.Logar(loginDTO.Email, loginDTO.Senha);

                if (usuario != null)
                {
                    var data = new
                    {
                        result = new
                        {
                            nome  = usuario.Nome,
                            email = usuario.Email,
                        }
                    };

                    return(Ok(new { success = true, data = data }));
                }
                else
                {
                    var data = new
                    {
                        result = new
                        {
                            mensagem = "Usuário não encontrado!"
                        }
                    };

                    return(NotFound(new { success = true, data = data }));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new { success = false, errors = new KeyValuePair <string, string>("BadRequest", $"Erro ao executar o método Logar: {ex.Message}") }));
            }
        }
コード例 #5
0
        public IActionResult Create([Bind] Login user)
        {
            LoginValidation validator = new LoginValidation();

            ValidationResult result = validator.Validate(user);

            if (!result.IsValid)

            {
                foreach (ValidationFailure failer in result.Errors)

                {
                    ModelState.AddModelError(failer.PropertyName, failer.ErrorMessage);
                }
            }

            else
            {
                //Acciones que queramos ejecutar (crear el usuario)
            }

            return(View(user));
        }
コード例 #6
0
 public bool ValidateForm()
 {
     return(LoginValidation.Validate());
 }