예제 #1
0
 public JsonResult Login(string user_id, string password)
 {
     Models.AdminAccount user = AdminAccountService.GetbyUserId(user_id);
     if (user == null)
     {
         return(Json(
                    new
         {
             statusCode = 0,
             msg = "用户未注册!",
         }
                    , JsonRequestBehavior.AllowGet));
     }
     if (user.User_password.Equals(MD5.Get(password).ToLower()) ||
         user.User_password == password)
     {
         //CreateSession(user);
         return(Json(new { statusCode = 200, msg = "登录成功!" }, JsonRequestBehavior.AllowGet));
     }
     return(Json(
                new
     {
         statusCode = -1,
         msg = "未知错误!",
     }
                , JsonRequestBehavior.AllowGet));
 }
예제 #2
0
        public ActionResult ChangeStatus(int id)
        {
            var result = AdminAccountService.ChangeStatus(id);

            SetFlashMessage(result == Result.Ok
                ? "Thay đổi trạng thái tài khoản thành công."
                : "Không tìm thấy tài khoản cần thay đổi trạng thái.");
            return(RedirectToAction("Index"));
        }
예제 #3
0
        public ActionResult OnDelete(int id)
        {
            var result = AdminAccountService.Delete(id);

            SetFlashMessage(result == Result.Ok ?
                            "Xóa tài khoản thành công." :
                            "Tài khoản không tồn tại trên hệ thống.");
            return(RedirectToAction("Index"));
        }
예제 #4
0
        public ActionResult Login(Models.AdminAccount adminAccount, string ReturnUrl, string code)
        {
            if (string.IsNullOrEmpty(code) || Session["code"] == null)
            {
                TempData["loginerr"]    = "err";
                TempData["loginerrmsg"] = "验证码已失效";
                return(RedirectToAction("Index", "Login", ViewBag));
            }
            else
            {
                if (code.ToLower() != Session["code"].ToString().ToLower())
                {
                    TempData["loginerr"]    = "err";
                    TempData["loginerrmsg"] = "验证码错误";
                    return(RedirectToAction("Index", "Login", ViewBag));
                }
            }

            Models.AdminAccount user = AdminAccountService.GetbyUserId(adminAccount.User_id);
            if (user == null)
            {
                //登陆失败;
                //ViewBag.err = "err";
                //ViewBag.errmsg = "账号未注册!";
                TempData["loginerr"]    = "err";
                TempData["loginerrmsg"] = "账号未注册";
                return(RedirectToAction("Index", "Login", ViewBag));
            }
            else
            {
                //判断密码;
                if (user.User_password != adminAccount.User_password)
                {
                    //登陆失败
                    TempData["loginerr"]    = "err";
                    TempData["loginerrmsg"] = "密码错误";
                    return(RedirectToAction("Index", "Login", ViewBag));
                }
                else
                {
                    //登陆成功;
                    CreateSession(user);
                    var ggg = Request.UrlReferrer.OriginalString;
                    Session["RegionCode"] = null;
                    //跳转
                    if (string.IsNullOrEmpty(ReturnUrl))
                    {
                        return(RedirectToAction("Index", "Home"));//如果登录成功跳转的页面。
                    }
                    else
                    {
                        return(Redirect(ReturnUrl));
                    }
                }
            }
        }
예제 #5
0
        public ActionResult OnCreate(AdminModels model)
        {
            if (ModelState.IsValid)
            {
                if (string.IsNullOrWhiteSpace(model.Password))
                {
                    ModelState.AddModelError("Password", "Vui lòng nhập Mật khẩu tài khoản.");
                    ViewBag.ListRole        = RoleService.GetAll();
                    ViewBag.ListAccountType = DataHelper.ListEnumType <AccountType>();
                    return(View("Create", model));
                }
                if (model.ConfirmPassword != model.Password)
                {
                    ModelState.AddModelError("ConfirmPassword", "Mật khẩu xác nhận không đúng.");
                    ViewBag.ListRole        = RoleService.GetAll();
                    ViewBag.ListAccountType = DataHelper.ListEnumType <AccountType>();
                    return(View("Create", model));
                }
                model.AvatarUrl = model.AvatarFile != null?
                                  model.AvatarFile.Upload() :
                                      model.AvatarUrl;

                var result = AdminAccountService.Insert(new Data.Admin
                {
                    UserName = model.UserName,
                    Password = model.Password,
                    Avatar   = model.AvatarUrl,
                    Email    = model.Email,
                    FullName = model.FullName,
                    Role     = model.Role,
                    Date     = model.Date,
                    Status   = model.Status,
                    Type     = model.Type,
                });
                if (result == Result.Exists)
                {
                    ModelState.AddModelError("", $"Tài khoản '{model.UserName}' đã tồn tại trên hệ thống.");
                    ViewBag.ListRole        = RoleService.GetAll();
                    ViewBag.ListAccountType = DataHelper.ListEnumType <AccountType>();
                    return(View("Create", model));
                }
                SetFlashMessage($"Thêm tài khoản '{model.UserName}' thành công.");
                if (model.SaveList)
                {
                    return(RedirectToAction("Index"));
                }
                ViewBag.ListRole        = RoleService.GetAll();
                ViewBag.ListAccountType = DataHelper.ListEnumType <AccountType>();
                return(View("Create", model.ResetValue()));
            }
            ViewBag.ListRole        = RoleService.GetAll();
            ViewBag.ListAccountType = DataHelper.ListEnumType <AccountType>();
            return(View("Create", model));
        }
