Exemplo n.º 1
0
        /// <summary>
        /// 处理登陆
        /// </summary>
        /// <param name="context">HttpContext</param>
        /// <param name="action">请求动作</param>
        /// 时间:2016-05-10 17:28
        /// 备注:
        private void HanlderLogin(HttpContext context, string action)
        {
            if (string.Compare(action, "login", true) == 0)
            {
                string _userName     = context.Request["userName"],
                       _userPassword = context.Request["userPassword"],
                       _verifyCode   = context.Request["verifyCode"];
                if (CheckedVerifyCode(context, _verifyCode))
                {
                    try
                    {
                        Base_UserInfo userinfo = new Base_UserInfo();
                        userinfo.User_Name = _userName;
                        userinfo.User_Pwd  = _userPassword;
                        FormsPrincipal <Base_UserInfo> .SignIn(_userName, userinfo);

                        context.CreateResponse("登陆成功.", HttpStatusCode.OK);
                    }
                    catch (Exception ex)
                    {
                        HanlderErrorRequest(context, ex, "登陆失败,请稍后重试。");
                    }
                }
            }
        }
Exemplo n.º 2
0
        public bool Login(string adminName, string password)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("AdminName", adminName);
            dic.Add("Password", password);
            dic.Add("Status", (1).ToString());
            Administrator admin = adminBLL.Get(dic);

            if (admin == null)
            {
                return(false);
            }
            else
            {
                //设置cookie信息
                CookiesModel ck = new CookiesModel
                {
                    AdminId   = admin.AdminId,
                    AdminName = admin.AdminName,
                    GroupId   = admin.GroupId
                };
                FormsPrincipal <CookiesModel> .SignIn(ck.AdminName, ck, 0);

                return(true);
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            UserInfo userinfo = new UserInfo();

            userinfo.UserName = "******";
            userinfo.UserId   = 1;
            userinfo.GroupId  = 1;
            FormsPrincipal <UserInfo> .SignIn("yanzhiwei", userinfo, 1);

            FormsPrincipal <UserInfo> .RedirectDefaultPage("yanzhiwei");
        }
Exemplo n.º 4
0
        private void LoginOper(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            string userName = context.Request["userName"].ToString();
            string password = context.Request["password"].ToString();
            string strWhere = " and StaffName='" + userName + "' ";

            StaffsBLL bll   = new StaffsBLL();
            Staffs    model = bll.GetModel(strWhere);

            if (model != null)
            {
                if (model.UserPwd == password)
                {
                    FormsPrincipal.SignIn(model.UserName, model, 30);
                    LogHelper.Info(this.GetType(), model.UserName + "登录");

                    context.Response.Write(JsonConvert.SerializeObject(new
                    {
                        success = 0,
                        result  = "登录成功!"
                    }));
                }
                else
                {
                    context.Response.Write(JsonConvert.SerializeObject(new
                    {
                        success = 1,
                        result  = "密码输入不正确!"
                    }));
                }
            }
            else
            {
                context.Response.Write(JsonConvert.SerializeObject(new
                {
                    success = 2,
                    result  = "用户不存在!"
                }));
            }
            context.Response.End();
        }
