Exemple #1
0
        public override void InitializeComponent()
        {
            if (!Context.User.Identity.IsAuthenticated)
            {
                return;
            }
#if false   // 停止从Context.User.Identity.Name获取用户名进行自动登录
            userPrincipal = new AccountsPrincipal(Context.User.Identity.Name);
            if (Session[Globals.SESSIONKEY_USER] == null)
            {
                currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
                Session[Globals.SESSIONKEY_USER] = currentUser;
                Session["Style"] = currentUser.Style;
            }
            else
            {
                currentUser      = (YSWL.Accounts.Bus.User)Session[Globals.SESSIONKEY_USER];
                Session["Style"] = currentUser.Style;
            }
#else
            if (Session[Globals.SESSIONKEY_USER] == null)
            {
                return;
            }
            currentUser = (YSWL.Accounts.Bus.User)Session[Globals.SESSIONKEY_USER];
            if (currentUser == null)
            {
                return;
            }
            Session["Style"] = currentUser.Style;
            userPrincipal    = new AccountsPrincipal(currentUser.UserName);
#endif
        }
Exemple #2
0
        //private void BindRoles(AccountsPrincipal user)
        //{
        //    if (user.Permissions.Count > 0)
        //    {
        //        RoleList.Visible = true;
        //        ArrayList Permissions = user.Permissions;
        //        RoleList.Text = "权限列表:<ul>";
        //        for (int i = 0; i < Permissions.Count; i++)
        //        {
        //            RoleList.Text += "<li>" + Permissions[i] + "</li>";
        //        }
        //        RoleList.Text += "</ul>";
        //    }
        //}

        protected void btnSave_Click(object sender, System.EventArgs e)
        {
            if (Page.IsValid)
            {
                string            username = this.lblName.Text.Trim();
                AccountsPrincipal user     = new AccountsPrincipal(username);
                User currentUser           = new YSWL.Accounts.Bus.User(user);
                currentUser.UserName = username;
                currentUser.TrueName = txtTrueName.Text.Trim();
                //if (RadioButton1.Checked)
                //    currentUser.Sex = "1";
                //else
                //    currentUser.Sex = "0";
                //currentUser.Phone = this.txtPhone.Text.Trim();
                currentUser.Email = txtEmail.Text.Trim();
                //currentUser.UserType = dropUserType.SelectedValue;
                //int style = int.Parse(this.dropStyle.SelectedValue);
                //currentUser.Style = style;
                if (!currentUser.Update())
                {
                    Session[YSWL.Common.Globals.SESSIONKEY_ADMIN] = currentUser;
                    YSWL.Common.MessageBox.ShowFailTip(this, Resources.Site.TooltipUpdateError);
                }
                else
                {
                    YSWL.Common.MessageBox.ShowSuccessTip(this, Resources.Site.TooltipSaveOK);
                }
            }
        }
Exemple #3
0
        protected override bool InitializeComponent(ActionExecutingContext filterContext)
        {
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                filterContext.Result = RedirectToLogin(filterContext);
                return(false);
            }
            try
            {
                userPrincipal = new AccountsPrincipal(HttpContext.User.Identity.Name);
            }
            catch (System.Security.Principal.IdentityNotMappedException)
            {
                //用户在DB中不存在 退出
                System.Web.Security.FormsAuthentication.SignOut();
                Session.Remove(Globals.SESSIONKEY_SUPPLIER);
                Session.Clear();
                Session.Abandon();
                filterContext.Result = RedirectToLogin(filterContext);
                return(false);
            }
            if (Session[Globals.SESSIONKEY_SUPPLIER] == null)
            {
                currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
                Session[Globals.SESSIONKEY_SUPPLIER] = currentUser;
                Session["Style"] = currentUser.Style;
            }
            else
            {
                currentUser      = (YSWL.Accounts.Bus.User)Session[Globals.SESSIONKEY_SUPPLIER];
                Session["Style"] = currentUser.Style;
            }

            if (CurrentUser.UserType == "AG" && !string.IsNullOrWhiteSpace(Request.QueryString["AGSupplierId"]))
            {
                //Session["Agent_SupplierId"] = Request.QueryString["AGSupplierId"];
                //if (SupplierId > 0)
                //{
                //    ColoPay.BLL.Shop.Supplier.SupplierInfo bll = new ColoPay.BLL.Shop.Supplier.SupplierInfo();
                //    ColoPay.Model.Shop.Supplier.SupplierInfo model = bll.GetModelByCache(SupplierId);
                //    if (model.AgentId.ToString() != CurrentUser.DepartmentID)
                //    {
                //        filterContext.Result = RedirectToLogin(filterContext);
                //        return false;
                //    }
                //}
            }

            if (CurrentUser == null || (CurrentUser.UserType != "SP" && CurrentUser.UserType != "AG") ||
                (CurrentUser.UserType == "AG" && SupplierId < 1))
            {
                filterContext.Result = RedirectToLogin(filterContext);
                return(false);
            }

            //追加权限验证
            ValidatingPermission();
            return(true);
        }
