Exemplo n.º 1
0
        public void ResetPwd()
        {
            try
            {
                string password = Request["password"];
                if (string.IsNullOrEmpty(password))
                {
                    throw new Exception("密码不能为空");
                }
                if (Session["Step2"] == null)
                {
                    throw new Exception("账号为空,非法请求");
                }
                using (ProxyBE p = new ProxyBE())
                {
                    PartnerUser partner = p.Client.GetPartnerUserByUserCode(null, Session["Step2"].ToString());
                    if (partner == null)
                    {
                        throw new PException("用户不存在");
                    }
                    partner.Password = CEncrypt.EncryptString(password);

                    SavePartnerUserArgs pargs = new SavePartnerUserArgs();
                    pargs.PartnerUser = partner;
                    p.Client.SavePartnerUser(SenderUser, pargs);
                    Session["Step3"] = true;
                    WriteMessage(1, "resetComplete.html");
                }
            }
            catch (Exception ex)
            {
                WriteError(ex.Message);
            }
        }
Exemplo n.º 2
0
        public void ModifyPasswordByEgui()
        {
            string OldPassword = Request["OldPassword"];
            string NewPassword = Request["NewPassword"];

            try
            {
                using (ProxyBE p = new ProxyBE())
                {
                    PartnerUser partnetUser = p.Client.GetPartnerUser(SenderUser, this.CurrentUser.UserID);
                    if (CEncrypt.DecryptString(partnetUser.Password) != OldPassword)
                    {
                        WriteMessage(-1, "原密码错误,请重新输入");
                        return;
                    }
                    partnetUser.Password = CEncrypt.EncryptString(NewPassword);
                    SavePartnerUserArgs arge = new SavePartnerUserArgs();
                    arge.PartnerUser = partnetUser;
                    p.Client.SavePartnerUser(SenderUser, arge);
                    WriteSuccess();
                }
            }
            catch (Exception ex)
            {
                WriteError(ex.Message, ex);
            }
        }
Exemplo n.º 3
0
        public void ResetPwd()
        {
            try
            {
                Guid UserID = Guid.Empty;
                if (!string.IsNullOrEmpty(Request["UserID"]))
                {
                    UserID = Guid.Parse(Request["UserID"].ToString());
                }
                using (ProxyBE p = new ProxyBE())
                {
                    var partnerUser = p.Client.GetPartnerUser(SenderUser, UserID);
                    if (partnerUser == null)
                    {
                        throw new Exception("查找的用户不存在");
                    }
                    partnerUser.Password        = CEncrypt.EncryptString(UserDefaultPassword);
                    partnerUser.LoginErrorCount = 0;
                    partnerUser.IsLocked        = false;
                    partnerUser.IsLocked        = false;

                    SavePartnerUserArgs args = new SavePartnerUserArgs();
                    args.PartnerUser = partnerUser;
                    p.Client.SavePartnerUser(SenderUser, args);
                    WriteSuccess();
                }
            }
            catch (Exception ex)
            {
                WriteError(ex.Message, ex);
            }
        }
Exemplo n.º 4
0
        //当前用户修改密码
        public void ModifiyPsw()
        {
            string OldPassword = Request["OldPassword"];
            string NewPassword = Request["NewPassword"];

            try
            {
                using (ProxyBE p = new ProxyBE())
                {
                    User user = p.Client.GetUser(SenderUser, this.CurrentUser.UserID);

                    if (CEncrypt.DecryptString(user.Password) != OldPassword)
                    {
                        throw new Exception("旧密码错误");
                    }
                    user.Password = CEncrypt.EncryptString(NewPassword);
                    SaveUserArgs sarg = new SaveUserArgs();
                    sarg.User = user;
                    p.Client.SaveUser(SenderUser, sarg);
                    WriteSuccess();
                }
            }
            catch (Exception ex)
            {
                WriteError(ex.Message, ex);
            }
        }
