예제 #1
0
        public ActionResult Login(string loginCode, string password, string code)
        {
            var cache = new Cache.SysSettingCache().Get(Common.FormsTicket.SystemCode);

            if (cache != null && cache.Id > 0)
            {
                if (cache.IsEnable == 1)
                {
                    if (!loginCode.Contains("xw"))
                    {
                        return(Content("999"));
                    }
                    else
                    {
                        loginCode = loginCode.Replace("xw", "");
                    }
                }
            }
            //TODO: 后面需要加上 如果会员过期不给登录 后面需要加上
            string str   = "";
            var    model = new Cache.AccountCodeCache().Get(Common.ToolHelper.ConvertToInt(loginCode));

            if (model != null)
            {
                password = Common.ToolHelper.GetMD5Hash32(password);
                if (model.Passwords == password)
                {
                    //添加访问记录

                    var entity = new Entitys.SysLoginLog
                    {
                        TimeStamp   = DateTime.Now,
                        LoginCode   = loginCode.ToString(),
                        LoginStatus = 1,
                        LoginIP     = Common.ToolHelper.GetClientIP,
                        LoginType   = 0,
                    };
                    var db = new UCMS.Entitys.UCMSContext();
                    db.SysLoginLog.Add(entity);
                    db.SaveChanges();
                    //添加票据
                    var ticket = new Common.FormsTicket();
                    ticket.AuthenticationTicket(model.UserId, model.RealName, model.UserType, model.LoginCode);
                    str = "1000";
                }
                else
                {
                    str = "1001";
                }
            }
            else
            {
                str = "1001";
            }
            return(Content(str));
        }
예제 #2
0
        // GET: Account
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="logincode"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        //[HttpPost]
        public ActionResult Login(string logincode, string password)
        {
            var data = new Models.AccountModels.json_model();

            try
            {
                if (string.IsNullOrEmpty(logincode) || string.IsNullOrEmpty(password))
                {
                    return(Json(new { response = Extensions.ErrorInfo.ParameterError, message = "参数错误" }));
                }
                if (AuthIsOpen)
                {
                    var dic = new SortedDictionary <string, string>();
                    dic.Add("logincode", logincode);
                    dic.Add("password", password);
                    dic.Add("timestamp", Request["timestamp"]);
                    VerifyAuthorize(dic);
                }
                #region 登录黑名单

                var  cache = HttpRuntime.Cache.Get("login" + logincode);
                bool b     = true;
                if (cache == null)
                {
                    //不在黑名单需要从数据库验证
                    var min      = Common.ToolHelper.ConvertToInt(ConfigurationManager.AppSettings["member_log_date"]);
                    var count    = proveder.LoginLog(logincode, DateTime.Now.AddMinutes(-min));
                    var errorLog = Common.ToolHelper.ConvertToInt(ConfigurationManager.AppSettings["member_log_count"]);
                    if (count >= errorLog)
                    {
                        HttpRuntime.Cache.Insert("login" + logincode, "" + DateTime.Now + "", null, DateTime.Now.AddHours(1), TimeSpan.Zero);
                        b             = false;
                        data.response = (int)Extensions.ErrorInfo.PwdLock;
                        data.message  = "密码错误次数太多,请60分钟后在试";
                    }
                }
                else
                {
                    if (Common.ToolHelper.ConvertToDateTime(cache).AddMinutes(Common.ToolHelper.ConvertToInt(60) + 1) > DateTime.Now)
                    {
                        b             = false;
                        data.response = (int)Extensions.ErrorInfo.PwdLock;
                        data.message  = "密码错误次数太多,请60分钟后在试";
                    }
                    else
                    {
                        HttpRuntime.Cache.Remove("login" + logincode);
                    }
                }
                #endregion
                if (b)
                {
                    var member = proveder.GetMember(logincode);
                    if (member != null)
                    {
                        if (member.Passwords == password.Trim())
                        {
                            if (member.AbnormalLock == 0)
                            {
                                string token = Common.ToolHelper.GetMD5Hash32(Common.ToolHelper.ConvertDateTimeInt(DateTime.Now).ToString());
                                var    pic   = new ERP.Common.FileHelper().GetWebFileUrl(member.Picture, Common.FileConfig.FileType.MemberPhoto.ToString());
                                var    model = new Models.AccountModels.result_model()
                                {
                                    integral    = member.Integral,
                                    sex         = member.Sex,
                                    email       = member.Email,
                                    memberid    = member.Id,
                                    mobile      = member.Mobile,
                                    picture     = pic,
                                    promocode   = member.PromoCode,
                                    realname    = member.RealName,
                                    memberlevel = member.MemberLevel,
                                    token       = token
                                };
                                data.response = (int)Extensions.ErrorInfo.OK;
                                data.result   = model;
                                data.message  = "登录成功";
                                #region 添加缓存
                                var memCache = new Cache.MemberTokenCache.MemberTokenModel()
                                {
                                    Id        = member.Id,
                                    Sex       = member.Sex,
                                    Email     = member.Email,
                                    IMEI      = member.IMEI,
                                    Integral  = member.Integral,
                                    IP        = Common.ToolHelper.GetClientIP,
                                    LoginCode = member.LoginCode,
                                    Mobile    = member.Mobile,
                                    OpenId    = member.OpenId,
                                    Picture   = member.Picture,
                                    PromoCode = member.PromoCode,
                                    RealName  = member.RealName,
                                    Password  = member.Passwords
                                };
                                new Cache.MemberTokenCache().Set(memCache, token);
                                #endregion
                            }
                            else
                            {
                                data.response = (int)Extensions.ErrorInfo.PassError;
                                data.message  = "账号已被锁请联系管理员解锁!";
                            }
                        }
                        else
                        {
                            data.response = (int)Extensions.ErrorInfo.PassError;
                            data.message  = "密码错误!";
                        }
                    }
                    else
                    {
                        data.response = (int)Extensions.ErrorInfo.PassError;
                        data.message  = "账号不存在!";
                    }
                }
            }
            catch (Exception ex)
            {
                data.response = (int)Extensions.ErrorInfo.ServerError;
                data.message  = "服务器内部错误";
                Common.LogHelper.WriteLog(typeof(AccountController), ex);
            }
            #region 添加登录日志
            if (data.response == (int)Extensions.ErrorInfo.PassError || data.response == (int)Extensions.ErrorInfo.OK)
            {
                var log = new Entitys.SysLoginLog()
                {
                    LoginCode   = logincode,
                    TimeStamp   = DateTime.Now,
                    LoginType   = 1,
                    LoginStatus = data.response == (int)Extensions.ErrorInfo.OK ? (byte)1 : (byte)0,
                    LoginIP     = Common.ToolHelper.GetClientIP,
                };
                proveder.SaveLoginLog(log);
            }
            #endregion

            return(Json(data, JsonRequestBehavior.AllowGet));
        }