Exemplo n.º 5
0
        /// <summary>
        /// 用户认证
        /// </summary>
        private void AjaxLogin(HttpContext context, string xname, string xpassword)
        {
            //var msg = new StringBuilder();
            var ip        = SingleQuery.Instance.Find(IpHelper.ClientIp);
            var ipAddress = string.Format("{0} {1}", new object[] { ip.Country, ip.Area });

            try
            {
                //msg.Append("000、======================>");
                var server = new AccountService();
                //msg.Append("001、======================>" + xpassword); ;
                //var password = EncryptUtil.Encrypt(xpassword);
                //msg.Append("002、======================>"+password);
                var accountNumber = xname.Trim();
                var account       = server.Where
                                        (p => (p.account_number == accountNumber || p.account_name == accountNumber) &&
                                        p.account_password == xpassword && p.deleteflag == 0)
                                    .FirstOrDefault();
                //msg.Append("1、读用户信息");

                if (account != null)
                {
                    // msg.Append("2、用户信息验证通过");
                    if (!account.account_flag.Equals(1))
                    {
                        _response = "{\"result\" :\"" + 0 + "\",\"returnval\" :\"" + "请所提供的帐号已被管理员禁用,请联系管理员。" + "\"}";
                        return;
                    }

                    //执行用户登录操作
                    int urlPort = context.Request.Url.Port;
                    //执行用户登录操作
                    FormsPrincipal <base_account> .SignIn(accountNumber,                                         //
                                                          new LoginUser(account.id,                              //
                                                                        account.account_name,                    //
                                                                        account.account_number,                  //
                                                                        account.account_number,                  //
                                                                        Convert.ToInt32(account.account_org_id), //
                                                                        Convert.ToInt32(account.FCompanyId),     //
                                                                        account.account_role_id,                 //
                                                                        urlPort),                                //
                                                          99999);

                    //最后一次登录时间
                    account.account_last_date = DateTime.Now;
                    account.account_ip        = IpHelper.ClientIp;
                    account.account_ip_addres = ipAddress;
                    server.SaveChanges();

                    //  msg.Append("3、记录用户本次登录信息");

                    var name = string.Format("{0}->{1}({2})", account.base_orgnization.org_name, //
                                             account.account_name, account.account_number);

                    //记录用户登录系统日志
                    var loginService = new LoginSevice();
                    var login        = new t_logins
                    {
                        account_name    = name,
                        account_ip      = IpHelper.ClientIp,
                        account_address = ipAddress,
                        account_id      = CurrentUser.Id,
                        action_on       = DateTime.Now,
                        action_desc     = "用户登录成功。"
                    };

                    loginService.Add(login);
                    //msg.Append("4、日志记录完毕");


                    //  msg.Append("5、调用友接口开始");
                    //接口
                    T6Account.Receiver    = "U8";
                    T6Account.Dynamicdate = DateTime.Now.ToString("MM/dd/yyyy");
                    T6Account.Sender      = "008";

                    // msg.Append("6、登录完成");
                    //context.Response.Redirect(FormsAuthentication.DefaultUrl);
                    _response = "{\"result\" :\"" + 1 + "\",\"returnval\" :\"" + "登录成功,正在转到主页..." + "\"}";
                }
                else
                {
                    _response = "{\"result\" :\"" + 0 + "\",\"returnval\" :\"" + "您所提供的用户名或者密码不正确,请联系管理员。" + "\"}";
                }
            }
            catch (Exception ex)
            {
                _response = "{\"result\" :\"" + 0 + "\",\"returnval\" :\"" + ex.Message + "\"}";//ex.Message
            }
        }
