예제 #1
0
        public LoginResultDto <UserDto> LoginCheck(string account, string passwd, Enums.LoginPlatform loginPlatform)
        {
            LoginResultDto <UserDto> result = new LoginResultDto <UserDto>();


            try
            {
                if (String.IsNullOrWhiteSpace(account) || String.IsNullOrWhiteSpace(passwd))
                {
                    result.Failed("用户名/密码不能为空!");
                    return(result);
                }


                //passwd = RSAHelper.Instance.Encrypt(account+passwd);
                var user = FindUserByLoginName(account);
                if (user == null || user.State == Enums.UserStatus.Deleted || user == null || user.State == Enums.UserStatus.Deleted || user.LoginPasswd != passwd)
                {
                    result.Failed("用户名/密码错误!");
                    return(result);
                }
                if (user.State == Enums.UserStatus.Forbid)
                {
                    result.Failed("您的账号已被停用,请联系单位管理员!");
                    return(result);
                }


                //走到这里说明验证通过

                if (loginPlatform == Enums.LoginPlatform.Web)
                {
                    var token = Tools.CreateWebToken(user.Id, user.LoginName, Enums.LoginPlatform.Web);
                    RedisHelper.Instance.SetHash(RedisCacheTables.WebTokenDto, user.Id, token);
                    result.Success("登录成功!");
                    result.Data  = user;
                    result.Token = token;
                }
                else if (loginPlatform == Enums.LoginPlatform.Android)
                {
                }
                else if (loginPlatform == Enums.LoginPlatform.IOS)
                {
                }
                else if (loginPlatform == Enums.LoginPlatform.WeiXinProgram)
                {
                }
            }
            catch (Exception ex)
            {
                result.Failed(ex);
            }


            return(result);
        }
        public LoginResultDto <UserDto> LoginCheck(string account, string passwd, LoginPlatform loginPlatform)
        {
            LoginResultDto <UserDto> result = new LoginResultDto <UserDto>();

            try
            {
                if (String.IsNullOrWhiteSpace(account) || String.IsNullOrWhiteSpace(passwd))
                {
                    result.Failed("用户名/密码不能为空!");
                    return(result);
                }


                //passwd = RSAHelper.Instance.Encrypt(account+passwd);
                var user = FindUserByLoginName(account);
                if (user == null || user.State == UserStatus.Deleted || user.LoginPasswd != passwd)
                {
                    result.Failed("用户名/密码错误!");
                    return(result);
                }
                if (user.State == UserStatus.Forbid)
                {
                    result.Failed("您的账号已被停用,请联系单位管理员!");
                    return(result);
                }

                result.Success("登录成功!");
                result.Data = user;
                //走到这里说明验证通过
            }
            catch (Exception ex)
            {
                result.Failed(ex);
            }


            return(result);
        }