コード例 #1
0
ファイル: LoginController.cs プロジェクト: khaliyo/UCsoft
        public ActionResult DoLogin(FormCollection fc)
        {
            ResponseMessage rmsg=new ResponseMessage();
            try
            {
                //LogHelper.Info("来自" + HttpUtility.UrlDecode(fc["clientPlace"].ToString()) + "的" +
                //LogHelper.Info(fc["userName"].ToString() + "正在登录...");
                //rmsg = AccountService.Login(System.Web.HttpContext.Current, fc["type"].ToString(),
                //    fc["accountType"].ToString(), fc["userName"].ToString(), fc["userPassword"].ToString(),
                //    fc["remember"].ToString(),
                //    fc["clientIp"].ToString(), HttpUtility.UrlDecode(fc["clientPlace"].ToString()),
                //     fc["clientTime"].ToString());
            }
            catch (Exception ex)
            {
                //LogHelper.Error("登录异常," + ex.Message);
                //rmsg = new ResponseMessage() {Status = false, Msg = "登录异常,请联系管理员!"};
            }

            return Json(rmsg);
        }
コード例 #2
0
ファイル: AccountServiceImpl.cs プロジェクト: khaliyo/UCsoft
        /// <summary>
        /// 账户验证 2014/8/21 9:04:10   By 唐有炜
        /// </summary>
        /// <param name="type">注册或登录方式(normal,qrcode,usb,footprint)</param>
        /// <param name="accountType">账号类型(username,email,phone)</param>
        /// <param name="userName">用户名</param>
        /// <param name="userPassword">密码</param>
        /// <returns>ResponseMessage</returns>
        public ResponseMessage ValidateAccount(string type, string accountType, string userName,
            string userPassword = null)
        {
            ResponseMessage rmsg = new ResponseMessage();

            switch (type)
            {
                case "normal": //正常
                    //登录时账户类型不分开
                    if (UserNameExists(accountType, userName))
                    {
                        rmsg.Status = true;
                        rmsg.Msg = "用户名输入正确!";
                        //密码空时只验证用户名
                        if (String.IsNullOrEmpty(userPassword))
                        {
                            return rmsg;
                        }
                    }
                    else
                    {
                        rmsg.Status = false;
                        rmsg.Msg = "该用户名不存在!";
                        return rmsg;
                    }

                    if (UserPasswordExists(accountType, userName, userPassword))
                    {
                        rmsg.Status = true;
                        rmsg.Msg = "密码输入正确!";
                    }
                    else
                    {
                        rmsg.Status = false;
                        rmsg.Msg = "密码错误!";
                        return rmsg;
                    }

                    return rmsg;
                    break;
                default:
                    rmsg.Status = false;
                    rmsg.Msg = "该登录方式尚未开通!";
                    return rmsg;
                    break;
            }
        }
コード例 #3
0
ファイル: AccountServiceImpl.cs プロジェクト: khaliyo/UCsoft
        /// <summary>
        /// 登录验证并写入登录日志 2014-08-21 07:58:50 By 唐有炜
        /// </summary>
        /// <param name="httpContext">HttpContext</param>
        /// <param name="type">注册或登录方式(normal,qrcode,usb,footprint)</param>
        /// <param name="accountType">账号类型(username,email,phone)</param>
        /// <param name="userName">用户名</param>
        /// <param name="userPassword">密码</param>
        /// <param name="remember">记住密码</param>
        /// <param name="clientIp">客户端ip地址</param>
        ///   /// <param name="clientPlace">客户端地址</param>
        /// <param name="clientTime">客户端登录时间</param>
        /// <returns>ResponseMessage</returns>
        public ResponseMessage Login(HttpContext httpContext, string type, string accountType, string userName,
            string userPassword,
            string remember, string clientIp, string clientPlace, string clientTime)
        {
            ResponseMessage rmsg = new ResponseMessage();
            try
            {
                //账户验证
                rmsg = ValidateAccount(type, accountType, userName, userPassword);
                if (!rmsg.Status)
                {
                    return rmsg;
                }
                //判断用户是否被禁用

                //获取用户信息
                var sysUser = GetSysUserByAccountTypeAndUserLname(accountType, userName);
                if (sysUser.UserEnable != 1)
                {
                    rmsg.Status = false;
                    rmsg.Msg = "对不起,该用户已经被禁用!";
                    return rmsg;
                }

                var sysRole = TSysRoleDao.GetEntity(r => r.Id == sysUser.RoleId);
                //书写SessionCookie
                WriteSessionCookie(httpContext, sysUser, sysRole, remember);
                //写日志
                var loginUser = sysUser.UserTname;
                if (String.IsNullOrEmpty(loginUser))
                {
                    if (String.IsNullOrEmpty(clientPlace))
                    {
                        clientPlace = "未知地区";
                    }
                    loginUser = clientPlace + "网友";
                }
                TSysLog sysLog = new TSysLog()
                {
                    UserId = sysUser.Id,
                    UserLname = sysUser.UserLname,
                    LogAction = UCEnums.LogActionEnum.Login.ToString(),
                    LogRemark = String.Concat(new[] {"【", loginUser, "】,登录了系统。"}),
                    LogIp = clientIp,
                    LogPlace = clientPlace,
                    LogTime = DateTime.Parse(clientTime)
                };
                TSysLogDao.InsertEntity(sysLog);

                rmsg.Status = true;
                rmsg.Msg = "登陆成功";
                LogHelper.Info(userName + "登录成功,登录日志已记录。");
            }
            catch (Exception ex)
            {
                rmsg.Status = false;
                rmsg.Msg = "登陆失败";
                LogHelper.Debug("登陆错误", ex);
            }

            return rmsg;
        }