Exemple #4
0
        public override void InitializeComponent()
        {
            if (!Context.User.Identity.IsAuthenticated)
            {
                return;
            }

#if false   // 停止从Context.User.Identity.Name获取用户名进行自动登录
            if (Session[Globals.SESSIONKEY_SUPPLIER] == null)
            {
                userPrincipal = new AccountsPrincipal(Context.User.Identity.Name);
                currentUser   = new YSWL.Accounts.Bus.User(userPrincipal);
                Session[Globals.SESSIONKEY_SUPPLIER] = currentUser;
                Session["Style"] = currentUser.Style;
            }
            else
            {
                currentUser      = (YSWL.Accounts.Bus.User)Session[Globals.SESSIONKEY_SUPPLIER];
                Session["Style"] = currentUser.Style;
            }
#else
            if (Session[Globals.SESSIONKEY_SUPPLIER] == null)
            {
                return;
            }
            currentUser      = (YSWL.Accounts.Bus.User)Session[Globals.SESSIONKEY_SUPPLIER];
            Session["Style"] = currentUser.Style;

            if (currentUser.UserType != "SP")
            {
                FormsAuthentication.SignOut();
                Session.Clear();
                Session.Abandon();
                Response.Clear();
                Response.Write("<script defer>parent.location='" + DefaultLoginSupplier + "';</script>");
                Response.End();
                return;
            }


            //Model.Shop.Supplier.SupplierInfo model = supplierManage.GetModelByCache(Globals.SafeInt(currentUser.DepartmentID, -1));
            //if (model == null || model.Status != 1)
            //{
            //    FormsAuthentication.SignOut();
            //    Session.Clear();
            //    Session.Abandon();
            //    Response.Clear();
            //    Response.Write("<script defer>parent.location='" + DefaultLoginSupplier + "';</script>");
            //    Response.End();
            //    return;
            //}
            userPrincipal = new AccountsPrincipal(currentUser.UserName);
#endif
        }
Exemple #5
0
        protected override bool InitializeComponent(ActionExecutingContext filterContext)
        {
            if (MvcApplication.IsAutoConn)//如果是SAAS 自动化链接
            {
                long enterpriseId = YSWL.Common.Globals.SafeLong(YSWL.Common.CallContextHelper.GetClearTag(), 0);
                if (enterpriseId <= 0)
                {
                    string returnUrl = YSWL.Common.ConfigHelper.GetConfigString("SAASLoginUrl");
                    filterContext.Result = Redirect(returnUrl);
                    return(false);
                }
            }
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                filterContext.Result = RedirectToLogin(filterContext);
                return(false);
            }
            try
            {
                userPrincipal = new AccountsPrincipal(HttpContext.User.Identity.Name);
            }
            catch (System.Security.Principal.IdentityNotMappedException)
            {
                //用户在DB中不存在 退出
                System.Web.Security.FormsAuthentication.SignOut();
                Session.Remove(Globals.SESSIONKEY_USER);
                Session.Clear();
                Session.Abandon();
                filterContext.Result = RedirectToLogin(filterContext);
                return(false);
            }
            if (Session[Globals.SESSIONKEY_USER] == null)
            {
                currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
                Session[Globals.SESSIONKEY_USER] = currentUser;
                Session["Style"] = currentUser.Style;
            }
            else
            {
                currentUser      = (YSWL.Accounts.Bus.User)Session[Globals.SESSIONKEY_USER];
                Session["Style"] = currentUser.Style;
            }

            if (CurrentUser == null || CurrentUser.UserType == "AA")
            {
                filterContext.Result = RedirectToLogin(filterContext);
                return(false);
            }

            //追加权限验证
            ValidatingPermission();
            return(true);
        }
Exemple #6
0
        public ActionResult Login(string returnUrl)
        {
            ViewBag.RegisterToggle = BLL.SysManage.ConfigSystem.GetValueByCache("Shop_RegisterToggle");//注册方式
            bool IsCloseLogin = YSWL.MALL.BLL.SysManage.ConfigSystem.GetBoolValueByCache("System_Close_Login");

            if (!string.IsNullOrWhiteSpace(returnUrl))
            {
                ViewBag.returnUrl = returnUrl;
            }
            if (IsCloseLogin)
            {
                return(RedirectToAction("Index", "Home"));
            }
            #region 自动登录
            bool IsNeedBind = YSWL.MALL.BLL.SysManage.ConfigSystem.GetBoolValueByCache("SyStem_WeChat_UserBind");
            if (IsNeedBind)
            {
                YSWL.WeChat.BLL.Core.User wUserBll = new WeChat.BLL.Core.User();
                if (String.IsNullOrWhiteSpace(OpenId) || String.IsNullOrWhiteSpace(UserOpen))
                {
                    return(View());
                }
                YSWL.WeChat.Model.Core.User wUserModel = wUserBll.GetUser(OpenId, UserOpen);
                if (wUserModel.UserId <= 0)
                {
                    return(View());
                }
                AccountsPrincipal userPrincipal = new AccountsPrincipal(wUserModel.UserId);

                User currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
                if (!currentUser.Activity)
                {
                    return(View());
                }
                HttpContext.User = userPrincipal;
                Session[YSWL.Common.Globals.SESSIONKEY_USER] = currentUser;
                FormsAuthentication.SetAuthCookie(currentUser.UserName, true);
                return(String.IsNullOrWhiteSpace(returnUrl) ? Redirect(ViewBag.BasePath + "Profile/Index") : Redirect(returnUrl));
            }
            #endregion
            //string returnUrl = Request.QueryString["returnUrl"];


            if (CurrentUser != null && CurrentUser.UserType != "AA")
            {
                return(String.IsNullOrWhiteSpace(returnUrl) ? Redirect(ViewBag.BasePath + "Profile/Index") : Redirect(returnUrl));
            }
            //三方登录Key
            ViewBag.Title = "登录";
            return(View());
        }
