Ejemplo n.º 1
0
 public ActionResult Login(string username, string password, int isPersistent = 0)
 {
     using (BasicDB db = new BasicDB(false))
     {
         if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
         {
             ViewBag.Error = "The username and password can not be empty";
         }
         else
         {
             MldAdmin model = adminDal.Query("name=@1 and pwd=@2", username, Common.Encryption.GetAdminPwd(password));
             if (model != null)
             {
                 if (model.IsLock == 1)
                 {
                     ViewBag.Error = "Sorry, your account has been locked up";
                 }
                 else
                 {
                     WebSiteHelper.Login(model.Name, ((EnumAdminRole)model.Rid).ToString(), Convert.ToBoolean(isPersistent));
                     model.LastLoginTime = DateTime.Now;
                     model.LastLoginIP   = HttpHelper.Context.Request.UserHostAddress;
                     adminDal.Update(model);
                     return(Redirect("/WebAdmin/Home/Welcome"));
                 }
             }
             else
             {
                 ViewBag.Error = "The username or password is incorrect, please reenter it";
             }
         }
     }
     return(View());
 }
Ejemplo n.º 2
0
        public ActionResult Index(string name, string pwd)
        {
            ViewBag.Error = "none";
            using (BasicDB db = new BasicDB(false))
            {
                if (string.IsNullOrEmpty(name))
                {
                    ViewBag.Error = "Account is not null";
                }
                else
                {
                    if (string.IsNullOrEmpty(pwd))
                    {
                        ViewBag.Error = "Pwd is not null";
                    }
                    else
                    {
                        if (adminDal.Exists("name=@1", name))
                        {
                            ViewBag.Error = "The account has already existed";
                        }
                        else
                        {
                            MldAdmin model = new MldAdmin()
                            {
                                Rid = (int)EnumAdminRole.Normal, Name = name, Pwd = Common.Encryption.GetAdminPwd(pwd), AddTime = DateTime.Now, IsLock = 0
                            };

                            if (adminDal.Add(model) > 0)
                            {
                                ViewBag.Success = "ok";
                            }
                            else
                            {
                                ViewBag.Error = "Error";
                            }
                        }
                    }
                }
            }
            return(View());
        }
Ejemplo n.º 3
0
        public ActionResult Edit(int id, string name, string pwd, int islock)
        {
            ViewBag.Error = "none";
            using (BasicDB db = new BasicDB(false))
            {
                if (adminDal.Exists("name=@1 and id!=@2", name, id))
                {
                    ViewBag.Error = "The account has already existed";
                }
                else
                {
                    if (string.IsNullOrEmpty(name))
                    {
                        ViewBag.Error = "Account is not null";
                    }
                    else
                    {
                        MldAdmin model = new MldAdmin();
                        model.ID   = id;
                        model.Name = name;

                        model.IsLock = islock;
                        if (!string.IsNullOrEmpty(pwd))
                        {
                            model.Pwd = Common.Encryption.GetAdminPwd(pwd);
                        }
                        if (adminDal.Update(model))
                        {
                            ViewBag.Success = "ok";
                        }
                        else
                        {
                            ViewBag.Error = "Error";
                        }
                    }
                }
                return(View("Edit", adminDal.Query(id)));
            }
        }