Esempio n. 1
0
        public ActionResult LoginAccess(string username, string password)
        {
            if (string.IsNullOrEmpty(password) || string.IsNullOrEmpty(username))
            {
                ViewBag.ValidateInfo = "用户名或密码不能为空请重新登录";
                return(View("Login"));//new RedirectResult("/Admin/Account/Login");
            }
            UserBC     bc     = new UserBC();
            var        result = bc.GetUsers(username, password);
            UserEntity entity = new UserEntity();

            if (result != null && result.Count > 0)
            {
                entity = result.FirstOrDefault();
            }
            else
            {
                ViewBag.ValidateInfo = "用户名或密码错误请重新登录";
                ////用户名密码错误请重新登录
            }

            if (entity != null && !string.IsNullOrEmpty(entity.User_Id))
            {
                var currentSession = new UserAuthSession
                {
                    Id         = entity.User_Id,
                    Account    = entity.Login_Name,
                    Name       = entity.User_Name,
                    Token      = Guid.NewGuid().ToString().GetHashCode().ToString("x"),
                    CreateTime = DateTime.Now,
                    IpAddress  = HttpContext.Request.UserHostAddress,
                };


                CacheManager.Instance.CurrentUser = currentSession;
                //创建Session
                new ObjCacheProvider <UserAuthSession>().Create(currentSession.Token, currentSession, DateTime.Now.AddHours(1));
                var cookie = new HttpCookie("Token", currentSession.Token)
                {
                    Expires = DateTime.Now.AddHours(1)
                };
                HttpContext.Response.Cookies.Add(cookie);
                return(new RedirectResult("/Admin/Account/Index"));
            }
            else
            {
                ViewBag.ValidateInfo = "用户名或密码错误请重新登录";
                ////用户名密码错误请重新登录
            }

            // return new RedirectResult("/Admin/Account/Login");
            return(View("Login"));
        }
Esempio n. 2
0
 private void initializeUsers()
 {
     //metodo linq
     users = userBC.GetUsers().Select(x => new UserViewModel
     {
         Id                 = x.IdUser,
         Apellido           = x.LastName,
         Nombre             = x.Name,
         Correo_electronico = x.Email,
         DNI                = x.DNI,
         Estado             = (x.Status == "A") ? "Activo" : "Desactivado", //(x.Status == "A") ? "Activo" : (x.Status == "E") ? "Eliminado" : "Desactivado"
         Genero             = (x.Gener == "M") ? "Masculino" : "Femenino",  // obtenergenero(x.gener) => String
         Fecha_Nacimiento   = x.Birthday.Value.ToShortDateString(),
         Nombre_Usuario     = x.username,
         Telefono           = x.PhoneNumber
     }).OrderBy(x => x.Apellido).ToList();// el OrderBy ordena de manera Ascendente y el OrderByDescending va de manera descendente
 }