Exemple #7
0
        private void InitializeComponent()
        {
            if (!Page.IsPostBack)
            {
                if (!Context.User.Identity.IsAuthenticated)
                {
                    string defaullogin = BLL.SysManage.ConfigSystem.GetValueByCache("DefaultLoginAdmin");
                    FormsAuthentication.SignOut();
                    Session.Clear();
                    Session.Abandon();
                    Response.Clear();
                    Response.Write("<script defer>window.alert('You do not have permission to access this page or session expired!\\n Please login again or contact your administrator!');parent.location='" + defaullogin + "';</script>");
                    Response.End();
                    return;
                }

#if false
                AccountsPrincipal user = new AccountsPrincipal(Context.User.Identity.Name);
                if (Session[Globals.SESSIONKEY_ADMIN] == null)
                {
                    YSWL.Accounts.Bus.User currentUser = new YSWL.Accounts.Bus.User(user);
                    Session[Globals.SESSIONKEY_ADMIN] = currentUser;
                    Session["Style"] = currentUser.Style;
                    Response.Write("<script defer>location.reload();</script>");
                }
                if ((PermissionID != -1) && (!user.HasPermissionID(PermissionID)))
                {
                    Response.Clear();
                    Response.Write("<script defer>window.alert('You do not have permission to access this page!\\n Please login again or contact your administrator');history.back();</script>");
                    Response.End();
                }
#else
                if (Session[Globals.SESSIONKEY_ADMIN] == null)
                {
                    return;
                }
                AccountsPrincipal user = new AccountsPrincipal(
                    ((YSWL.Accounts.Bus.User)
                     Session[Globals.SESSIONKEY_ADMIN]).UserName);
                if ((PermissionID != -1) && (!user.HasPermissionID(PermissionID)))
                {
                    Response.Clear();
                    Response.Write("<script defer>window.alert('You do not have permission to access this page!\\n Please login again or contact your administrator');history.back();</script>");
                    Response.End();
                }
#endif
            }
        }
Exemple #8
0
 public void UpdateUserInfo(FormCollection collection)
 {
     if (!HttpContext.User.Identity.IsAuthenticated || CurrentUser == null)
     {
         RedirectToAction(ViewBag.BasePath + "Account/Login");//去登录
     }
     else
     {
         JsonObject json = new JsonObject();
         Model.Members.UsersExpModel model = bllUE.GetUsersModel(CurrentUser.UserID);
         if (null == model)
         {
             RedirectToAction("Login");//去登录
         }
         else
         {
             model.TelPhone = collection["TelPhone"];
             string birthday = collection["Birthday"];
             if (!string.IsNullOrWhiteSpace(birthday) && PageValidate.IsDateTime(birthday))
             {
                 model.Birthday = Globals.SafeDateTime(birthday, DateTime.Now);
             }
             else
             {
                 model.Birthday = null;
             }
             model.Constellation  = collection["Constellation"];  //星座
             model.PersonalStatus = collection["PersonalStatus"]; //职业
             model.Singature      = collection["Singature"];
             model.Address        = collection["Address"];
             User currentUser = new YSWL.Accounts.Bus.User(CurrentUser.UserID);
             currentUser.Sex      = collection["Sex"];
             currentUser.Email    = collection["Email"];
             currentUser.NickName = collection["NickName"];
             currentUser.Phone    = collection["Phone"];
             if (currentUser.Update() && bllUE.Update(model))
             {
                 json.Accumulate("STATUS", "SUCC");
             }
             else
             {
                 json.Accumulate("STATUS", "FAIL");
             }
             Response.Write(json.ToString());
         }
     }
 }
Exemple #9
0
 protected void gridView_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "Status")
     {
         if (e.CommandArgument != null)
         {
             int      Id   = 0;
             string[] Args = e.CommandArgument.ToString().Split(new char[] { ',' });
             Id = YSWL.Common.Globals.SafeInt(Args[0], 0);
             AccountsPrincipal user = new AccountsPrincipal(Id);
             User currentUser       = new YSWL.Accounts.Bus.User(user);
             bool Status            = YSWL.Common.Globals.SafeBool(Args[1], false);
             currentUser.Activity = Status ? false : true;
             currentUser.Update();
             gridView.OnBind();
         }
     }
 }
