/// <summary>
        /// 添加登录日志
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="trans"></param>
        /// <returns></returns>
        public CommonResult<string> AddCyUserLoginLog(CyUserLoginLogEntity entity, IDbTransaction trans = null)
        {
            var commonResult = new CommonResult<string>();
            const string sql = @"INSERT INTO [dbo].[CyUserLoginLog]
                                       ([UserNo]
                                       ,[LoginTime]
                                       ,[LoginIp])
                                 VALUES
                                       (@UserNo
                                       ,@LoginTime
                                       ,@LoginIp)";
            if (trans == null)
            {
                using (var conn = DbHelper.CreateOpenConnection(DbConnectionStringConfig.CyMainDbConnectionStringName))
                {
                    try
                    {
                        var rows = conn.Execute(sql, entity);

                        commonResult.Success = true;
                        commonResult.Message = "执行成功";
                        commonResult.EffectRows = rows;
                    }
                    catch (Exception ex)
                    {
                        commonResult.Success = false;
                        commonResult.IsHappenEx = true;
                        commonResult.Message = "执行失败";
                        commonResult.ExMessage = ex.Message;
                        commonResult.ExData = ex;
                    }
                }
            }
            else
            {
                try
                {
                    var rows = trans.Connection.Execute(sql, entity, transaction: trans);

                    commonResult.Success = true;
                    commonResult.Message = "执行成功";
                    commonResult.EffectRows = rows;
                }
                catch (Exception ex)
                {
                    commonResult.Success = false;
                    commonResult.IsHappenEx = true;
                    commonResult.Message = "执行失败";
                    commonResult.ExMessage = ex.Message;
                    commonResult.ExData = ex;
                }
            }
            return commonResult;
        }
Beispiel #2
0
        /// <summary>
        /// 添加登录日志
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="trans"></param>
        /// <returns></returns>
        public CommonResult<string> AddCyUserLoginLog(CyUserLoginLogEntity entity, IDbTransaction trans = null)
        {
            try
            {
                return CyUserProvider.AddCyUserLoginLog(entity, trans);
            }
            catch (Exception)
            {

                throw;
            }
        }
        public JsonResult LoginIn(LoginUser loginUser)
        {
            var userResult = new CommonResult<CyUserEntity>();
            try
            {
                var user = new CyUserEntity()
                {
                    UserName = loginUser.UserName,
                    UserPwd = loginUser.UserPwd,
                    ValideCode = loginUser.ValideCode
                };

                //验证用户信息
                userResult = CyUserService.Login(user);
                //验证成功
                if (userResult.Success)
                {
                    var cyUser = userResult.ResultObj;
                    var model = new UserModel()
                    {
                        UserNo = cyUser.UserNo,
                        UserName = cyUser.UserName,
                        NickName = cyUser.NickName,
                        TrueName = cyUser.TrueName,
                        MemberType = cyUser.MemberType,
                        Role = cyUser.Role
                    };
                    UserContext.SetAuthCookie(model, true);
                    var loginLog = new CyUserLoginLogEntity()
                    {
                        UserNo = cyUser.UserNo,
                        LoginIp = IpHelper.GetUserIpAddress(),
                        LoginTime = DateTime.Now
                    };
                    CyUserService.AddCyUserLoginLog(loginLog);
                }
            }
            catch (Exception ex)
            {
                userResult.Success = false;
                userResult.Message = ex.Message;
            }
            return Json(userResult, JsonRequestBehavior.AllowGet);
        }