Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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
        }