Esempio n. 1
0
        public ActionResult GetCurentUser()
        {
            base.fin_r = base.error_r;
            T_SysUser user = Session["User"] as T_SysUser;

            user.LoginPsw = "********";
            base.fin_r    = base.success_r;
            return(JsonR(user, JsonRequestBehavior.AllowGet));
        }
 /// <summary>
 /// 创建新的 T_SysUser 对象。
 /// </summary>
 /// <param name="id">Id 的初始值。</param>
 /// <param name="userAccount">UserAccount 的初始值。</param>
 /// <param name="pwd">Pwd 的初始值。</param>
 public static T_SysUser CreateT_SysUser(int id, string userAccount, string pwd)
 {
     T_SysUser t_SysUser = new T_SysUser();
     t_SysUser.Id = id;
     t_SysUser.UserAccount = userAccount;
     t_SysUser.Pwd = pwd;
     return t_SysUser;
 }
Esempio n. 3
0
        public ActionResult LoginChecked(string username, string password)
        {
            base.fin_r = base.error_r;
            try
            {
                using (WechatEntities db = new WechatEntities())
                {
                    T_SysUser user = db.T_SysUser.Where(u => u.UserId == username && u.IsDeleted == false).FirstOrDefault();
                    #region 判断用户是否存在
                    if (user != null)
                    {
                        #region 密码正确
                        if (user.LoginPsw == new CommonHelper().MD5(password))
                        {
                            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, username, DateTime.Now, DateTime.Now.AddMinutes(90),
                                                                                             true, string.Format("{0}:{1}", username, password), FormsAuthentication.FormsCookiePath);

                            string ticString = FormsAuthentication.Encrypt(ticket);

                            //把票据信息写入Cookie和Session
                            //SetAuthCookie方法用于标识用户的Identity状态为true
                            HttpContext.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, ticString));
                            FormsAuthentication.SetAuthCookie(username, true);
                            HttpContext.Session["USER_LOGON_TICKET"] = ticString;

                            //重写HttpContext中的用户身份,可以封装自定义角色数据;
                            //判断是否合法用户,可以检查:HttpContext.User.Identity.IsAuthenticated的属性值
                            string[]   roles     = ticket.UserData.Split(',');
                            IIdentity  identity  = new FormsIdentity(ticket);
                            IPrincipal principal = new GenericPrincipal(identity, roles);
                            HttpContext.User = principal;

                            HttpContext.Session["User"] = user;
                            base.fin_r = new KeyValueModel
                            {
                                Key   = "success",
                                Value = "1秒钟后自动跳转"
                            };
                        }
                        #endregion
                        #region  正确
                        else
                        {
                            base.fin_r.Value = "用户名或者密码不正确";
                        }
                        #endregion
                    }
                    #endregion
                    #region 用户不存在
                    else
                    {
                        base.fin_r.Value = "不存在该用户";
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                base.fin_r.Value = ex.Message;
            }
            return(JsonR());
        }
 /// <summary>
 /// 架构中不存在 T_SysUser 的注释。
 /// </summary>
 public void AddToT_SysUser(T_SysUser t_SysUser)
 {
     base.AddObject("T_SysUser", t_SysUser);
 }