예제 #1
0
        public ActionResult Index(LoginModel model)
        {
            //if (ModelState.IsValid)
            //{
            var dao    = new LoginDAO();
            var result = dao.CheckLogin(model.UserName, Encryptor.MD5Hash(model.Password));

            if (result == 1)
            {
                var user        = dao.GetUserByUserName(model.UserName);
                var userSession = new LoginModel();
                userSession.UserName   = model.UserName;
                userSession.Password   = model.Password;
                userSession.RememberMe = model.RememberMe;
                //var listCredentials = dao.GetListCredential(model.Email);
                //Session.Add(CMS.Common.CommonConstants.SESSION_CREDENTIALS, listCredentials);
                Session.Add(CommonConstants.USER_SESSION, user);
                Session.Add
                    (CommonConstants.CHECK_LOGIN, userSession);
                return(View("/Admin/Home"));
            }
            else
            {
                ModelState.AddModelError("", "Đăng nhập không thành công");
            }
            //}
            return(View());
        }
예제 #2
0
        public JsonResult DoLogin(User user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    LoginDAO loginDAO = new LoginDAO();
                    user.Password = Utils.Crypt.EncodeSHA1(user.Password);

                    user = loginDAO.CheckLogin(user);
                    if (user != null)
                    {
                        //FormsAuthentication.SetAuthCookie(user.Username, true);

                        Session.Add("usuario", user);

                        return(Json(new { success = true, message = "Login efetuado com sucesso.", redirect = Url.Action("Index", "Home") }, JsonRequestBehavior.AllowGet));
                    }
                }
                return(this.Json(new { success = false, message = "Falha ao efetuar login. Verifique suas credenciais." }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(this.Json(new { success = false, message = "O servidor respondeu com uma exceção. \n\nDetalhes:\n\n" + e.Message }, JsonRequestBehavior.AllowGet));
            }
        }
예제 #3
0
        private void BtnConfirm_Click(object sender, EventArgs e)
        {
            if (LoginDAO.CheckLogin(txtLogin.Text, txtPassword.Text))
            {
                DialogResult = DialogResult.OK;
                Close();
            }
            else
            {
                System.Windows.MessageBox.Show("Usuario ou senha incorreta", "Erro de Login",
                                               MessageBoxButton.OK, MessageBoxImage.Warning);
            }

            // TESTES
            //if (LoginDAO.verificarLogin(txtLogin.Text, txtPassword.Text))
            //{
            //    MessageBox.Show("Logado", "Logado");
            //}
            //else
            //{
            //    MessageBox.Show("Erro: Login Incorreto ou Inexistente", "Falha no Login");
            //}
        }