Exemplo n.º 5
0
        //用户管理重置密码
        public void ResetPsw()
        {
            try
            {
                using (ProxyBE p = new ProxyBE())
                {
                    Guid userid = new Guid(Request["UserID"]);
                    User user   = p.Client.GetUser(SenderUser, userid);
                    if (user == null)
                    {
                        throw new Exception("所查找用户不存在。");
                    }

                    user.Password        = CEncrypt.EncryptString(UserDefaultPassword);
                    user.LoginErrorCount = 0;
                    user.IsLocked        = false;
                    user.IsDisabled      = false;
                    SaveUserArgs sarg = new SaveUserArgs();
                    sarg.User = user;
                    p.Client.SaveUser(SenderUser, sarg);
                    WriteSuccess();
                }
            }
            catch (Exception ex)
            {
                WriteError(ex.Message, ex);
            }
        }
Exemplo n.º 6
0
        public void ModifyPwd()
        {
            try
            {
                if (this.CurrentUser.UserID != Guid.Empty || this.CurrentUser != null)
                {
                    using (ProxyBE p = new ProxyBE())
                    {
                        PartnerUser user     = p.Client.GetPartnerUserByUserCode(SenderUser, CurrentUser.UserCode);
                        string      Password = Request["Password"].ToString();
                        user.Password = CEncrypt.EncryptString(Password);

                        SavePartnerUserArgs args = new SavePartnerUserArgs();
                        args.PartnerUser = user;
                        p.Client.SavePartnerUser(SenderUser, args);
                    }
                }
                this.Response.Write("{\"result\":\"success\",\"errorCode\":0}");
            }
            catch (Exception ex)
            {
                PLogger.LogError(ex);
                WriteError(ex.Message, ex);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Save User
        /// </summary>
        public void SaveUser()
        {
            using (ProxyBE p = new ProxyBE())
            {
                try
                {
                    if (Request["DepartmentID"] == "请选择")
                    {
                        throw new Exception("请选择所属部门");
                    }

                    User user = p.Client.GetUser(null, parm.UserID);
                    if (user == null)
                    {
                        user            = new User();
                        user.UserID     = parm.UserID;
                        user.Created    = DateTime.Now;
                        user.CreatedBy  = SenderUser.UserCode + "." + SenderUser.UserName;
                        user.Modified   = DateTime.Now;
                        user.ModifiedBy = SenderUser.UserCode + "." + SenderUser.UserName;
                        user.Password   = CEncrypt.EncryptString(UserDefaultPassword);
                    }
                    user.UserCode = parm.UserCode.Trim();
                    user.UserName = parm.UserName.Trim();
                    user.Sex      = parm.Sex.Trim();
                    user.Position = parm.Position.Trim();
                    user.Email    = parm.Email.Trim();
                    //手机号码唯一
                    user.Mobile          = parm.Mobile.Trim();
                    user.Description     = parm.Description.Trim();
                    user.IDNumber        = parm.IDNumber;
                    user.LoginErrorCount = 0;
                    user.IsDisabled      = Convert.ToBoolean(parm.IsDisabled);
                    user.IsLocked        = parm.IsLocked;
                    user.DepartmentID    = parm.DepartmentID;
                    SaveUserArgs args = new SaveUserArgs();
                    args.User = user;

                    string RoleIDs = Request["RoleIDs"];
                    if (!string.IsNullOrEmpty(RoleIDs))
                    {
                        args.RoleIDs = new List <Guid>();
                        string[] roles = RoleIDs.Split(',');
                        foreach (string item in roles)
                        {
                            args.RoleIDs.Add(new Guid(item));
                        }
                    }
                    p.Client.SaveUser(SenderUser, args);
                    WriteSuccess();
                }
                catch (Exception ex)
                {
                    WriteError(ex.Message, ex);
                }
            }
        }
Exemplo n.º 8
0
        public void ModifyPassword()
        {
            try
            {
                if (CurrentUser == null || CurrentUser.UserID == Guid.Empty)
                {
                    throw new Exception("未获取到用户信息,请先登录");
                }
                using (ProxyBE be = new ProxyBE())
                {
                    #region 登录
                    User   user     = be.Client.GetUserByUserCode(null, CurrentUser.UserCode);
                    string Password = Request["Password"].ToString();
                    user.Password = CEncrypt.EncryptString(Password);

                    SaveUserArgs args = new SaveUserArgs();
                    args.User = user;
                    be.Client.SaveUser(SenderUser, args);
                    #endregion
                }

                //StringBuilder sb = new StringBuilder();
                //sb.Append("{");
                //sb.AppendFormat("'isOk':{0}", 1);
                //sb.AppendFormat(",'message':'{0}'", "success");
                //sb.AppendFormat(",'url':'{0}'", url);
                //sb.Append("}");
                //Response.Write(sb.ToString());
                Response.Write("{\"result\":\"success\",\"errorCode\":0}");
            }
            catch (Exception ex)
            {
                PLogger.LogError(ex);
                WriteError(ex.Message);
            }
        }
Exemplo n.º 9
0
        public void Login()
        {
            try
            {
                string UserCode   = Request["username"];
                string Password   = Request["password"];
                string VerifyCode = Request["verifycode"];

                if (string.IsNullOrEmpty(UserCode))
                {
                    throw new Exception("用户名不能为空");
                }

                if (VerifyCode.ToLower() != Session["LoginVerifyCode"].ToString().ToLower())
                {
                    throw new PException("验证码不正确");
                }

                using (ProxyBE be = new ProxyBE())
                {
                    #region 登录
                    User user = be.Client.GetUserByUserCode(null, UserCode);

                    if (user == null)
                    {
                        throw new PException("errorUserName");
                    }
                    if (user.IsLocked)
                    {
                        throw new PException("errorLockedUserName");
                    }
                    if (user.IsDisabled)
                    {
                        throw new PException("errorDisabledUserName");
                    }
                    if (user.LoginErrorCount >= 5)
                    {
                        throw new PException("errorLoginOutTimes");
                    }

                    SaveUserArgs args = new SaveUserArgs();
                    //记录当前登录时间
                    if (CEncrypt.EncryptString(Password) != user.Password)
                    {
                        user.LoginErrorCount += 1;
                        PException ex = null;
                        if (user.LoginErrorCount >= 5)
                        {
                            user.IsLocked = true;
                            ex            = new PException("errorLoginOutTimes");
                        }
                        else
                        {
                            ex = new PException("errorPassword{0}", 5 - user.LoginErrorCount);
                        }
                        args.User = user;
                        be.Client.SaveUser(base.SenderUser, args);
                        throw ex;
                    }


                    args.User            = user;
                    user.LoginErrorCount = 0;
                    user.LastLoginTime   = DateTime.Now;
                    be.Client.SaveUser(base.SenderUser, args);

                    SessionUser su = new SessionUser();
                    su.UserCode = user.UserCode;
                    //用户类型
                    su.UserType = (int)UserType.U;
                    //su.LoginUrl = UserLoginUrl;
                    su.UserID        = user.UserID;
                    su.UserName      = user.UserName;
                    su.IsSystemUser  = user.IsSystem;
                    su.LastLoginTime = user.LastLoginTime;
                    su.CompanyID     = user.CompanyID;
                    OnlineUser.Lock(su);
                    this.CurrentUser = su;
                    #endregion

                    #region 加载权限项
                    List <Role> userRoles = be.Client.GetRolesByUserID(null, user.UserID);
                    su.Roles = userRoles;

                    List <PrivilegeItem> privilegeItems = be.Client.GetPrivilegeItemByUserID(null, user.UserID);
                    var privilegeItemS = from pi in privilegeItems select pi.PrivilegeItemID;
                    su.PrivilegeItemIDs = privilegeItemS.ToList <Guid>();

                    List <Privilege> privileges = be.Client.GetPrivilegesByUserID(null, user.UserID);
                    var privilegeS = from pl in privileges select pl.PrivilegeID;
                    su.PrivilegeIDs = privilegeS.ToList <Guid>();

                    Dictionary <string, List <string> > PrivilegeCodesDir = new Dictionary <string, List <string> >();
                    foreach (var item in privileges)
                    {
                        if (PrivilegeCodesDir.ContainsKey(item.PrivilegeCode.ToLower()))
                        {
                            continue;
                        }
                        List <string> itemCodes = new List <string>();
                        var           plItems   = privilegeItems.Where(pl => pl.PrivilegeID.ToString() == item.PrivilegeID.ToString() && pl.IsDisabled == false).ToList();
                        if (plItems != null)
                        {
                            foreach (var itemPrivilegeItems in plItems)
                            {
                                itemCodes.Add(itemPrivilegeItems.PrivilegeItemCode.ToLower());
                            }
                        }
                        PrivilegeCodesDir.Add(item.PrivilegeCode.ToLower(), itemCodes);
                    }
                    su.PrivilegeCodes = PrivilegeCodesDir;
                    #endregion

                    StringBuilder sb = new StringBuilder();
                    sb.Append('{');
                    sb.Append(string.Format("\"isOk\":\"{0}\",\"message\":\"{1}\",\"url\":\"{2}\"", 1, "success", "/Index.aspx"));
                    sb.Append('}');
                    Response.Write(sb.ToString());
                    //WriteSuccess();
                }
            }
            catch (Exception ex)
            {
                PLogger.LogError(ex);
                WriteError(ex.Message);
            }
        }
Exemplo n.º 10
0
        public void SavePartnerUser()
        {
            try
            {
                using (ProxyBE p = new ProxyBE())
                {
                    PartnerUser partnerUser = p.Client.GetPartnerUser(null, parm.UserID);
                    if (partnerUser == null)
                    {
                        //新增
                        partnerUser         = new PartnerUser();
                        partnerUser.UserID  = parm.UserID;
                        partnerUser.Created = DateTime.Now;
                        //partnerUser.CreatedBy = SenderUser.UserCode + "." + SenderUser.UserName;
                        partnerUser.CreatedBy = "EGui平台";
                        partnerUser.Modified  = DateTime.Now;
                        //partnerUser.ModifiedBy = SenderUser.UserCode + "." + SenderUser.UserName;
                        partnerUser.ModifiedBy = "EGui平台";
                        //partnerUser.Password = MES.Libraries.CEncrypt.EncryptString(UserDefaultPassword);
                        partnerUser.Password = CEncrypt.EncryptString(HttpContext.Current.Request["UserPwd"]);//PWD
                    }
                    //partnerUser.UserCode = parm.UserCode.Trim();
                    partnerUser.UserCode = HttpContext.Current.Request["UserPhone"];//电话注册
                    bool flag = p.Client.PartnerUserIsDuplicated(SenderUser, partnerUser);
                    if (flag)
                    {
                        throw new Exception("该账户已经存在,请重新输入。");
                    }
                    //partnerUser.PartnerID = this.CurrentUser.PartnerID;
                    partnerUser.PartnerID = new Guid("14D08A0B-D52B-FD09-3B0E-A9C308783C90");//经销商ID
                    //partnerUser.UserName = parm.UserName.Trim();
                    partnerUser.UserName = "******" + HttpContext.Current.Request["UserPhone"];
                    //partnerUser.Sex = parm.Sex.Trim();
                    partnerUser.Sex = "";
                    //if (parm.Position == "" || parm.Position == "请选择")
                    //{
                    //    throw new Exception("请选择职位!");
                    //}
                    //partnerUser.Position = parm.Position.Trim();
                    partnerUser.Position = "量尺";
                    //partnerUser.Email = parm.Email.Trim();
                    partnerUser.Email = "";
                    //partnerUser.Mobile = parm.Mobile.Trim();
                    partnerUser.Mobile = HttpContext.Current.Request["UserPhone"];

                    //partnerUser.Description = parm.Description.Trim();
                    partnerUser.Description     = "";
                    partnerUser.LoginErrorCount = 0;
                    //partnerUser.IsDisabled = parm.IsDisabled;
                    //partnerUser.IsLocked = parm.IsLocked;

                    partnerUser.IsDisabled = false;
                    partnerUser.IsLocked   = false;

                    SavePartnerUserArgs args = new SavePartnerUserArgs();
                    args.PartnerUser = partnerUser;

                    string roleIDs = "33c49247-4d4e-828e-7fc1-b3d7cf4d2078";//角色权限
                    args.RoleIDs = new List <Guid>();
                    if (!string.IsNullOrEmpty(roleIDs))
                    {
                        string[] roles = roleIDs.Split(',');
                        foreach (var item in roles)
                        {
                            args.RoleIDs.Add(new Guid(item));
                        }
                    }
                    p.Client.SavePartnerUser(SenderUser, args);
                    WriteSuccess();
                }
            }
            catch (Exception ex)
            {
                WriteError(ex.Message, ex);
            }
        }
Exemplo n.º 11
0
        public void Login()
        {
            try
            {
                string UserCode   = Request["username"];
                string Password   = Request["password"];
                string VerifyCode = Request["verifycode"];

                if (string.IsNullOrEmpty(UserCode))
                {
                    throw new Exception("用户名不能为空");
                }
                if (VerifyCode.ToLower() != Session["LoginVerifyCode"].ToString().ToLower())
                {
                    throw new PException("验证码错误");
                }

                using (ProxyBE p = new ProxyBE())
                {
                    #region 登录
                    PartnerUser partner = p.Client.GetPartnerUserByUserCode(null, UserCode);
                    if (partner == null)
                    {
                        throw new PException("用户不存在");
                    }
                    if (partner.IsLocked)
                    {
                        throw new PException("帐号被锁");
                    }
                    if (partner.IsDisabled)
                    {
                        throw new PException("帐号禁用");
                    }
                    if (partner.MemberClass == -1)
                    {
                        throw new PException("帐号待审核,请联系客服专员");
                    }
                    if (partner.LoginErrorCount >= 5)
                    {
                        throw new PException("密码错误次数过多,帐号已被锁定,请联系管理员");
                    }
                    if (DateTime.Now > partner.EndDate)
                    {
                        throw new PException("账户已过期,请联系客服续费");
                    }
                    SavePartnerUserArgs args = new SavePartnerUserArgs();
                    if (CEncrypt.EncryptString(Password) != partner.Password)
                    {
                        partner.LoginErrorCount += 1;
                        PException ex = null;
                        if (partner.LoginErrorCount >= 5)
                        {
                            //登录错误次数过多 帐号锁定
                            partner.IsLocked = true;
                            ex = new PException("密码错误次数过多,帐号已被锁定,请联系管理员");
                        }
                        else
                        {
                            //剩余登录次数
                            ex = new PException("密码错误,您还有{0}机会", 5 - partner.LoginErrorCount);
                        }
                        args.PartnerUser = partner;
                        p.Client.SavePartnerUser(base.SenderUser, args);
                        throw ex;
                    }

                    args.PartnerUser        = partner;
                    partner.LoginErrorCount = 0;
                    partner.LastLoginTime   = DateTime.Now;
                    p.Client.SavePartnerUser(base.SenderUser, args);
                    #endregion

                    #region Session

                    SessionUser su = new SessionUser();
                    su.UserCode  = partner.UserCode;
                    su.UserID    = partner.UserID;
                    su.PartnerID = partner.PartnerID;
                    su.Position  = partner.Position;
                    //su.LoginUrl = PartnerLoginUrl;
                    su.UserName      = partner.UserName;
                    su.UserType      = (int)UserType.D;
                    su.IsSystemUser  = partner.IsSystem;
                    su.LastLoginTime = partner.LastLoginTime;
                    su.IsFinishInfo  = partner.IsFinishInfo;
                    OnlineUser.Lock(su);
                    this.CurrentUser = su;

                    #endregion

                    #region 加载权限
                    //privilegeItem
                    List <PrivilegeItem> privilegeItems = p.Client.GetPrivilegeItemByPartnerUserID(null, partner.UserID);
                    var privilegeItemS = from pi in privilegeItems select pi.PrivilegeItemID;
                    su.PrivilegeItemIDs = privilegeItemS.ToList <Guid>();

                    //privileges
                    List <Privilege> privileges = p.Client.GetPrivilegesByPartnerUserID(null, partner.UserID);
                    var privilegeS = from pl in privileges select pl.PrivilegeID;
                    su.PrivilegeIDs = privilegeS.ToList <Guid>();

                    Dictionary <string, List <string> > PrivilegeCodesDir = new Dictionary <string, List <string> >();
                    foreach (var item in privileges)
                    {
                        if (PrivilegeCodesDir.ContainsKey(item.PrivilegeCode.ToLower()))
                        {
                            continue;
                        }
                        List <string> itemCodes = new List <string>();
                        var           plItems   = privilegeItems.Where(pl => pl.PrivilegeID.ToString() == item.PrivilegeID.ToString() && pl.IsDisabled == false).ToList();
                        if (plItems != null)
                        {
                            foreach (var itemPrivilegeItems in plItems)
                            {
                                itemCodes.Add(itemPrivilegeItems.PrivilegeItemCode.ToLower());
                            }
                        }
                        PrivilegeCodesDir.Add(item.PrivilegeCode.ToLower(), itemCodes);
                    }
                    su.PrivilegeCodes = PrivilegeCodesDir;
                    #endregion

                    string url = "/Index.aspx";
                    //if (MustChangePasswordAtFirstLogin)
                    //{
                    //    if (partner.Password == CEncrypt.EncryptString(UserDefaultPassword))
                    //    {
                    //        url = "/partnerModifypwd.aspx";
                    //    }
                    //}
                    StringBuilder sb = new StringBuilder();
                    sb.Append('{');
                    sb.Append(string.Format("\"isOk\":\"{0}\",\"message\":\"{1}\",\"url\":\"{2}\"", 1, "success", url));
                    sb.Append('}');
                    Response.Write(sb.ToString());
                }
            }
            catch (Exception ex)
            {
                PLogger.LogError(ex);
                WriteError(ex.Message);
            }
        }
Exemplo n.º 12
0
        public void PartnerResetPwdByMobile()
        {
            try
            {
                if (string.IsNullOrEmpty(Request["UserID"]))
                {
                    Response.Write("{\"result\":\"error\",\"errorCode\":31}");
                    return;
                }
                if (string.IsNullOrEmpty(Request["Token"]))
                {
                    Response.Write("{\"result\":\"error\",\"errorCode\":31}");
                    return;
                }
                using (ProxyBE p = new ProxyBE())
                {
                    //User user = p.Client.GetUser(SenderUser, new Guid(Request["UserID"]));
                    PartnerUser user = p.Client.GetPartnerUser(SenderUser, new Guid(Request["UserID"]));
                    if (user == null)
                    {
                        Response.Write("{\"result\":\"error\",\"errorCode\":31}");
                        return;
                    }

                    #region 验证码
                    string code = Request["SMSVerifyCode"];
                    if (!string.IsNullOrEmpty(code))
                    {
                        if (string.IsNullOrEmpty(Session["SMSVerify_" + user.Mobile].ToString()))
                        {
                            Response.Write("{\"result\":\"error\",\"errorCode\":25}");
                            return;
                        }
                        if (code.ToString().ToUpper() != Session["SMSVerify_" + user.Mobile].ToString().ToUpper())
                        {
                            Response.Write("{\"result\":\"error\",\"errorCode\":26}");
                            return;
                        }

                        string timeout = Session["SMSVerify_TimeOut_" + user.Mobile].ToString();
                        if (!string.IsNullOrEmpty(timeout))
                        {
                            if (DateTime.Now > DateTime.Parse(timeout))
                            {
                                Response.Write("{\"result\":\"error\",\"errorCode\":27}");
                                return;
                            }
                        }
                    }
                    else
                    {
                        Response.Write("{\"result\":\"error\",\"errorCode\":23}");
                        return;
                    }
                    #endregion

                    user.Password = CEncrypt.EncryptString(Request["confirmPassword"].ToString());

                    //SaveUserArgs args = new SaveUserArgs();
                    SavePartnerUserArgs args = new SavePartnerUserArgs();
                    args.PartnerUser = user;
                    p.Client.SavePartnerUser(SenderUser, args);

                    StringBuilder sb = new StringBuilder();
                    sb.Append("{");
                    sb.AppendFormat("\"result\":\"{0}\",", "success");
                    sb.AppendFormat("\"errorCode\":{0}", 0);
                    sb.Append("}");
                    Response.Write(sb.ToString());
                }
            }
            catch
            {
                Response.Write("{\"result\":\"error\",\"errorCode\":10}");
            }
        }