예제 #6
0
 /// <summary>
 /// 修改密码
 /// </summary>
 /// <returns></returns>
 public JsonResult ChangePwd(string userid, string password)
 {
     Models.AdminAccount user = AdminAccountService.UpdatePwd(userid, MD5.Get(password).ToLower());
     if (user.Id > 0)
     {
         return(Json(new
         {
             statusCode = 200,
         }, JsonRequestBehavior.AllowGet));
     }
     return(Json(new
     {
         statusCode = 0,
     }, JsonRequestBehavior.AllowGet));
 }
예제 #7
0
        public ActionResult ChangePassword(int id)
        {
            var adminAccountPassword = AdminAccountService.Find(id);

            if (adminAccountPassword == null)
            {
                return(RedirectToAction("Index"));
            }
            var adminChangePasswordModels = new AdminChangePassworModels
            {
                Id       = adminAccountPassword.ID,
                UserName = adminAccountPassword.UserName
            };

            return(View("ChangePassword", adminChangePasswordModels));
        }
예제 #8
0
        public ActionResult OnChangePassword(AdminChangePassworModels admin)
        {
            if (ModelState.IsValid)
            {
                var result = AdminAccountService.ChangePassword(admin.Id, admin.NewPassword);
                if (result == Result.NotExists)
                {
                    ModelState.AddModelError("", "Khách hàng không tồn tại trên hệ thống.");
                    return(View("ChangePassword", admin));
                }

                SetFlashMessage("Thay đổi mật khẩu thành công.");
                if (admin.SaveList)
                {
                    return(RedirectToAction("Index"));
                }
                return(View("ChangePassword", admin));
            }
            return(View("ChangePassword", admin));
        }
예제 #9
0
        public ActionResult OnEdit(AdminModels model)
        {
            if (ModelState.IsValid)
            {
                model.AvatarUrl = model.AvatarFile != null?
                                  model.AvatarFile.Upload() :
                                      model.AvatarUrl.ToImageOriginalPath();

                var result = AdminAccountService.Update(new Data.Admin
                {
                    ID       = model.Id,
                    UserName = model.UserName,
                    Password = model.Password,
                    Avatar   = model.AvatarUrl,
                    Email    = model.Email,
                    FullName = model.FullName,
                    Role     = model.Role,
                    Date     = model.Date,
                    Status   = model.Status,
                    Type     = model.Type,
                });
                if (result == Result.NotExists)
                {
                    ModelState.AddModelError("", "Tài khoản không tồn tại trên hệ thống.");
                    ViewBag.ListRole        = RoleService.GetAll();
                    ViewBag.ListAccountType = DataHelper.ListEnumType <AccountType>();
                    return(View("Edit", model));
                }
                SetFlashMessage($"Sửa tài khoản '{model.FullName}' thành công.");
                if (model.SaveList)
                {
                    return(RedirectToAction("Index"));
                }
                ViewBag.ListRole        = RoleService.GetAll();
                ViewBag.ListAccountType = DataHelper.ListEnumType <AccountType>();
                return(View("Edit", model));
            }
            ViewBag.ListRole        = RoleService.GetAll();
            ViewBag.ListAccountType = DataHelper.ListEnumType <AccountType>();
            return(View("Edit", model));
        }
예제 #10
0
        public ActionResult OnLogin(LoginModels login)
        {
            if (ModelState.IsValid)
            {
                var result = AdminAccountService.CheckAccount(login.Username, login.Password);

                if (result == null)
                {
                    ModelState.AddModelError("", "Sai tên tài khoản hoặc mật khẩu.");
                    return(View("Login", login));
                }
                var myUser = new MyUser
                {
                    UserName = login.Username,
                    UserId   = result.ID,
                    RoleId   = result.Role ?? 0
                };
                AuthenticationHelper.SignIn(myUser, login.Remember);
                return(RedirectToAction("Index"));
            }
            return(View("Login", login));
        }
예제 #11
0
        public ActionResult Edit(int id)
        {
            var adminEdit = AdminAccountService.Find(id);

            if (adminEdit == null)
            {
                return(Redirect("Index"));
            }
            var model = new AdminModels
            {
                Id        = adminEdit.ID,
                UserName  = adminEdit.UserName,
                Email     = adminEdit.Email,
                FullName  = adminEdit.FullName,
                Role      = adminEdit.Role ?? 0,
                Status    = adminEdit.Status ?? false,
                Type      = adminEdit.Type ?? 0,
                AvatarUrl = adminEdit.Avatar
            };

            ViewBag.ListRole        = RoleService.GetAll();
            ViewBag.ListAccountType = DataHelper.ListEnumType <AccountType>();
            return(View("Edit", model));
        }
예제 #12
0
 public string OnCheckUserName(string userName)
 {
     return(AdminAccountService.CheckUserName(userName));
 }
예제 #13
0
 public ActionResult Index()
 {
     return(View("Index", AdminAccountService.GetAll()));
 }