Example #1
0
        public ActionResult Login(LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult
                {
                    Status = "error",
                    ErrorMsg = MVCHelper.GetValidMesg(ModelState)
                }));
            }

            if (model.VerifyCode != (string)TempData["verifyCode"])
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "验证码错误"
                }));
            }

            bool result = AdminUserService.CheckLogin(model.PhoneNum, model.Password);

            if (result)
            {
                //将userId存放到session中
                Session["LoginUserId"] = AdminUserService.GetByPhoneNum(model.PhoneNum).Id;
                return(Json(new AjaxResult {
                    Status = "ok"
                }));
            }
            else
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "用户名或者密码错误"
                }));
            }
        }
Example #2
0
        public ActionResult Add(AdminUserAddNewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = MVCHelper.GetValidMesg(ModelState)
                }));
            }

            var user = AdminUserService.GetByPhoneNum(model.PhoneNum);

            if (user != null)
            {
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = "该手机号已被注册"
                }));
            }
            //发现在service里面也判断了一次手机是否注册,感觉越早判断越好,service那个就没必要了
            //TODO:这里应该用事务
            long adminUserId = AdminUserService.AddAdminUser(model.Name, model.PhoneNum, model.PassWord, model.Email, model.CityId);

            RoleService.AddRoleIds(adminUserId, model.RoleIds);

            return(Json(new AjaxResult()
            {
                Status = "ok"
            }));
        }
 public ActionResult CheckLoginPhoneNum(string phoneNum)
 {
     try
     {
         var data = AdminUserService.GetByPhoneNum(phoneNum);
         if (data != null)
         {
             return(Json(new AjaxResult <object>
             {
                 code = 1,
                 msg = "此手机号已存在!"
             }));
         }
         return(Json(new AjaxResult <object>
         {
             code = 0
         }));
     }
     catch (Exception ex)
     {
         return(Json(new AjaxResult <object>
         {
             code = 1,
             msg = ex.Message
         }));
     }
 }
Example #4
0
        public ActionResult Edit(AdminUserEditModel model)
        {
            //修改的时候密码为空表示不修改,这样的话属性验证过不了,直接去掉这个了
            //if (!ModelState.IsValid)
            //{
            //    return Json(new AjaxResult() { Status = "error", ErrorMsg = MVCHelper.GetValidMesg(ModelState) });
            //}

            var user = AdminUserService.GetByPhoneNum(model.PhoneNum);

            if (user == null)
            {
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = "该手机号不存在"
                }));
            }
            //TODO:这里应该用事务
            AdminUserService.UpdateAdminUser(user.Id, model.Name, model.PhoneNum, model.PassWord, model.Email, model.CityId);
            RoleService.UpdateRoleIds(user.Id, model.RoleIds);

            return(Json(new AjaxResult()
            {
                Status = "ok"
            }));
        }
Example #5
0
        public void TestAddAdminUser()
        {
            AdminUserService auService = new AdminUserService();
            long             id        = auService.AddAdminUser("wuhuajie", "12312312312", "123456", "*****@*****.**", null);

            try
            {
                AdminUserDTO userDto = auService.GetById(id);
                Assert.AreEqual(id, userDto.Id);
                Assert.AreEqual("wuhuajie", userDto.Name);
                Assert.AreEqual("12312312312", userDto.PhoneNum);
                Assert.AreEqual(CommonHelper.CalcMD5(userDto.PasswordSalt + "123456"), userDto.PasswordHash);
                Assert.AreEqual("*****@*****.**", userDto.EMail);

                AdminUserDTO[] userDtos = auService.GetAll();
                //AminUserDTO[] userDtos2 = auService.GetAll();
                Assert.IsNotNull(userDtos);
                AdminUserDTO userDto2 = auService.GetByPhoneNum("12312312312");
                Assert.IsNotNull(userDto2);
                AdminUserDTO userDto3 = auService.GetByPhoneNum("1231231221312");
                Assert.IsNull(userDto3);
                bool login = auService.CheckLogin("12312312312", "123456");
                Assert.IsTrue(login);
                bool login2 = auService.CheckLogin("123412312312", "123456");
                Assert.IsFalse(login2);
                bool login3 = auService.CheckLogin("12312312312", "3422");
                Assert.IsFalse(login3);
                bool login4 = auService.CheckLogin("3242323423", "3422");
                Assert.IsFalse(login4);

                auService.MarkDeleted(id);
            }
            catch (Exception ex)
            {
                auService.MarkDeleted(id);
                throw ex;
            }
        }
