public Admins Login(Admins user)
 {
     user = new AdminLoginService().Login(user);
     if (user != null)
     {
         HttpContext.Current.Session["CurrentUser"] = user;
     }
     return(user);
 }
        public void DoLogin_With_Right_Credentials(string username, string password)
        {
            //DaoFactory.Register<IAdminLoginDao>(typeof(FakeAdminLoginDao));  also works
            var             adminLoginService = new AdminLoginService(new FakeAdminLoginDao());
            IAdminLoginData loginData         = new AdminLoginData {
                Username = username, Password = password
            };

            var loginInfo = adminLoginService.DoLogin(loginData);

            Assert.AreEqual(0, loginInfo.ErrorMessages.Count);
            Assert.AreEqual(StatusCode.Success, loginInfo.StatusCode);
            Assert.AreEqual(username, loginInfo.Administrator.Username);
        }
        [TestCase("Cindy", "Eke")]      //test property validators seperately
        public void DoLogin_With_Wrong_Credentials(string username, string password)
        {
            DaoFactory.Register <IAdminLoginDao>(typeof(FakeAdminLoginDao));
            var             adminLoginService = new AdminLoginService();
            IAdminLoginData loginData         = new AdminLoginData {
                Username = username, Password = password
            };

            var loginInfo = adminLoginService.DoLogin(loginData);

            Assert.GreaterOrEqual(loginInfo.ErrorMessages.Count, 1);
            Assert.AreEqual(StatusCode.Failure, loginInfo.StatusCode);
            Assert.AreEqual(null, loginInfo.Administrator);
        }
Exemple #4
0
        public ICollection <Author> SearchAuthorByRoleid(int userid)
        {
            string statuscode = string.Empty;
            User   user       = new Entity.User()
            {
                UserId = userid
            };

            User getuser = new AdminLoginService().AdminLogin(user);

            int?roleid = getuser.RoleId;


            ICollection <Author> authorlist = new RoleService().GetAllAuthor(roleid);//获取这个学员所有的权限

            return(authorlist);
        }
Exemple #5
0
        public ActionResult Login(LoginModel model)
        {
            //1:必须有非空的一个校验
            if (!ModelState.IsValid)
            {
                //说明校验没通过,提示用户XXX为空
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = CommonHelper.GetValidMsg(ModelState)
                }));
            }
            //2:校验用户输入的验证码跟model里面的是否一致
            if (TempData["code"].ToString() != model.VerCode)
            {
                return(Json(new AjaxResult()
                {
                    Status = "error", ErrorMsg = "验证码不对"
                }));
            }
            //3:根据用户名和密码做数据库的校验
            bool b = AdminLoginService.CheckLogin(model.Name, model.Pwd);

            if (b)
            {
                Session["LoginID"] = AdminUserService.GetAdminByPhone(model.Name).Id;
                return(Json(new AjaxResult()
                {
                    Status = "ok"
                }));
            }
            else
            {
                return(Json(new AjaxResult()
                {
                    Status = "no"
                }));
            }
        }
        public ActionResult AdminLogin(string loginphonenum, string loginpwd)
        {
            JsonResultData <string> resultdata = new JsonResultData <string>();

            string statuscode = string.Empty;
            User   user       = new Entity.User()
            {
                UserPhoneNumber = loginphonenum,
                UserPwd         = loginpwd,
            };

            try
            {
                User getuser = new AdminLoginService().AdminLogin(user, out statuscode);

                if (getuser == null)
                {
                    resultdata.Code = 0;
                    resultdata.Data = statuscode;
                }
                else
                {
                    if (statuscode == "账户被禁用")
                    {
                        resultdata.Code = 0;
                        resultdata.Data = statuscode;
                    }
                    else if (statuscode == "用户名或密码错误")
                    {
                        resultdata.Code = 0;
                        resultdata.Data = statuscode;
                    }
                    else if (statuscode == "登录成功")
                    {
                        //如果登录成功//把信息保存到session中
                        // Response.Cookies["currentuserinfo"].Value = getuser;

                        //在获取此学员拥有的权限

                        int?roleid = getuser.RoleId;

                        ICollection <Author> authorlist = new RoleService().GetAllAuthor(roleid);//获取这个学员所有的权限

                        // List<AuthorUIModel> list = authorlist;


                        // ViewBag.authorlist = list;

                        //判断此人的角色
                        //   int roleid = (int)getuser.RoleId;
                        Role   role   = new AdminLoginService().GetRole(roleid);
                        Author author = null;

                        if (role != null)
                        {
                            if (role.RoleName == "学员")
                            {
                                author = authorlist.FirstOrDefault(x => x.ActionName == "Index" && x.ControllerName == "ProjectList");
                                resultdata.IsStuent = 0;
                            }

                            else//不是学生的
                            {
                                author = authorlist.FirstOrDefault(x => x.ActionName == "Index" && x.ControllerName == "Home");
                                resultdata.IsStuent = 1;
                            }
                            if (author != null)
                            {
                                resultdata.Code = 1;
                                resultdata.Data = statuscode;


                                FormsAuthentication.SetAuthCookie(getuser.UserId.ToString(), true);//创建一个身份凭证

                                //FormsAuthenticationTicket ticks=new FormsAuthenticationTicket(1,getuser.UserId,DateTime.Now,DateTime.Now.AddHours(1.0),true, Newtonsoft)

                                //用户的信息
                                Session["currentuserinfo"] = getuser;
                                ////权限的信息
                                Session["authorlist"] = authorlist;
                            }
                            else
                            {
                                resultdata.Code = 2;
                                resultdata.Data = "您没有权限";
                            }
                        }
                        else
                        {
                            resultdata.Code = 3;
                            resultdata.Data = "您还是未知的角色";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                resultdata.Msg = ex.Message;
            }
            return(Json(resultdata, JsonRequestBehavior.AllowGet));
        }
Exemple #7
0
 public AdminLoginController(AdminService adminService, AdminLoginService adminLoginService)
 {
     _adminService      = adminService;
     _adminLoginService = adminLoginService;
 }