Esempio n. 1
0
        public ActionResult AppLogin(UserLoginModel model)
        //public ActionResult AppLogin(string username,string password)
        {
            if (model.UserName == null || model.Password == null)
            {
                return(Json(new { Code = 301, Msg = "post未获取到参数" }));
            }
            var user = SysUserDAL.GetByOne(q => q.UserName == model.UserName && q.Password == model.Password);

            if (user != null)
            {
                user.Token = TokenProccessor.MakeToken();

                LoginUserModel loginUser = new LoginUserModel {
                    Token       = user.Token,
                    Id          = user.Id,
                    UserName    = user.UserName,
                    RealName    = user.RealName,
                    Email       = user.Email,
                    OpenId      = user.OpenId,
                    QQ          = user.QQ,
                    MobilePhone = user.MobilePhone,
                    UserType    = user.UserType,
                    RoleIds     = new List <int> {
                        1, 2, 3, 4
                    },
                    RoleName     = "系统管理员",
                    FirstDepId   = "1001",
                    FirstDepName = "管理中心",
                    DepName      = "财政部",
                    Name         = "李四"
                };

                ResultData <LoginUserModel> rst = new ResultData <LoginUserModel> {
                    Code   = 200,
                    Msg    = "success",
                    Result = loginUser
                };

                //更新登录用户Token
                SysUserDAL.Update(user);
                LoginUser = loginUser;
                return(Json(rst));
            }
            else
            {
                return(Json(new { Code = 401, Msg = "用户不存在或密码错误" }));
            }
        }
Esempio n. 2
0
        // GET: Login
        public ActionResult Index()
        {
            //List<SelectOption> options = DropDownList.SysRolesSelect();
            //ViewBag.ddlRoles = DropDownList.SetDropDownList(options);
            if (HttpContext.Request.Cookies["username"] != null)
            {
                ViewBag.username = HttpContext.Request.Cookies["username"].Value;
                ViewBag.remberme = "checked";
            }
            ViewBag.LoginState = "";
            LoginModel model = new LoginModel();

            if (Request.Cookies["name"] != null)
            {
                model.userName   = Server.UrlDecode(Request.Cookies["name"].Value);
                model.isRemember = true;
            }
            string token = TokenProccessor.getInstance().makeToken();

            model.token      = token;
            Session["token"] = token;
            //if (Request.Cookies["role"] != null) model.role = PageValidate.FilterParam(Request.Cookies["role"].Value);
            return(View(model));
        }
        // GET: Teacher/Edit/5
        public ActionResult Edit(int?id)
        {
            setSelect();
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToRoute(new { controller = "Login", action = "LogOut" }));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            int userid = PageValidate.FilterParam(User.Identity.Name);

            if (id == null)
            {
                return(View());
            }
            if (!RoleCheck.CheckHasAuthority(userid, db, "用户管理") && id != userid)
            {
                return(RedirectToRoute(new { controller = "Error", action = "Index", err = "没有权限。" }));
            }

            TeacherEditModel model = (from user in db.User_Infos
                                      where user.user_id == id
                                      join u1 in db.User_Infos
                                      on user.user_add_user equals u1.user_id into T1
                                      from t1 in T1.DefaultIfEmpty()
                                      join u2 in db.User_Infos
                                      on user.user_update_user equals u2.user_id into T2
                                      from t2 in T2.DefaultIfEmpty()
                                      join uvr in db.User_vs_Roles on user.user_id equals uvr.uvr_user_id into R
                                      from r in R.DefaultIfEmpty()
                                      select new TeacherEditModel
            {
                user_add_time = user.user_add_time,
                user_add_user = t1.user_name,
                user_email = user.user_email,
                user_home_address = user.user_home_address,
                user_id = user.user_id,
                user_info = user.user_info,
                user_login_times = user.user_login_times,
                user_name = user.user_name,
                user_phone = user.user_phone,
                user_update_time = user.user_update_time,
                user_update_user = t2.user_name,
                user_photo_path = user.user_photo_path,
                role_id = r.uvr_role_id,
                real_name = user.real_name,
                gender = user.user_gender
            }).FirstOrDefault();

            if (model == null)
            {
                return(HttpNotFound());
            }
            string token = TokenProccessor.getInstance().makeToken();

            model.token      = token;
            Session["token"] = token;
            return(View(model));
        }