Example #6
0
        public void TestAddAdminUser()
        {
            long uid =
                userService.AddAdminUser("abc", "189181", "123", "*****@*****.**", null);
            var user = userService.GetById(uid);

            Assert.AreEqual(user.Name, "abc");
            Assert.AreEqual(user.PhoneNum, "189181");
            Assert.AreEqual(user.Email, "*****@*****.**");
            Assert.IsNull(user.CityId);
            Assert.IsTrue(userService.CheckLogin("189181", "123"));
            Assert.IsFalse(userService.CheckLogin("189181", "abc"));
            userService.GetAll();
            Assert.IsNotNull(userService.GetByPhoneNum("189181"));
            userService.MarkDeleted(uid);//为了保证TestCase可以重复执行,那么把创建的数据干掉
        }
Example #7
0
 public void TestAdminUser()
 {
     long id = userService.AddAdminUser("abc", "13132131131", "123456", "*****@*****.**", null);
     var user= userService.GetById(id);
     Assert.AreEqual(user.Name, "abc");
     Assert.AreEqual(user.PhoneNum, "13132131131");
     Assert.AreEqual(user.Email, "*****@*****.**");
     Assert.IsNull(user.CityId);
     Assert.IsTrue(userService.CheckLogin("13132131131", "123456"));
     Assert.IsFalse(userService.CheckLogin("13132131131", "324"));
     userService.GetAll();
     Assert.IsNull(userService.GetByPhoneNum("2325252"));
     userService.GetAll(1);
     userService.UpdateAdminUser(id, "bbc", "*****@*****.**", null);
     userService.MarkDeleted(id);
 }
Example #8
0
        public void AddAdminUserTest()
        {
            AdminUserService adminService = new AdminUserService();

            long id   = new AdminUserService().AddAdminUser("cyq", "189", "mima", "123", null);
            var  user = adminService.GetById(id);

            Assert.AreEqual("cyq", user.Name);
            Assert.AreEqual("189", user.PhoneNum);
            Assert.AreEqual("123", user.Email);
            Assert.IsTrue(adminService.CheckLogin("189", "mima"));
            Assert.IsFalse(adminService.CheckLogin("189", "mima1"));
            adminService.GetAll();
            Assert.IsNotNull(adminService.GetByPhoneNum("189"));
            adminService.MarkDeleted(id);
        }
Example #9
0
        public void TestAddAdminUser()
        {
            string phoneNum = Guid.NewGuid().ToString().Substring(0, 11);
            long   uId      = adminUserService.AddAdminUser("张三", phoneNum, "123456", "*****@*****.**", null);
            var    user     = adminUserService.GetById(uId);

            Assert.AreEqual(user.Name, "张三");
            Assert.AreEqual(user.PhoneNum, phoneNum);
            Assert.AreEqual(user.Email, "*****@*****.**");
            Assert.IsNull(user.CityId);
            Assert.IsTrue(adminUserService.CheckLogin(phoneNum, "123456"));
            Assert.IsFalse(adminUserService.CheckLogin(phoneNum, "123"));
            adminUserService.GetAll();
            Assert.IsNotNull(adminUserService.GetByPhoneNum(phoneNum));
            adminUserService.MarkDeleted(uId);
        }
 public ActionResult AddAdminUser(AdminUserAddModel model)
 {
     if (!ModelState.IsValid)
     {
         return(Json(new AjaxResult <object>
         {
             code = 1,
             msg = CommonHelper.GetValidMsg(ModelState)
         }));
     }
     if (AdminUserService.GetByPhoneNum(model.PhoneNum) != null)
     {
         return(Json(new AjaxResult <object>
         {
             code = 1,
             msg = "手机号已存在"
         }));
     }
     try
     {
         using (TransactionScope sc = new TransactionScope())
         {
             long?cityid = null;
             if (model.City != 0)
             {
                 cityid = model.City;
             }
             var id = AdminUserService.AddAdminUser(model.Name, model.PhoneNum, model.Password, model.Email, cityid);
             AdminUserService.AddAdminUserRole(id, model.Roles);
             sc.Complete();
         }
         return(Json(new AjaxResult <object>
         {
             code = 0,
             msg = "添加成功"
         }));
     }
     catch (Exception ex)
     {
         Log.ErrorFormat("添加管理员用户失败:{0}", ex.Message);
         return(Json(new AjaxResult <object>
         {
             code = 1,
             msg = ex.Message
         }));
     }
 }