Exemplo n.º 6
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string code     = Request.Form["email"];
            string password = Request.Form["password"];

            if (string.IsNullOrEmpty(code) || string.IsNullOrEmpty(password))
            {
                Response.Write("<script>alert('请填写完整信息!');</script>");
                return;
            }

            //var userService = IoC.Resolve<ISysUserService>();
            //var userInfo = userService.GetAm(code, password);
            //if (userInfo == null || userInfo.UserType != Ytg.BasicModel.UserType.Manager)
            //{
            //    Response.Write("<script>alert('登录名不存在或密码错误!');</script>");
            //    return;
            //}

            var sysAccountService = IoC.Resolve <ISysAccountService>();

            var userInfo = sysAccountService.Login(code, password);

            if (userInfo == null)
            {
                Response.Write("<script>alert('登录名不存在或密码错误!');</script>");
                return;
            }
            else if (userInfo.IsEnabled == false)
            {
                Response.Write("<script>alert('当前账号已停用!');</script>");
                return;
            }
            else
            {
                //记录登录日志
                var sysAccountLogsService = IoC.Resolve <ISysAccountLogsService>();
                sysAccountLogsService.Create(new SysAccountLog()
                {
                    UserId       = userInfo.Id,
                    OccDate      = DateTime.Now,
                    Ip           = Ytg.Comm.Utils.GetIp(),
                    ServerSystem = Ytg.Comm.Utils.GetUserSystem(),
                    //   Descript = Utils.GetCityByIp(Ytg.Comm.Utils.GetIp())
                });
                sysAccountLogsService.Save();
            }

            string preLoginIp   = userInfo.LastLoginIp;
            string preLoginTime = userInfo.LastLoginTime != null?userInfo.LastLoginTime.Value.ToString("yyyy/MM/dd HH:mm:ss") : "";

            string curLoginIp = Utils.GetIp();//当前登录的Ip

            //修改登录IP和时间
            userInfo.PreLoginIp    = userInfo.LastLoginIp;
            userInfo.PreLoginTime  = userInfo.LastLoginTime;
            userInfo.LastLoginIp   = Utils.GetIp();
            userInfo.LastLoginTime = DateTime.Now;
            sysAccountService.Save();//保存信息

            //登录成功
            CookUserInfo cokUserInfo = new CookUserInfo()
            {
                Id       = userInfo.Id,
                Code     = userInfo.Code,
                NikeName = curLoginIp + "," + preLoginIp,
                Sex      = preLoginTime
            };

            FormsPrincipal <CookUserInfo> .SignIn(userInfo.Code, cokUserInfo, FormsAuthentication.Timeout.Minutes);

            //跳转至index.aspx
            Response.Redirect("/index.html");
        }
        //玩家登陆
        private void Login(bool isfig = true)
        {
            var isLock = this.mLockIpInfoService.IsLockIp(Utils.GetIp());

            if (isLock)
            {
                //获取跳转地址
                AppGlobal.RenderResult(ApiCode.DisabledIp, this.GetRefDns());
                return;
            }

            //登陆名
            string loginCode = Request.Params["M_LOGINCODE"];
            //登陆密码
            string pwd = Request.Params["M_LOGINPWD"];
            //验证码
            string code = Request.Params["M_LOGINVIDACODE"];

            if (string.IsNullOrEmpty(loginCode) || string.IsNullOrEmpty(pwd))
            {
                AppGlobal.RenderResult(ApiCode.ParamEmpty);
                return;
            }
            if (string.IsNullOrEmpty(code) && isfig)
            {
                AppGlobal.RenderResult(ApiCode.ParamEmpty);
                return;
            }


            var item = this.mSysUserService.Get(loginCode, pwd);

            if (null == item)
            {
                AppGlobal.RenderResult(ApiCode.ValidationFails);
                return;
            }
            if (item.IsDelete)
            {
                AppGlobal.RenderResult(ApiCode.DisabledCode, this.GetRefDns());
                return;
            }


            string       sessionid = Guid.NewGuid().ToString();
            CookUserInfo info      = new CookUserInfo();

            info.Id         = item.Id;
            info.Code       = item.Code;
            info.NikeName   = item.NikeName;
            info.Sex        = sessionid;
            info.Head       = item.Head;
            info.Rebate     = item.Rebate;
            info.UserType   = item.UserType;
            info.IsRecharge = item.IsRecharge;
            info.PlayType   = item.PlayType;
            info.ProxyLevel = item.ProxyLevel;

            FormsPrincipal <CookUserInfo> .SignIn(loginCode, info, FormsAuthentication.Timeout.Minutes);

            //Ytg.ServerWeb.BootStrapper.SessionManager.AddOrUpdateSession(item.Id,new YtgSession()
            //{
            //    UserId = item.Id,
            //    SessionId = sessionid,
            //    OccDate = DateTime.Now,
            //    Code = item.Code
            //});


            string loginIpAddress = Ytg.Comm.Utils.GetIp();
            int    state          = this.mSysUserSessionService.UpdateInsertUserSession(new UserSession()
            {
                UserId      = item.Id,
                SessionId   = sessionid,
                LoginIp     = loginIpAddress,
                LoginClient = Ytg.Comm.Utils.GetLoginClientType(),
            });
            string loginCityName = "";//Utils.GetCityByIp(item.LastLoginIp);//获取所在城市
            string useSource     = System.Web.HttpContext.Current.Request.Params["usesource"];
            //判断是否为移动设备访问
            bool isMobile = Utils.IsMobile();

            if (isMobile)
            {
                useSource = "移动设备";
            }

            /**记录日志*/
            SysLog log = new SysLog()
            {
                Descript      = loginCityName,
                Ip            = loginIpAddress,
                OccDate       = DateTime.Now,
                ReferenceCode = info.Code,
                ServerSystem  = Ytg.Comm.Utils.GetUserSystem(),
                Type          = 0,
                UserId        = info.Id,
                UseSource     = useSource
            };

            /**记录日志 end*/

            //修改用户登录时间
            item.LastLoginTime = DateTime.Now;
            item.LastLoginIp   = loginIpAddress;
            item.IsLogin       = true;
            item.IsLineLogin   = true;
            item.LastCityName  = log.Descript;
            item.ServerSystem  = log.ServerSystem;
            item.UseSource     = log.UseSource;
            item.LoginCount++;//登录次数增加
            this.mSysUserService.Save();
            //单点登录
            // DanDianLogin(info.Id.ToString());

            //输出结果
            AppGlobal.RenderResult <CookUserInfo>(ApiCode.Success, info);
            //添加登录日志
            Ytg.Service.Logic.LogHelper.AddLog(log);
        }