Пример #1
0
        public void Can_Deserialize_From_Root_Element()
        {
            string           doc  = File.ReadAllText(Path.Combine(currentPath, "SampleData", "sojson.txt"));
            JsonDeserializer json = new JsonDeserializer {
                RootElement = "User"
            };
            SoUser output = json.Deserialize <SoUser>(new RestResponse {
                Content = doc
            });

            Assert.AreEqual("John Sheehan", output.DisplayName);
        }
Пример #2
0
        public void Can_Deserialize_Names_With_Underscore_Prefix()
        {
            string       data     = File.ReadAllText(Path.Combine(currentPath, "SampleData", "underscore_prefix.txt"));
            RestResponse response = new RestResponse {
                Content = data
            };
            JsonDeserializer json = new JsonDeserializer {
                RootElement = "User"
            };
            SoUser output = json.Deserialize <SoUser>(response);

            Assert.AreEqual("John Sheehan", output.DisplayName);
            Assert.AreEqual(1786, output.Id);
        }
Пример #3
0
        public static string GetLicense(int associateId, List <string> options)
        {
            SoUser soUser = SoUser.ManageUser(associateId);
            List <AssociateModuleLicenseLink> license = soUser.GetModuleLicenses().ToList();
            string result = "";

            foreach (var item in license)
            {
                if (options.Contains(item.License.ModuleName))
                {
                    result += item.License.ModuleDescription;
                }
            }
            return(result);
        }
Пример #4
0
        /// <summary>
        /// 判断用户登录角色
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="rememberPassWordFlag">记住密码标识</param>
        /// <param name="rturl">返回路径</param>
        /// <param name="ip"></param>
        /// <param name="SpecialUrl">特殊的Url 供店铺装修使用</param>
        /// <returns></returns>
        public Base CheckAndLogin(string username, string password, string ip, bool rememberPassWordFlag, out SoUser soUser)
        {
            soUser = new SoUser();

            Base   b = new Base();
            ExUser ex;

            string msg = string.Empty;

            #region 用户登录
            try
            {
                using (var db = new EFContext())
                {
                    var f = db.selmanager.FirstOrDefault(x => x.IsDel == 0 && x.IsLock == 0 && x.LoginName.ToLower() == username && x.LoginPwd.ToLower() == password);

                    if (f != null)
                    {
                        var shop = db.selshop.FirstOrDefault(x => x.ID == f.ShopID);
                        #region addcookie
                        SoUser sm = new SoUser();
                        sm.UserName      = f.LoginName;
                        sm.NickName      = f.NickName;
                        sm.ManagerId     = f.ID;
                        sm.ShopId        = f.ShopID;
                        sm.IsOwner       = f.IsOwner;
                        sm.ShopName      = shop.ShopName;
                        sm.UserLoginType = (int)UserLoginType.UserSelf;
                        sm.IP            = ip;
                        bool flag = SoLogin.Login(sm);
                        #endregion

                        #region 处理登录成功结果
                        if (flag)
                        {
                            b.Code    = 1;
                            b.Message = "登录成功!";
                            soUser    = sm;
                            return(b);
                        }
                        else
                        {
                            b.Code    = 0;
                            b.Message = "登录失败!";
                            soUser    = sm;
                            return(b);
                        }
                        #endregion
                    }
                    else
                    {
                        b.Code    = 0;
                        b.Message = "登录失败!";
                    }
                }
            }
            catch (Exception Exc)
            {
                b.Code    = 0;
                b.Message = "登录异常";
            }
            #endregion

            return(b);
        }