Exemple #10
0
        protected void btnSave_Click(object sender, System.EventArgs e)
        {
            string            username = this.lblName.Text.Trim();
            AccountsPrincipal user     = new AccountsPrincipal(username);
            User currentUser           = new YSWL.Accounts.Bus.User(user);

            currentUser.UserName = username;
            currentUser.TrueName = txtTrueName.Text.Trim();
            if (txtPassword.Text.Trim() != "")
            {
                currentUser.Password = AccountsPrincipal.EncryptPassword(txtPassword.Text);
            }
            //if (RadioButton1.Checked)
            //    currentUser.Sex = "1";
            //else
            //    currentUser.Sex = "0";

            currentUser.UserType = dropUserType.SelectedValue;
            currentUser.Phone    = this.txtPhone.Text.Trim();
            currentUser.Email    = txtEmail.Text.Trim();
            if (txtEmployeeID.Text.Length > 0)
            {
                currentUser.EmployeeID = Convert.ToInt32(txtEmployeeID.Text);
            }
            else
            {
                currentUser.EmployeeID = 0;
            }
            currentUser.Activity = !chkActive.Checked;

            //int style = int.Parse(this.dropStyle.SelectedValue);
            //currentUser.Style = style;

            if (!currentUser.Update())
            {
                this.lblMsg.ForeColor = Color.Red;
                this.lblMsg.Text      = Resources.Site.TooltipUpdateError;
            }
            else
            {
                LogHelp.AddUserLog(CurrentUser.UserName, CurrentUser.UserType, string.Format("编辑用户:【{0}】", username), this);
                Response.Redirect("useradmin.aspx");
            }
        }
Exemple #11
0
        protected override bool InitializeComponent(ActionExecutingContext filterContext)
        {
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                filterContext.Result = RedirectToLogin(filterContext);
                return(false);
            }
            try
            {
                userPrincipal = new AccountsPrincipal(HttpContext.User.Identity.Name);
            }
            catch (System.Security.Principal.IdentityNotMappedException)
            {
                //用户在DB中不存在 退出
                System.Web.Security.FormsAuthentication.SignOut();
                Session.Remove(Globals.SESSIONKEY_ADMIN);
                Session.Clear();
                Session.Abandon();
                filterContext.Result = RedirectToLogin(filterContext);
                return(false);
            }
            if (Session[Globals.SESSIONKEY_ADMIN] == null)
            {
                currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
                Session[Globals.SESSIONKEY_ADMIN] = currentUser;
                Session["Style"] = currentUser.Style;
            }
            else
            {
                currentUser      = (YSWL.Accounts.Bus.User)Session[Globals.SESSIONKEY_ADMIN];
                Session["Style"] = currentUser.Style;
            }


            if (CurrentUser == null || (CurrentUser.UserType != "AA"))
            {
                filterContext.Result = RedirectToLogin(filterContext);
                return(false);
            }

            //追加权限验证
            ValidatingPermission();
            return(true);
        }
Exemple #12
0
 /// <summary>
 /// 加载已登录用户对象和Style数据, 由子类实现 采用虚方法 子类可选
 /// </summary>
 protected virtual bool InitializeComponent(ActionExecutingContext filterContext)
 {
     if (HttpContext.User.Identity.IsAuthenticated)
     {
         try
         {
             userPrincipal = new AccountsPrincipal(HttpContext.User.Identity.Name);
         }
         catch (System.Security.Principal.IdentityNotMappedException)
         {
             //用户在DB中不存在 退出
             System.Web.Security.FormsAuthentication.SignOut();
             Session.Remove(Globals.SESSIONKEY_USER);
             Session.Clear();
             Session.Abandon();
             return(false);
         }
         if (Session[Globals.SESSIONKEY_USER] == null)
         {
             if (MvcApplication.IsAutoConn)
             {
                 //用户在DB中不存在 退出
                 System.Web.Security.FormsAuthentication.SignOut();
                 Session.Clear();
                 Session.Abandon();
                 return(false);
             }
             else
             {
                 currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
                 Session[Globals.SESSIONKEY_USER] = currentUser;
                 Session["Style"] = currentUser.Style;
             }
         }
         else
         {
             currentUser      = (YSWL.Accounts.Bus.User)Session[Globals.SESSIONKEY_USER];
             Session["Style"] = currentUser.Style;
             ViewBag.UserType = currentUser.UserType;
         }
         ViewBag.CurrentUserId = currentUser.UserID;
     }
     return(true);
 }
Exemple #13
0
 /// <summary>
 /// 加载已登录用户对象和Style数据, 子类可替换此基础逻辑
 /// </summary>
 public virtual void InitializeComponent()
 {
     //DONE: 20120922单点登录功能恢复 BEN ADD
     if (Context.User.Identity.IsAuthenticated)
     {
         userPrincipal = new AccountsPrincipal(Context.User.Identity.Name);
         if (Session[Globals.SESSIONKEY_ADMIN] == null)
         {
             currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
             Session[Globals.SESSIONKEY_ADMIN] = currentUser;
             Session["Style"] = currentUser.Style;
         }
         else
         {
             currentUser      = (YSWL.Accounts.Bus.User)Session[Globals.SESSIONKEY_ADMIN];
             Session["Style"] = currentUser.Style;
         }
     }
 }
Exemple #14
0
        public ActionResult UserModify(string txtName, string txtTrueName, string txtEmail)
        {
            AccountsPrincipal user = new AccountsPrincipal(txtName.Trim());

            YSWL.Accounts.Bus.User currentUser = new YSWL.Accounts.Bus.User(user);
            currentUser.UserName = txtName;
            currentUser.TrueName = txtTrueName.Trim();
            currentUser.Email    = txtEmail.Trim();
            JsonObject json = new JsonObject();

            if (currentUser.Update())
            {
                json.Put("Result", "OK");
                return(Json(json));
            }
            else
            {
                json.Put("Result", "NO");
                return(Json(json));
            }
        }
