Ejemplo n.º 1
0
        /// <summary>
        /// 用户登录事件(异步)
        /// </summary>
        /// <param name="auth"></param>
        /// <param name="uVaildInfo"></param>
        private static async void SignInEvents(AuthResult auth, UserVaildInfo uVaildInfo)
        {
            await Task.Run(() =>
            {
                //首次登录
                if (uVaildInfo.LoginCount < 1)
                {
                    // ToDo
                }
                else
                {
                    //更换设备登录
                    if (auth.DeviceChanged)
                    {
                        // ToDo
                    }
                }

                //每日第一次登录
                if (DateTime.Now.Date.Subtract(uVaildInfo.LastLoginDate.Date).TotalDays >= 1d)
                {
                    // ToDo
                }

                //每次登录
                // ToDo
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="context">当前请求上下文应答实例</param>
        /// <param name="acount">账号信息</param>
        /// <param name="uAccount">用户账户信息</param>
        private static void UserSignIn(DataContext context, Account acount, UserAccount uAccount)
        {
            UserVaildInfo vaildInfo = UserBiz.GetUserVaildInfo(uAccount);

            string[] errMessages = new string[] { "密码错误!", "您的账号尚未通过验证!", "您的账号已被锁定,暂时无法登录!", "试用账号已过期!请更换其它账号登录!" };
            if (vaildInfo.UserId <= 0)
            {
                context.Flush(RespondCode.ShowError, errMessages[Math.Abs(vaildInfo.UserId)]);
                return;
            }

            //更新登录信息
            UserExtInfo extInfo = new UserExtInfo
            {
                UserId                  = vaildInfo.UserId,
                LastLoginDeviceId       = context.DeviceId,
                LastLoginAPPChannel     = context.ReqChannel,
                LastLoginAccountChannel = (int)acount.AccountChannel
            };

            UserBiz.UserSignIn(extInfo);

            //创建登录日志
            CreateSignInLog(context, acount, vaildInfo);

            //返回登录结果
            FlushResult(context, vaildInfo);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 获取用户验证信息
 /// </summary>
 /// <param name="userName">用户名</param>
 /// <param name="userAccess">用户对应的登录权限</param>
 /// <returns>用户验证信息</returns>
 public static UserVaildInfo GetUserVaildInfo(string userName, UserAccess userAccess)
 {
     using (DbCommander cmd = new DbCommander(DbConn.ReadDb, "SP_Users_GetUserVaildInfo", CommandType.StoredProcedure))
     {
         cmd.AddInputParameters("UserName, UserAccess", userName, userAccess);
         UserVaildInfo resultData = null;
         using (IDataReader reader = cmd.ExecuteReader())
         {
             if (reader.Read())
             {
                 resultData = new UserVaildInfo
                 {
                     UserId            = (int)reader["UserId"],
                     UserName          = (string)reader["UserName"],
                     Password          = (string)reader["Password"],
                     PasswordSalt      = (string)reader["PasswordSalt"],
                     IsApproved        = (bool)reader["IsApproved"],
                     IsLocked          = (bool)reader["IsLocked"],
                     LastLockedoutDate = (DateTime)reader["LastLockedoutDate"],
                     LoginCount        = (int)reader["LoginCount"],
                     LastLoginDate     = (DateTime)reader["LastLoginDate"],
                     UserSite          = (int)reader["UserSite"],
                     UserRole          = (int)reader["UserRole"],
                     UserAccess        = (UserAccess)(int)reader["UserAccess"],
                     LastLoginDeviceId = (int)reader["LastLoginDeviceId"]
                 };
             }
             reader.Close();
         }
         return(resultData);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取用户基本账户信息
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static UserAccount GetUserAccount(int userId)
        {
            UserCacheInfo userCache  = ReadUserCacheInfo(userId);
            UserVaildInfo uVaildInfo = UserData.GetUserVaildInfo(userCache.UserName, UserAccess.App);

            return(new UserAccount
            {
                UserId = userId,
                Password = uVaildInfo.Password,
                PasswordSalt = uVaildInfo.PasswordSalt
            });
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 创建登录日志
        /// </summary>
        /// <param name="context">当前请求上下文应答实例</param>
        /// <param name="acount">账号信息</param>
        /// <param name="uVaildInfo">用户账户信息</param>
        private static void CreateSignInLog(DataContext context, Account acount, UserVaildInfo uVaildInfo)
        {
            UserLoginLog log = new UserLoginLog
            {
                UserId         = uVaildInfo.UserId,
                LogType        = 2,
                NetworkType    = (int)acount.NetworkType,
                AccountChannel = (int)acount.AccountChannel,
                AppChannel     = context.ReqChannel,
                AppVersion     = acount.Version,
                DeviceId       = context.DeviceId,
                LoginAccount   = uVaildInfo.UserName,
                CreateDate     = DateTime.Now
            };

            LogsBiz.CreateLogs <UserLoginLog>(log);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="context">当前请求上下文应答实例</param>
        /// <param name="acount">账号信息</param>
        /// <param name="uAccount">用户账户信息</param>
        /// <param name="uInfo">用户个人信息</param>
        private static void UserSignUp(DataContext context, Account acount, UserAccount uAccount, UserInfo uInfo)
        {
            UserExtInfo extInfo = new UserExtInfo
            {
                CreateDeviceId       = context.DeviceId,
                CreateAPPChannel     = context.ReqChannel,
                CreateAccountChannel = (int)acount.AccountChannel
            };

            UserBiz.CreateUser(uAccount, uInfo, extInfo);
            //注册结果:uAccount.UserId > 0 为成功,反之为失败!
            if (uAccount.UserId > 0)
            {
                //注册成功后,更新游客账户用户名、昵称信息
                if (acount.AccountChannel == AccountChannel.Guest)
                {
                    uAccount.UserName = string.Format("{0}{1}", GuestUserNamePreFix, uAccount.UserId);
                    uInfo.NickName    = string.Format("游客{0}", Convert.ToBase64String(uAccount.UserId.GetIntOffsetBytes(), Base64FormattingOptions.None).TrimEnd('='));
                    UserBiz.UpdateGuestUserInfo(uAccount, uInfo);
                }

                //写注册日志
                CreateSignUpLog(context, acount, uAccount);

                //输出登录结果
                UserVaildInfo vaildInfo = new UserVaildInfo
                {
                    UserId            = uAccount.UserId,
                    LastLoginDeviceId = context.DeviceId,
                    LastLoginDate     = uAccount.CreateDate,
                    LoginCount        = uAccount.LoginCount
                };
                SignIn.FlushResult(context, vaildInfo);
            }
            else
            {
                context.Flush(RespondCode.ExecError);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 输出登录结果
        /// </summary>
        /// <param name="context">当前请求上下文应答实例</param>
        /// <param name="uVaildInfo">用户验证信息</param>
        internal static void FlushResult(DataContext context, UserVaildInfo uVaildInfo)
        {
            UserCacheInfo userCacheInfo = UserBiz.ReadUserCacheInfoFromDb(uVaildInfo.UserId);
            AuthResult    authResult    = new AuthResult
            {
                UserId        = uVaildInfo.UserId,
                DeviceChanged = context.DeviceId == uVaildInfo.LastLoginDeviceId,
                SessionId     = uVaildInfo.UserId.GetSessionId(),
                UserBase      = userCacheInfo.ToUserBase()
            };

            //缓存用户会话状态
            authResult.SessionId.SetSession(uVaildInfo.UserId, ExpiredConfigs.GetSessionExpired());

            //缓存用户信息
            UserBiz.SetUserCacheInfo(uVaildInfo.UserId, userCacheInfo);

            //用户登录事件
            SignInEvents(authResult, uVaildInfo);

            //输出请求响应
            context.Flush <AuthResult>(authResult);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 获取用户验证信息
        /// </summary>
        /// <param name="uAccount">用户账户信息(用户名和密码)</param>
        /// <param name="userAccess">用户对应的登录权限</param>
        /// <returns>用户验证信息</returns>
        public static UserVaildInfo GetUserVaildInfo(UserAccount uAccount, UserAccess userAccess = UserAccess.App)
        {
            UserVaildInfo uVaildInfo = UserData.GetUserVaildInfo(uAccount.UserName, userAccess);

            #region 密码

            uAccount.Password = string.Format("MIAP_{0}_{1}_GW", uAccount.Password, uVaildInfo.PasswordSalt).CreateMD5Encrypt();
            if (!uAccount.Password.Equals(uVaildInfo.Password))
            {
                uVaildInfo.UserId = 0;
                return(uVaildInfo);
            }

            #endregion

            #region 账户是否通过验证

            if (!uVaildInfo.IsApproved)
            {
                uVaildInfo.UserId = -1;
                return(uVaildInfo);
            }

            #endregion

            #region 是否被锁定

            if (uVaildInfo.IsLocked)
            {
                if (DateTime.Now < uVaildInfo.LastLockedoutDate)
                {
                    uVaildInfo.UserId = -2;
                    return(uVaildInfo);
                }

                //锁定时间到期,解锁
                UserData.SetUsesUnLocked(uVaildInfo.UserId);
                //记录状态变更日志
                UserStatusChangedLog log = new UserStatusChangedLog
                {
                    UserId     = uVaildInfo.UserId,
                    Action     = 1,
                    Comment    = "锁定时间到期,自动解锁!",
                    CreateDate = DateTime.Now
                };
                LogsBiz.CreateLogs <UserStatusChangedLog>(log);
            }

            #endregion

            #region 是否为试用账号,如果是,试用账号状态

            if (uVaildInfo.UserSite > 0)
            {
                UserWithSchool uWithSchool = UserData.GetUserWithSchool(uVaildInfo.UserId);
                UserWithSchool tempUserWithSchoolInfo;
                //试用账号
                if (uWithSchool.IsTrial)
                {
                    if (!uWithSchool.IsActivated)
                    {
                        //激活试用账号
                        UserConfig userConfig = UserConfigs.GetUserConfigCache();
                        tempUserWithSchoolInfo = new UserWithSchool
                        {
                            UserId        = uWithSchool.UserId,
                            IsActivated   = true,
                            ActivatedDate = DateTime.Now,
                            IsExpired     = false,
                            ExpiredDate   = userConfig.TrialAccountExpiredDay > 0 ? DateTime.Now.AddDays(userConfig.TrialAccountExpiredDay) : DateTime.MaxValue
                        };
                        UserData.SchoolTrialUserStatusChanged(tempUserWithSchoolInfo);
                    }
                    else
                    {
                        //超时时间已过,将试用账号设为过期
                        if (!uWithSchool.IsExpired && DateTime.Now >= uWithSchool.ExpiredDate)
                        {
                            tempUserWithSchoolInfo = new UserWithSchool
                            {
                                UserId        = uWithSchool.UserId,
                                IsActivated   = uWithSchool.IsActivated,
                                ActivatedDate = uWithSchool.ActivatedDate,
                                IsExpired     = true,
                                ExpiredDate   = uWithSchool.ExpiredDate
                            };
                            UserData.SchoolTrialUserStatusChanged(tempUserWithSchoolInfo, 1);

                            uWithSchool.IsExpired = true;
                        }

                        //试用账号已过期
                        if (uWithSchool.IsExpired)
                        {
                            uVaildInfo.UserId = -3;
                            return(uVaildInfo);
                        }
                    }
                }
            }

            #endregion

            return(uVaildInfo);
        }