Пример #5
0
        private bool updateUser(string associateId, string firstname, string lastname, string fullname, string username, string email, string role, string group, string license, DataGridViewRow item)
        {
            bool result = false;

            try
            {
                SoUser user = SoUser.ManageUser(Convert.ToInt32(associateId));
                SuperOffice.CRM.Entities.Person p = user.Person;
                p.Firstname = firstname;
                p.Lastname  = lastname;
                //p.PersonNumber = username;
                String   pwd = username;
                EmailRow em  = null;
                if (p.Emails.Count == 0)
                {
                    em = p.Emails.AddNew();
                    em.SetDefaults();
                }
                else
                {
                    em = p.Emails[0];
                }

                // always set correct email; we have just the one address
                em.EmailAddress = email;
                em.Protocol     = "SMTP";

                // save complete person entity
                p.Save();
                //Console.WriteLine("\tPerson/email done");

                // set our various properties
                user.SetPassword(pwd);
                user.GroupIdx      = _groups[group];
                user.OtherGroupIds = new int[0];

                user.RoleIdx   = _roles[role];
                user.LogonName = username;
                user.Tooltip   = fullname + " (" + SoSystemInfo.GetCurrent().CompanyName + ")";

                // add licenses
                if (user.GetModuleLicense("SuperOffice", DefaultLicense).CanAssign)
                {
                    user.GetModuleLicense("SuperOffice", DefaultLicense).Assigned = true;
                    item.Cells["AssignedLicenses"].Value = "Assigned Default";
                }
                else
                {
                    item.Cells["AssignedLicenses"].Value = "Cannot Assign";
                }
                //user.GetModuleLicense(SoLicenseNames.SuperLicenseServicePro).Assigned = true;

                /*user.GetModuleLicense(SoLicenseNames.User).Assigned = true;
                 * user.GetModuleLicense(SoLicenseNames.Web).Assigned = true;*/
                user.GetModuleLicense(SoLicenseNames.VisibleFor).Assigned = true;

                // save the user
                user.Save();
                //Console.WriteLine("\tUser saved\n");
                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return(result);
        }
Пример #6
0
        private bool createUser(string firstname, string lastname, string fullname, string username, string email, string role, string group, string company, string license, DataGridViewRow item)
        {
            bool result = false;

            try
            {
                // find person by firstname, lastname & owner contact
                SuperOffice.CRM.Entities.Person.CustomSearch pc = new SuperOffice.CRM.Entities.Person.CustomSearch();
                pc.Restriction = pc.TableInfo.Firstname.Equal(S.Parameter(firstname)).
                                 And(pc.TableInfo.Lastname.Equal(S.Parameter(lastname))).
                                 And(pc.TableInfo.ContactId.Equal(S.Parameter(_contacts[company])));

                SuperOffice.CRM.Entities.Person p = SuperOffice.CRM.Entities.Person.GetFromCustomSearch(pc);

                // we either found an existing person, or got a blank, ready-to-populate one
                if (p.IsNew)
                {
                    p.SetDefaults(_contacts[company]);

                    p.Firstname = firstname;
                    p.Lastname  = lastname;
                }

                // always set userid into number field, for convenience
                p.PersonNumber = username;

                // find existing email, or create a new one
                EmailRow em = null;
                if (p.Emails.Count == 0)
                {
                    em = p.Emails.AddNew();
                    em.SetDefaults();
                }
                else
                {
                    em = p.Emails[0];
                }

                // always set correct email; we have just the one address
                em.EmailAddress = email;
                em.Protocol     = "SMTP";

                // save complete person entity
                p.Save();

                // if person is associate - get him/her; otherwise create a new SoUser
                SoUser user;
                if (AssociateCache.GetCurrent().IsPersonAssociate(p.PersonId))
                {
                    user = SoUser.ManageUserFromPersonId(p.PersonId)[0];
                }
                else
                {
                    user = SoUser.CreateNew(p.PersonId, UserType.InternalAssociate);
                }

                // set our various properties
                user.SetPassword(username);
                user.GroupIdx      = _groups[group];
                user.OtherGroupIds = new int[0];

                user.RoleIdx   = _roles[role];
                user.LogonName = username;
                user.Tooltip   = fullname + " (" + company + ")";

                // add licenses
                if (user.GetModuleLicense("SuperOffice", DefaultLicense).CanAssign)
                {
                    user.GetModuleLicense("SuperOffice", DefaultLicense).Assigned = true;
                    item.Cells["AssignedLicenses"].Value = "Assigned Default";
                }
                else
                {
                    item.Cells["AssignedLicenses"].Value = "Cannot Assign";
                }
                //user.GetModuleLicense(SoLicenseNames.SuperLicenseServicePro).Assigned = true;

                /*user.GetModuleLicense(SoLicenseNames.User).Assigned = true;
                 * user.GetModuleLicense(SoLicenseNames.Web).Assigned = true;*/
                user.GetModuleLicense(SoLicenseNames.VisibleFor).Assigned = true;

                // save the user
                user.Save();
                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return(result);
        }
Пример #7
0
        public JsonResult UserLogin()
        {
            #region field

            var iLog = log4net.LogManager.GetLogger("LogToTXT");

            //仿照sso添加登录信息模型
            ViewUserLogin model = new ViewUserLogin();
            string        msg   = string.Empty;
            bool          flag  = false;

            var userName = Request.Form["txtUserName"];
            var passWord = Request.Form["txtPassWord"];
            var vailCode = Request.Form["txtVailCode"];
            var chkFlag  = Request.Form["chkReMember"];
            var url      = Request.Form["url"];

            string ip = SM.Current.IPManager.GetIP();
            #endregion

            #region Login

            try
            {
                #region 验证信息
                if (string.IsNullOrEmpty(userName))
                {
                    msg  = "请输入用户名";
                    flag = true;
                }
                if (string.IsNullOrEmpty(passWord))
                {
                    msg  = "请输入密码";
                    flag = true;
                }
                if (string.IsNullOrEmpty(vailCode))
                {
                    msg  = "请输入验证码";
                    flag = true;
                }
                if (Session["ValidateCode"] == null || vailCode != Session["ValidateCode"].ToString())
                {
                    msg  = "验证码输入错误";
                    flag = true;
                }
                if (!string.IsNullOrEmpty(url))
                {
                    url = SOLib.SoLogin.Decrypt(url);
                }

                if (flag)
                {
                    ViewBag.Msg      = msg;
                    ViewBag.UserName = userName;

                    model.Code    = 0;
                    model.Message = msg;

                    return(Json(model));
                }
                #endregion

                #region 验证IP

                if (Manager.Current.UserLoginManager.AuthencationUser(ip))
                {
                    ViewBag.Msg      = "您登陆失败超过30次,今天无法登陆,请联系管理员";
                    ViewBag.UserName = userName;

                    //返回结果
                    model.Code    = 0;
                    model.Message = "您已经登陆失败超过30次,今天已经无法在重新登陆,请联系管理员";
                    model.Url     = url;

                    return(Json((model)));
                }
                #endregion



                #region 验证登录


                passWord = MD5.GetMD5(passWord, "");

                var rememberPassWordFlag = !string.IsNullOrEmpty(chkFlag);

                SoUser soUser = null;
                var    b      = Manager.Current.UserLoginManager.CheckAndLogin(userName.Trim(), passWord.Trim(), ip, rememberPassWordFlag, out soUser);
                #endregion

                #region 此处处理用户登录成功之后Url跳转


                //用户登录成功之后跳转到网站首页 增加网站首页联盟广告的刷新量
                if (string.IsNullOrEmpty(url))
                {
                    url = ConfigHelper.GetHomeUrl;
                }

                if (b.Code == 1)
                {
                    model.Code     = 1;
                    model.Message  = b.Message;
                    model.Url      = url;
                    model.UserName = soUser.UserName;

                    return(Json(model));
                }
                else
                {
                    ViewBag.UserName = userName;
                    ViewBag.Msg      = b.Message;

                    model.Code     = 0;
                    model.Message  = b.Message;
                    model.Url      = url;
                    model.UserName = soUser.UserName;

                    return(Json(model));
                }

                #endregion
            }
            catch (Exception Exc)
            {
                model.Code    = 0;
                model.Message = "登录错误!";
                model.Url     = url;

                return(Json(model));
            }
            #endregion
        }
Пример #8
0
        public JsonResult UserReg(FormCollection form)
        {
            #region field
            ViewUserReg b = new ViewUserReg();

            DateTime dt1 = DateTime.Now;

            var iLog = log4net.LogManager.GetLogger("LogToTXT");

            //仿照sso添加登录信息模型
            string msg          = string.Empty;
            bool   flag         = false;
            string tg           = form.Get("tg");
            string userName     = form.Get("userName");
            string password     = form.Get("password");
            string cpassword    = form.Get("cpassword");
            string email        = form.Get("email");
            string phone        = form.Get("phone");
            string validatecode = form.Get("validatecode");
            string validateid   = form.Get("validateid");
            #endregion

            #region 开始验证

            #region 判断用户密码是否为空
            if (string.IsNullOrEmpty(validateid))
            {
                flag = true;
                msg  = string.Format("验证码不能为空!");
            }

            if (string.IsNullOrEmpty(validatecode))
            {
                flag = true;
                msg  = string.Format("验证码不能为空!");
            }

            if (password != cpassword)
            {
                flag = true;
                msg  = string.Format("两次输入的密码不相同!");
            }

            if (string.IsNullOrEmpty(cpassword))
            {
                flag = true;
                msg  = string.Format("确认密码不能为空!");
            }

            if (string.IsNullOrEmpty(password))
            {
                flag = true;
                msg  = string.Format("密码不能为空!");
            }

            if (string.IsNullOrEmpty(email))
            {
                flag = true;
                msg  = string.Format("邮箱不能为空!");
            }
            if (string.IsNullOrEmpty(userName))
            {
                flag = true;
                msg  = string.Format("用户名不能为空!");
            }
            #endregion

            #region 开始校验
            if (Session["ValidateCode"] == null || validatecode != Session["ValidateCode"].ToString())
            {
                flag = true;
                msg  = string.Format("验证码输入不正确!");
            }
            if (Session["ValidateId"] == null || validateid != Session["ValidateId"].ToString())
            {
                flag = true;
                msg  = string.Format("验证码输入不正确!");
            }
            if (Session["Email"] == null || email != Session["Email"].ToString())
            {
                flag = true;
                msg  = string.Format("验证码输入不正确!");
            }
            #endregion


            #region 开始判断
            if (flag)
            {
                ViewBag.Email    = email;
                ViewBag.UserName = userName;
                ViewBag.Phone    = phone;

                b.Code    = 0;
                b.Message = msg;
                return(Json(b));
            }

            var bbb = RegexHelper.CheckPassword(password);
            if (bbb.Code == 0)
            {
                b.Code    = 0;
                b.Message = bbb.Message;
                return(Json(b));
            }

            var bbbb = RegexHelper.CheckUserName(userName);
            if (bbbb.Code == 0)
            {
                b.Code    = 0;
                b.Message = bbbb.Message;
                return(Json(b));
            }
            #endregion

            #endregion

            #region 用户注册
            try
            {
                #region httpclient

                var apiUrl = ConfigHelper.GetApiUrl;
                var url    = string.Format(apiUrl + "/api/so/postRegister");

                using (var http = new HttpClient())
                {
                    var content = new FormUrlEncodedContent(new Dictionary <string, string>()
                    {
                        { "safecode", SafeCodeHelper.GetSafeCode },
                        { "username", userName },
                        { "password", password },
                        { "email", email },
                        { "tg", tg }
                    });

                    var response = http.PostAsync(url, content).Result;
                    if (response.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        NewBase <ExRegUser> bb = JsonConvert.DeserializeObject <NewBase <ExRegUser> >(response.Content.ReadAsStringAsync().Result);
                        if (bb.Code == 1)
                        {
                            b.Code = 1;
                            //采用服务端的返回提示
                            // b.Message = "注册成功!";
                            b.Url     = ConfigHelper.GetHomeUrl;
                            b.Message = bb.Message;

                            //清理注册Session
                            Session["ValidateCode"] = null;

                            Session["ValidateId"] = null;

                            Session["Email"] = null;

                            //登录成功之后 默认用户登录 然后跳转到用户后台
                            SoUser sm = new SoUser();
                            sm.UserName  = userName;
                            sm.NickName  = userName;
                            sm.IP        = SM.Current.IPManager.GetIP();
                            sm.ManagerId = bb.Data.UGUID;
                            bool isLogin = SoLogin.Login(sm);
                            return(Json(b));
                        }
                        else
                        {
                            b.Code = 0;
                            //采用服务端的返回提示
                            //b.Message = "注册失败!";
                            b.Message = bb.Message;
                            return(Json(b));
                        }
                    }
                    else
                    {
                        b.Code    = 0;
                        b.Message = response.ReasonPhrase;
                        return(Json(b));
                    }
                }
                #endregion
            }
            catch (Exception Exc)
            {
                b.Code    = 0;
                b.Message = "注册异常!";
                return(Json(b));
            }
            #endregion
        }