Exemple #15
0
        public ActionResult AjaxLogin(string UserName, string UserPwd)
        {
            bool IsCloseLogin = YSWL.MALL.BLL.SysManage.ConfigSystem.GetBoolValueByCache("System_Close_Login");

            if (IsCloseLogin)
            {
                return(Content("-1"));
            }
            if (ModelState.IsValid)
            {
                AccountsPrincipal userPrincipal = AccountsPrincipal.ValidateLogin(UserName, UserPwd);
                if (userPrincipal != null)
                {
                    User currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
                    if (!currentUser.Activity)
                    {
                        ModelState.AddModelError("Message", "对不起,该帐号已被冻结,请联系管理员!");
                    }
                    //if (currentUser.UserType == "AA")
                    //{
                    //    ModelState.AddModelError("Message", "您是管理员用户,您没有权限登录后台系统!") ;
                    //}
                    HttpContext.User = userPrincipal;
                    FormsAuthentication.SetAuthCookie(UserName, true);
                    Session[YSWL.Common.Globals.SESSIONKEY_USER] = currentUser;
                    //登录成功加积分
                    YSWL.MALL.BLL.Members.PointsDetail pointBll = new BLL.Members.PointsDetail();
                    int pointers  = pointBll.AddPoints(1, currentUser.UserID, "登录操作");
                    int rankScore = BLL.Members.RankDetail.AddScore(1, currentUser.UserID, "登录操作");
                    return(Content(string.Format("1|{0}|{1}", pointers, rankScore)));
                }
                else
                {
                    return(Content("0"));
                }
            }
            return(Content("0"));
        }
Exemple #16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (String.IsNullOrWhiteSpace(returnUrl))
                {
                    return;
                }
                User currentUser = null;

                Page.Title = MvcApplication.SiteName + "-系统登录";

                if (Session[Globals.SESSIONKEY_ADMIN] != null)
                {
                    Response.Redirect("main.htm");
                }


                if (YSWL.Common.ConfigHelper.GetConfigBool("LocalTest"))
                {
                    AccountsPrincipal newUser = AccountsPrincipal.ValidateLogin("admin", "1");
                    currentUser  = new YSWL.Accounts.Bus.User(newUser);
                    Context.User = newUser;
                    FormsAuthentication.SetAuthCookie(currentUser.UserName, false);
                    Session[YSWL.Common.Globals.SESSIONKEY_ADMIN] = currentUser;
                    Session["Style"] = currentUser.Style;

                    //选择语言
                    Session["language"] = "zh-CN";
                    HttpCookie mCookie = new HttpCookie("language");
                    mCookie.Value   = "zh-CN";
                    mCookie.Expires = DateTime.MaxValue;
                    Response.AppendCookie(mCookie);
                    YSWL.Common.MessageBox.ShowSuccessTip(this, "自动登录成功, 正在为您跳转..", "main.htm");
                }
            }
        }
Exemple #17
0
        public ActionResult UserPass(string oldPassword, string newPassword, string confirmPassword)
        {
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));                                           //去登录
            }
            SiteIdentity SID  = new SiteIdentity(User.Identity.Name);
            JsonObject   json = new JsonObject();

            if (SID.TestPassword(oldPassword) == 0)
            {
                json.Put("Result", "Error");
                return(Json(json));
            }
            else
            {
                if (newPassword.Trim() != confirmPassword.Trim())
                {
                    json.Put("Result", "ConfirmError");
                    return(Json(json));
                }
                else
                {
                    YSWL.Accounts.Bus.User currentUser = CurrentUser;
                    if (!currentUser.SetPassword(CurrentUser.UserName, newPassword, MvcApplication.IsAutoConn))
                    {
                        json.Put("Result", "NO");
                        return(Json(json));
                    }
                    else
                    {
                        json.Put("Result", "OK");
                        return(Json(json));
                    }
                }
            }
        }