Example #11
0
        public void TestAddAdminUser()
        {
            long userId   = service.AddAdminUser("hhz", "13680398478", "123", "*****@*****.**", null);
            var  userInfo = service.GetById(userId);

            Assert.AreEqual(userInfo.Name, "hhz");
            Assert.AreEqual(userInfo.PhoneNum, "13680398478");
            Assert.AreEqual(userInfo.Email, "*****@*****.**");
            Assert.IsNull(userInfo.CityId);
            Assert.IsTrue(service.CheckLogin("13680398478", "123"));
            Assert.IsFalse(service.CheckLogin("13680398478", "1242"));

            service.GetAll();
            Assert.IsNotNull(service.GetByPhoneNum("13680398478"));

            service.MarkDeleted(userId);
        }
Example #12
0
        public ActionResult CheckPhoneNum(string phoneNum, long?userId)
        {
            bool isOk = false;
            var  user = AdminUserService.GetByPhoneNum(phoneNum);

            if (userId == null)
            {
                isOk = (user == null);
            }
            else
            {
                isOk = (user == null || user.Id == userId);
            }
            return(Json(new AjaxResult {
                Status = isOk ? "ok" : "exists"
            }));
        }
Example #13
0
        public JsonResult CheckPhoneNum(string phoneNum, long?userId)
        {
            var  user     = AdminUserService.GetByPhoneNum(phoneNum);
            bool isExists = false;

            if (userId == null)
            {
                isExists = !(user == null);
            }
            else
            {
                isExists = user != null && user.Id != userId;
            }
            return(Json(new AjaxResult {
                Status = isExists ? "exists" : "noExists"
            }));
        }
Example #14
0
        /// <summary>
        /// 检查手机号是否已存在
        /// </summary>
        /// <param name="phoneNum"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public ActionResult CheckPhoneNum(string phoneNum, long?userId)
        {
            var  user = AdminUserService.GetByPhoneNum(phoneNum);
            bool isOK = false;

            //如果没有给userId,则说明是“插入”,只要检查是不是存在这个手机号
            if (userId == null)
            {
                isOK = (user == null);
            }
            else//如果有userId,则说明是修改,则要把自己排除在外
            {
                isOK = (user == null || user.Id == userId);
            }

            return(Json(new AjaxResult()
            {
                Status = isOK ? "ok" : "exists"
            }));
        }
Example #15
0
        public ActionResult Login(LoginViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult <object>
                {
                    code = 1,
                    msg = CommonHelper.GetValidMsg(ModelState)
                }));
            }
            if ((string)TempData["code"] != model.Captcha)
            {
                return(Json(new AjaxResult <object>
                {
                    code = 1,
                    msg = "验证码错误"
                }));
            }
            bool result = AdminUserService.CheckLogin(model.PhoneNum, model.Password);

            if (result)
            {
                Session["AdminUserId"] = AdminUserService.GetByPhoneNum(model.PhoneNum).Id;
                return(Json(new AjaxResult <object>
                {
                    code = 0,
                    msg = "登陆成功"
                }));
            }
            else
            {
                return(Json(new AjaxResult <object>
                {
                    code = 1,
                    msg = "用户名或密码错误"
                }));
            }
        }
Example #16
0
        public ActionResult Create(AdminUserCreateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = MVCHelper.GetValidMsg(ModelState)
                }));
            }
            bool exists = AdminUserService.GetByPhoneNum(model.PhoneNum) != null;

            if (exists)
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "手机号已经存在"
                }));
            }
            long adminUserId = AdminUserService.AddAdminUser(model.Name, model.PhoneNum, model.Password, model.Email, model.CityId == 0 ? null : model.CityId);

            RoleService.AddRoleIds(adminUserId, model.roleIds);
            return(Json(new AjaxResult {
                Status = "ok"
            }));
        }