Exemple #18
0
        public ActionResult Login(MALL.ViewModel.SNS.LogOnModel model, string returnUrl)
        {
            ViewBag.Title = "登录";
            bool IsCloseLogin = YSWL.MALL.BLL.SysManage.ConfigSystem.GetBoolValueByCache("System_Close_Login");

            if (IsCloseLogin)
            {
                return(RedirectToAction("TurnOff", "Error"));
            }
            if (ModelState.IsValid)
            {
                AccountsPrincipal userPrincipal = AccountsPrincipal.ValidateLogin(model.Email, model.Password);
                if (userPrincipal == null)
                {
                    ModelState.AddModelError("Message", "用户名或密码不正确, 请重新输入!");
                    return(View(model));
                }

                User currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
                if (!currentUser.Activity)
                {
                    ModelState.AddModelError("Message", "对不起,该帐号已被冻结,请联系管理员!");
                    return(View(model));
                }
                HttpContext.User = userPrincipal;
                FormsAuthentication.SetAuthCookie(model.Email, model.RememberMe);
                Session[YSWL.Common.Globals.SESSIONKEY_USER] = currentUser;
                //登录成功加积分
                YSWL.MALL.BLL.Members.PointsDetail pointBll = new BLL.Members.PointsDetail();
                int pointers  = pointBll.AddPoints(1, currentUser.UserID, "登录操作");
                int rankScore = BLL.Members.RankDetail.AddScore(1, currentUser.UserID, "登录操作");

                #region 默认加小组  加失败之后显示加入小组按钮
                //加入小组
                YSWL.MALL.Model.SNS.GroupUsers groupModel = new Model.SNS.GroupUsers();
                if (!bll.Exists(GroupId, currentUser.UserID))
                {
                    groupModel.GroupID  = GroupId;
                    groupModel.JoinTime = DateTime.Now;
                    groupModel.NickName = currentUser.NickName;
                    groupModel.UserID   = currentUser.UserID;
                    groupModel.Status   = 1;
                    if (!bll.AddEx(groupModel))
                    {
                        ViewBag.joined = "error";
                    }
                }
                #endregion


                //加载Shop模块的购物车
                if (CurrentThemeName == "TaoLe")
                {
                    BLL.Shop.Products.ShoppingCartHelper.LoadShoppingCart(currentUser.UserID);
                }

                if (Session["ReturnUrl"] != null && !String.IsNullOrWhiteSpace(Session["ReturnUrl"].ToString()))
                {
                    returnUrl = Session["ReturnUrl"].ToString();
                    Session.Remove("ReturnUrl");
                    return(Redirect(returnUrl));
                }
                if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                    !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                {
                    return(Redirect(returnUrl));
                }
                else
                {
                    TempData["pointer"]   = pointers;
                    TempData["rankScore"] = rankScore;
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(model));
        }
Exemple #19
0
        /// <summary>
        /// 重写父类的登录跳转, 指向SNS登录
        /// </summary>
        public override ActionResult RedirectToLogin(ActionExecutingContext filterContext)
        {
            string rawurl      = Request.RawUrl;
            bool   IsAutoLogin = Common.Globals.SafeBool(YSWL.WeChat.BLL.Core.Config.GetValueByCache("WeChat_AutoLogin", -1, "AA"), false);

            #region  自动登陆
            bool IsNeedBind = YSWL.MALL.BLL.SysManage.ConfigSystem.GetBoolValueByCache("SyStem_WeChat_UserBind");

            if (Session[YSWL.Common.Globals.SESSIONKEY_USER] != null && CurrentUser != null && CurrentUser.UserType != "AA")
            {
                BLL.Shop.Products.ShoppingCartHelper.LoadShoppingCart(currentUser.UserID);
                return(String.IsNullOrWhiteSpace(rawurl) ? Redirect(ViewBag.BasePath) : Redirect(rawurl));
            }
            YSWL.WeChat.BLL.Core.User wUserBll = new WeChat.BLL.Core.User();
            if (String.IsNullOrWhiteSpace(OpenId) || String.IsNullOrWhiteSpace(UserOpen))
            {
                return(Redirect(ViewBag.BasePath + "Account/Login?returnUrl=" + Server.UrlEncode(rawurl)));
            }
            YSWL.WeChat.Model.Core.User wUserModel = wUserBll.GetUser(OpenId, UserOpen);
            if (IsNeedBind)
            {
                if (wUserModel.UserId <= 0)
                {
                    return(Redirect(ViewBag.BasePath + "Account/Login?returnUrl=" + Server.UrlEncode(rawurl)));
                }
                AccountsPrincipal userPrincipal = new AccountsPrincipal(wUserModel.UserId);
                User currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
                if (!currentUser.Activity)
                {
                    return(Redirect(ViewBag.BasePath + "Account/Login?returnUrl=" + Server.UrlEncode(rawurl)));
                }
                HttpContext.User = userPrincipal;

                #region 自动加入小组
                int groupId = BLL.SysManage.ConfigSystem.GetIntValueByCache("V_SNS_GroupId");
                YSWL.MALL.Model.SNS.GroupUsers groupModel = new Model.SNS.GroupUsers();
                YSWL.MALL.BLL.SNS.GroupUsers   bll        = new YSWL.MALL.BLL.SNS.GroupUsers();
                if (!bll.Exists(groupId, currentUser.UserID))
                {
                    groupModel.GroupID  = groupId;
                    groupModel.JoinTime = DateTime.Now;
                    groupModel.NickName = currentUser.NickName;
                    groupModel.UserID   = currentUser.UserID;
                    groupModel.Status   = 1;
                    if (!bll.AddEx(groupModel))
                    {
                        ViewBag.joined = "error";
                    }
                }
                #endregion

                Session[YSWL.Common.Globals.SESSIONKEY_USER] = currentUser;
                FormsAuthentication.SetAuthCookie(currentUser.UserName, true);
                return(String.IsNullOrWhiteSpace(rawurl) ?
                       Redirect(ViewBag.BasePath + "Home") : Redirect(rawurl));
            }
            if (IsAutoLogin)
            {
                string AutoLoginUrl = "/COM/Account/RegBind?returnUrl=" + Server.UrlEncode(rawurl);
                if (wUserModel.UserId <= 0)
                {
                    return(Redirect(AutoLoginUrl));
                }
                AccountsPrincipal userPrincipal = new AccountsPrincipal(wUserModel.UserId);
                if (userPrincipal == null)
                {
                    return(Redirect(AutoLoginUrl));
                }
                User currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
                if (!currentUser.Activity)
                {
                    return(Redirect(AutoLoginUrl));
                }
                HttpContext.User = userPrincipal;
                Session[YSWL.Common.Globals.SESSIONKEY_USER] = currentUser;
                FormsAuthentication.SetAuthCookie(currentUser.UserName, true);
                return(String.IsNullOrWhiteSpace(rawurl) ? Redirect(ViewBag.BasePath) : Redirect(rawurl));
            }

            #endregion

            return(Redirect(ViewBag.BasePath + "Account/Login?returnUrl=" + Server.UrlEncode(rawurl)));
        }
Exemple #20
0
        public void btnLogin_Click(object sender, EventArgs e)
        {
            if ((Session["PassErrorCountAdmin"] != null) && (Session["PassErrorCountAdmin"].ToString() != ""))
            {
                int PassErroeCount = Convert.ToInt32(Session["PassErrorCountAdmin"]);
                if (PassErroeCount > 3)
                {
                    txtUsername.Enabled = false;
                    txtPass.Enabled     = false;
                    btnLogin.Enabled    = false;
                    this.lblMsg.Text    = "对不起,你已经登录错误三次,系统锁定,请联系管理员!";
                    return;
                }
            }
            if ((Session["CheckCode"] != null) && (Session["CheckCode"].ToString() != ""))
            {
                if (Session["CheckCode"].ToString().ToLower() != this.CheckCode.Value.ToLower())
                {
                    this.lblMsg.Text     = "验证码错误!";
                    Session["CheckCode"] = null;
                    return;
                }
                else
                {
                    Session["CheckCode"] = null;
                }
            }
            else
            {
                Response.Redirect("Login.aspx");
            }

            #region

            string            userName      = YSWL.Common.PageValidate.InputText(txtUsername.Text.Trim(), 30);
            string            Password      = YSWL.Common.PageValidate.InputText(txtPass.Text.Trim(), 30);
            AccountsPrincipal userPrincipal = AccountsPrincipal.ValidateLogin(userName, Password);
            if (userPrincipal != null)
            {
                User currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
                if (currentUser.UserType != "AA")
                {
                    this.lblMsg.Text = "您非管理员用户或者业务员,您没有权限登录后台系统!";
                    return;
                }
                Context.User = userPrincipal;
                if (((SiteIdentity)User.Identity).TestPassword(Password) == 0)
                {
                    try
                    {
                        this.lblMsg.Text = "密码错误!";
                        LogHelp.AddUserLog(userName, "", lblMsg.Text, this);
                    }
                    catch
                    {
                        Response.Redirect("Login.aspx");
                    }
                }
                else
                {
                    if (!currentUser.Activity)
                    {
                        YSWL.Common.MessageBox.ShowSuccessTip(this, "对不起,该帐号已被冻结,请联系管理员!");
                        return;
                    }

                    #region 单用户登录模式

                    //单用户登录模式
                    //SingleLogin slogin = new SingleLogin();

                    ////if (slogin.IsLogin(currentUser.UserID))
                    ////{
                    ////    YSWL.Common.MessageBox.ShowSuccessTip(this, "对不起,你的帐号已经登录!");
                    ////    return;
                    ////}
                    //slogin.UserLogin(currentUser.UserID);

                    #endregion 单用户登录模式

                    FormsAuthentication.SetAuthCookie(userName, false);

                    Session[YSWL.Common.Globals.SESSIONKEY_ADMIN] = currentUser;
                    Session["Style"] = currentUser.Style;

                    //log
                    LogHelp.AddUserLog(currentUser.UserName, currentUser.UserType, "登录成功", this);


                    if (Session["returnPage"] != null)
                    {
                        string returnpage = Session["returnPage"].ToString();
                        Session["returnPage"] = null;
                        Response.Redirect(returnpage);
                    }
                    else
                    {
                        Response.Redirect("main.htm");
                    }
                }
            }
            else
            {
                this.lblMsg.Text = "登录失败,请确认用户名或密码是否正确。";
                if ((Session["PassErrorCountAdmin"] != null) && (Session["PassErrorCountAdmin"].ToString() != ""))
                {
                    int PassErroeCount = Convert.ToInt32(Session["PassErrorCountAdmin"]);
                    Session["PassErrorCountAdmin"] = PassErroeCount + 1;
                }
                else
                {
                    Session["PassErrorCountAdmin"] = 1;
                }

                //log
                LogHelp.AddUserLog(userName, "", "登录失败!", this);
            }

            #endregion
        }
Exemple #21
0
        private void InitializeComponent()
        {
            #region 安装检测
            if (!MvcApplication.IsInstall)
            {
                Response.Write("<script language='javascript'>window.top.location='/Installer/Default.aspx'</script>");
                Response.End();
                return; //未安装 终止
            }

            #region 设置企业标识

            if (MvcApplication.IsAutoConn)
            {
                string userName = YSWL.AuthenticationManagerClient.ClientManager.CheckUser();
                if (String.IsNullOrWhiteSpace(userName))//单点登录已经退出
                {
                    System.Web.Security.FormsAuthentication.SignOut();
                    Session.Clear();
                    Session.Abandon();
                    Response.Write("<script language='javascript'>window.top.location='" + DefaultLoginAdmin + "'</script>");
                    Response.End();
                    return;
                }
                //如果session过期了,重新赋值
                if (Session[Globals.SESSIONKEY_ADMIN] == null)
                {
                    currentUser = new User(userName);
                    Session[Globals.SESSIONKEY_ADMIN] = currentUser;
                }

                long enterpriseId = Common.Globals.SafeLong(YSWL.Common.CallContextHelper.GetAutoTag(), 0);
                if (enterpriseId == 0)
                {
                    Response.Write("<script language='javascript'>window.top.location='" + DefaultLoginAdmin + "'</script>");
                    Response.End();
                    return; //企业标识丢失,重新登陆
                }
                Common.CallContextHelper.SetAutoTag(enterpriseId);
            }

            #endregion


            #endregion
            //if (!Page.IsPostBack)
            {
                if (string.IsNullOrWhiteSpace(DefaultLoginAdmin))   //BEN ADD 2012-10-25 客户反馈, 登录跳转死循环BUG修复
                {
                    throw new ArgumentNullException("SA_Config_System - KEY [DefaultLoginAdmin] IS NULL!");
                }
                //DONE: 20121219单点登录功能恢复 BEN ADD
                if (!Context.User.Identity.IsAuthenticated) //|| Session[Globals.SESSIONKEY_ADMIN] == null)
                {
                    FormsAuthentication.SignOut();
                    Session.Clear();
                    Session.Abandon();
                    Response.Clear();
                    //Response.Write("<script defer>window.alert('" + PageBaseMessageTip.TooltipNoAuthenticated + "');parent.location='" + DefaultLoginAdmin + "';</script>");
                    Response.Write("<script defer>parent.location='" + DefaultLoginAdmin + "';</script>");
                    Response.End();
                    return;
                }

#if true       //DONE: 启用从Context.User.Identity.Name获取用户名进行自动登录 20121219单点登录功能恢复 BEN ADD
                userPrincipal = new AccountsPrincipal(Context.User.Identity.Name);

                if ((GetPermidByActID(Act_PageLoad) != -1) && (!userPrincipal.HasPermissionID(GetPermidByActID(Act_PageLoad))))
                {
                    Response.Clear();
                    Response.Write("<script defer>window.alert('" + PageBaseMessageTip.TooltipNoPermission + "');history.back();</script>");
                    Response.End();
                }

                if (Session[Globals.SESSIONKEY_ADMIN] == null)
                {
                    if (MvcApplication.IsAutoConn)
                    {
                        //用户在DB中不存在 退出
                        System.Web.Security.FormsAuthentication.SignOut();
                        Session.Clear();
                        Session.Abandon();
                        return;
                    }
                    else
                    {
                        currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
                        Session[Globals.SESSIONKEY_ADMIN] = currentUser;
                        Session["Style"] = currentUser.Style;
                    }
                    ////Response.Write("<script defer>location.reload();</script>");
                    ////跳转到 session 超时页面,提示用户重新登录

                    //Response.Clear();
                    //Response.Write("<script defer>window.alert('" + PageBaseMessageTip.TooltipSessionExpired + "');parent.location='" + defaullogin + "';</script>");
                    //Response.End();
                }
                else
                {
                    currentUser      = (YSWL.Accounts.Bus.User)Session[Globals.SESSIONKEY_ADMIN];
                    Session["Style"] = currentUser.Style;

                    string        allowUserType = ConfigHelper.GetConfigString("UserType");
                    List <String> UserTypeList  = new List <string> {
                        "AA"
                    };                                                    //允许后台登录的用户类型
                    if (!String.IsNullOrWhiteSpace(allowUserType))
                    {
                        UserTypeList.AddRange(allowUserType.Split(','));
                    }

                    if (!UserTypeList.Contains(currentUser.UserType))
                    {
                        FormsAuthentication.SignOut();
                        Session.Clear();
                        Session.Abandon();
                        Response.Clear();
                        Response.Write("<script defer>parent.location='" + DefaultLoginAdmin + "';</script>");
                        Response.End();
                        return;
                    }
                }
#else
                currentUser = (YSWL.Accounts.Bus.User)Session[Globals.SESSIONKEY_ADMIN];
                if (currentUser.UserType != "AA")
                {
                    FormsAuthentication.SignOut();
                    Session.Clear();
                    Session.Abandon();
                    Response.Clear();
                    Response.Write("<script defer>parent.location='" + DefaultLoginAdmin + "';</script>");
                    Response.End();
                    return;
                }
                Session["Style"] = currentUser.Style;

                userPrincipal = new AccountsPrincipal(currentUser.UserName);

                //if ((PermissionID != -1) && (!userPrincipal.HasPermissionID(PermissionID)))
                //{
                //    Response.Clear();
                //    Response.Write("<script defer>window.alert('" + PageBaseMessageTip.TooltipNoPermission + "');history.back();</script>");
                //    Response.End();
                //}

                if ((GetPermidByActID(Act_PageLoad) != -1) && (!userPrincipal.HasPermissionID(GetPermidByActID(Act_PageLoad))))
                {
                    Response.Clear();
                    Response.Write("<script defer>window.alert('" + PageBaseMessageTip.TooltipNoPermission + "');history.back();</script>");
                    Response.End();
                }
#endif
            }
        }
Exemple #22
0
 public ActionResult UserPass()
 {
     YSWL.Accounts.Bus.User currentUser = this.CurrentUser;
     return(View(currentUser));
 }