wei
2020-11-27 7ca4d7e50871c558e5927b6b0eeecb2071fdf14c
HDL_ON/UI/UI1-Login/LoginPageBLL.cs
@@ -28,6 +28,25 @@
        }
        /// <summary>
        /// 检测当前配置域名是否一致,不一致则替换
        /// </summary>
        /// <param name="result"></param>
        void CheckAndSetUserRequestHost(ResponsePackNew result)
        {
            try
            {
                var mGlobalRegionListObj = Newtonsoft.Json.JsonConvert.DeserializeObject<GlobalRegionListRes>(result.Data.ToString());
                if (UserInfo.Current.RequestHttpsHost != mGlobalRegionListObj.regionUrl)
                {
                    UserInfo.Current.RequestHttpsHost = mGlobalRegionListObj.regionUrl;
                    UserInfo.Current.GlobalRegion = mGlobalRegionListObj;
                    UserInfo.Current.SaveUserInfo();
                }
            }
            catch { }
        }
        /// <summary>
        /// 点击按钮获取验证码
        /// </summary>
        void GetVerificationCode()
@@ -51,7 +70,7 @@
                        btnAccountViewBottomLine.Height = Application.GetRealHeight(2);
                        return;
                    }
                    if (!Regex.IsMatch(account, @"^[1]+\d{10}") || (account.Length != 11))
                    if (!Utlis.CheckPhoneNumber(phoneNumber, phoneZoneCode))
                    {
                        var tip = new Tip()
                        {
@@ -73,11 +92,14 @@
                        var result = pm.GetRegionByAccount(account);
                        if (result.Code != StateCode.SUCCESS)
                        {
                            IMessageCommon.Current.ShowErrorInfoAlter(NewAPI.API_POST_GetRegionByAccount, result.Code);
                            IMessageCommon.Current.ShowErrorInfoAlter(result.Code);
                            return;
                        }
                        else
                        {
                            //检测当前配置域名是否一致,不一致则替换
                            CheckAndSetUserRequestHost(result);
                            //
                            Application.RunOnMainThread(() =>
                            {
                                btnGetVerificationCode.IsSelected = false;
@@ -113,7 +135,7 @@
                                    btnPasswordViewBottomLine.Height = Application.GetRealHeight(2);
                                });
                                // 提示错误
                                IMessageCommon.Current.ShowErrorInfoAlter(NewAPI.API_POST_Verification_Send, resultObj.Code);
                                IMessageCommon.Current.ShowErrorInfoAlter(resultObj.Code);
                            }
                        }
@@ -395,7 +417,7 @@
                        return;
                    if (loginType == 0)
                    {
                        if (!Regex.IsMatch(account, @"^[1]+\d{10}") || (account.Length != 11))
                        if (!Utlis.CheckPhoneNumber(registerPhone, phoneZoneCode))
                        {
                            var tip = new Tip()
                            {
@@ -418,7 +440,7 @@
                    }
                    else
                    {
                        if (!Regex.IsMatch(account, "([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,5})+"))
                        if (!Utlis.CheckEmail(registerEmail))
                        {
                            var tip = new Tip()
                            {
@@ -493,12 +515,15 @@
            {
                if (btnLogin.IsSelected)
                {
                    //判断是否同意了隐私政策
                    if (CheckPrivacyPolicy() == false) return;
                    account = etAccount.Text.Trim();
                    password = etPassword.Text.Trim();
                    if (loginType == 0)
                    {
                        if (!Regex.IsMatch(account, @"^[1]+\d{10}") && account.Length == 11)
                        if (!Utlis.CheckPhoneNumber(account, phoneZoneCode))
                        {
                            var tip = new Tip()
                            {
@@ -512,7 +537,7 @@
                    }
                    else
                    {
                        if (!Regex.IsMatch(account, "([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,5})+"))
                        if (!Utlis.CheckEmail(account))
                        {
                            var tip = new Tip()
                            {
@@ -584,8 +609,13 @@
                        var result = pm.GetRegionByAccount(account);
                        if (result.Code != StateCode.SUCCESS)
                        {
                            IMessageCommon.Current.ShowErrorInfoAlter(NewAPI.API_POST_GetRegionByAccount, result.Code);
                            IMessageCommon.Current.ShowErrorInfoAlter(result.Code);
                            return;
                        }
                        else
                        {
                            //设置用户所注册地区的域名,用户相关操作都用这个域名
                            CheckAndSetUserRequestHost(result);
                        }
                    }
@@ -627,7 +657,7 @@
                                OnAppConfig.Instance.RefreshUserConfig();
                                DB_ResidenceData.InitRoomFunction();
                            }
                            if (MainPage.LoginUser.userEmailInfo == "464027401@qq.com")
                            if ( UserInfo.Current.userEmailInfo == "464027401@qq.com")
                            {
                                DB_ResidenceData.residenceData.floors.Add(new Floor() { name = "1F", sid = "09888" });
                                var r111 = new Room() { sid = "0001", name = "Room-1", floorId = "09888", backgroundImage = "Classification/Room/Roombg.png" };
@@ -638,11 +668,11 @@
                                {
                                    sid = "030101123456780604010001ABCD",
                                    name = "空调",
                                    function = new List<Trait>() {
                                                                new Trait { name="on_off", max=1,min = 0, value_key= new List<string> { "on","off"} },
                                                                new Trait { name="mode", max = 2,min =0,value_key = new List<string>{ "auto", "heat", "cool","dry" } },
                                                                new Trait { name = "fan",max = 3,min =0,value_key = new List<string>{ "low", "medium", "high" ,"auto"} },
                                                                new Trait { name = "set_temperature", max = 32,min=16,value_key = new List<string>{"up","down" } },
                                    function = new List<FunctionAttributes>() {
                                                                new FunctionAttributes { key="on_off", max=1,min = 0, value= new List<string> { "on","off"} },
                                                                new FunctionAttributes { key="mode", max = 2,min =0,value = new List<string>{ "auto", "heat", "cool","dry" } },
                                                                new FunctionAttributes { key = "fan",max = 3,min =0,value = new List<string>{ "low", "medium", "high" ,"auto"} },
                                                                new FunctionAttributes { key = "set_temperature", max = 32,min=16,value = new List<string>{"up","down" } },
                                                            },
                                    roomIdList = new List<string>() { "0001" },
                                    lastState = "制冷 中风 18°C",
@@ -657,8 +687,8 @@
                                {
                                    sid = "030101123456780202020002ABCD",
                                    name = "调光灯",
                                    function = new List<Trait>() {
                                                                new Trait { name="brightness", max=100,min = 0, value_key= new List<string> { "up","down"} },
                                    function = new List<FunctionAttributes>() {
                                                                new FunctionAttributes { key="brightness", max=100,min = 0, value= new List<string> { "up","down"} },
                                                            },//"brightness",
                                    roomIdList = new List<string>() { "0001" },
                                    lastState = "20%",
@@ -675,8 +705,8 @@
                                    sid = "030101123456780303010003ABCD",
                                    name = "窗帘模块",
                                    roomIdList = new List<string>() { "0001" },
                                    function = new List<Trait>() {
                                                                new Trait { name="on_off", max=2,min = 0, value_key= new List<string> { "on","off","stop"} },
                                    function = new List<FunctionAttributes>() {
                                                                new FunctionAttributes { key="on_off", max=2,min = 0, value= new List<string> { "on","off","stop"} },
                                                            },// "curtain",
                                    lastState = "开",
                                    bus_Data = new BusData
@@ -691,8 +721,8 @@
                                    sid = "030101123456780303030011ABCD",
                                    name = "开合帘",
                                    roomIdList = new List<string>() { "0001" },
                                    function = new List<Trait>() {
                                                                new Trait { name="on_off", max=100,min = 0, value_key= new List<string> { "on","off","stop"} },
                                    function = new List<FunctionAttributes>() {
                                                                new FunctionAttributes { key="on_off", max=100,min = 0, value= new List<string> { "on","off","stop"} },
                                                            },//"curtaintype",
                                    lastState = "20%",
                                    bus_Data = new BusData
@@ -707,9 +737,9 @@
                                    sid = "030101123456780503040012ABCD",
                                    name = "卷帘",
                                    roomIdList = new List<string>() { "0001" },
                                    function = new List<Trait>() {
                                                                new Trait { name="on_off", max=2,min = 0, value_key= new List<string> { "on","off","stop"} },
                                                                new Trait { name="percent", max=100,min = 0, value_key= new List<string> { "percent" } },
                                    function = new List<FunctionAttributes>() {
                                                                new FunctionAttributes { key="on_off", max=2,min = 0, value= new List<string> { "on","off","stop"} },
                                                                new FunctionAttributes { key="percent", max=100,min = 0, value= new List<string> { "percent" } },
                                                            },// "rollingshutter",
                                    lastState = "20%",
@@ -725,10 +755,10 @@
                                    sid = "030101123456780404020004ABCD",
                                    name = "地热",
                                    roomIdList = new List<string>() { "0001" },
                                    function = new List<Trait>() {
                                                                new Trait { name="on_off", max=1,min = 0, value_key= new List<string> { "on","off"} },
                                                                new Trait { name="mode", max = 2,min =0,value_key = new List<string>{ "normal", "day", "night","timer","away" } },
                                                                new Trait { name = "set_temperature", max = 32,min=5,value_key = new List<string>{"up","down" } },
                                    function = new List<FunctionAttributes>() {
                                                                new FunctionAttributes { key="on_off", max=1,min = 0, value= new List<string> { "on","off"} },
                                                                new FunctionAttributes { key="mode", max = 2,min =0,value = new List<string>{ "normal", "day", "night","timer","away" } },
                                                                new FunctionAttributes { key = "set_temperature", max = 32,min=5,value = new List<string>{"up","down" } },
                                                            },//
                                    lastState = "自动 25°C",
                                    bus_Data = new BusData
@@ -742,8 +772,8 @@
                                {
                                    sid = "030101123456780202010005ABCD",
                                    name = "吊灯",
                                    function = new List<Trait>() {
                                                                new Trait { name="on_off", max=100,min = 0, value_key= new List<string> { "on","off"} },
                                    function = new List<FunctionAttributes>() {
                                                                new FunctionAttributes { key="on_off", max=100,min = 0, value= new List<string> { "on","off"} },
                                                            },//"on_off",
                                    roomIdList = new List<string>() { "0001" },
                                    bus_Data = new BusData
@@ -757,9 +787,9 @@
                                {
                                    sid = "030101123456780202040006ABCD",
                                    name = "RGB灯",
                                    function = new List<Trait>() {
                                                                new Trait { name="brightness", max=100,min = 0, value_key= new List<string> { "on","off"} },
                                                                new Trait { name="color", max=100,min = 0, value_key= new List<string> { "255", "255", "255" } },
                                    function = new List<FunctionAttributes>() {
                                                                new FunctionAttributes { key="brightness", max=100,min = 0, value= new List<string> { "on","off"} },
                                                                new FunctionAttributes { key="color", max=100,min = 0, value= new List<string> { "255", "255", "255" } },
                                                            },
                                    roomIdList = new List<string>() { "0001" },
                                    bus_Data = new BusData
@@ -773,9 +803,9 @@
                                {
                                    sid = "030101123456781010020006ABCD",
                                    name = "风扇",
                                    function = new List<Trait>() {
                                                            new Trait { name="on_off", max=1,min = 0, value_key= new List<string> { "on","off"} },
                                                            new Trait { name="percent", max=7,min = 0, value_key= new List<string> { "percent" } },
                                    function = new List<FunctionAttributes>() {
                                                            new FunctionAttributes { key="on_off", max=1,min = 0, value= new List<string> { "on","off"} },
                                                            new FunctionAttributes { key="percent", max=7,min = 0, value= new List<string> { "percent" } },
                                                        },
                                    roomIdList = new List<string>() { "0001" },
                                    bus_Data = new BusData
@@ -789,8 +819,8 @@
                                {
                                    sid = "030101123456781010020006ABCD",
                                    name = "电视",
                                    function = new List<Trait>() {
                                                            new Trait { name="on_off", max=1,min = 0, value_key= new List<string> { "on","off"} },
                                    function = new List<FunctionAttributes>() {
                                                            new FunctionAttributes { key="on_off", max=1,min = 0, value= new List<string> { "on","off"} },
                                                        },
                                    roomIdList = new List<string>() { "0001" },
                                    bus_Data = new BusData
@@ -804,8 +834,8 @@
                                {
                                    sid = "030101123456780101020006ABCD",
                                    name = "插座",
                                    function = new List<Trait>() {
                                                            new Trait { name="on_off", max=1,min = 0, value_key= new List<string> { "on","off"} },
                                    function = new List<FunctionAttributes>() {
                                                            new FunctionAttributes { key="on_off", max=1,min = 0, value= new List<string> { "on","off"} },
                                                        },
                                    roomIdList = new List<string>() { "0001" },
                                    bus_Data = new BusData
@@ -820,8 +850,8 @@
                                    sid = "030101123456781005060006ABCD",
                                    name = "PM2.5",
                                    roomIdList = new List<string>() { "0001" },
                                    function = new List<Trait>() {
                                                            new Trait { name="values", max=1,min = 0, value_key= new List<string> { "22"} },
                                    function = new List<FunctionAttributes>() {
                                                            new FunctionAttributes { key="values", max=1,min = 0, value= new List<string> { "22"} },
                                                        },
                                    bus_Data = new BusData
                                    {
@@ -835,8 +865,8 @@
                                    sid = "030101123456781005070006ABCD",
                                    name = "CO2",
                                    roomIdList = new List<string>() { "0001" },
                                    function = new List<Trait>() {
                                                            new Trait { name="values", max=1,min = 0, value_key= new List<string> { "1352"} },
                                    function = new List<FunctionAttributes>() {
                                                            new FunctionAttributes { key="values", max=1,min = 0, value= new List<string> { "1352"} },
                                                        },
                                    bus_Data = new BusData
                                    {
@@ -850,8 +880,8 @@
                                    sid = "030101123456781005020006ABCD",
                                    name = "温度",
                                    roomIdList = new List<string>() { "0001" },
                                    function = new List<Trait>() {
                                                            new Trait { name="values", max=1,min = 0, value_key= new List<string> { "28"} },
                                    function = new List<FunctionAttributes>() {
                                                            new FunctionAttributes { key="values", max=1,min = 0, value= new List<string> { "28"} },
                                                        },
                                    bus_Data = new BusData
                                    {
@@ -865,8 +895,8 @@
                                    sid = "030101123456781005050006ABCD",
                                    name = "TVOC",
                                    roomIdList = new List<string>() { "0001" },
                                    function = new List<Trait>() {
                                                            new Trait { name="values", max=1,min = 0, value_key= new List<string> { "0.3"} },
                                    function = new List<FunctionAttributes>() {
                                                            new FunctionAttributes { key="values", max=1,min = 0, value= new List<string> { "0.3"} },
                                                        },
                                    bus_Data = new BusData
                                    {
@@ -880,8 +910,8 @@
                                    sid = "030101123456781005030006ABCD",
                                    name = "湿度",
                                    roomIdList = new List<string>() { "0001" },
                                    function = new List<Trait>() {
                                                            new Trait { name="values", max=1,min = 0, value_key= new List<string> { "15"} },
                                    function = new List<FunctionAttributes>() {
                                                            new FunctionAttributes { key="values", max=1,min = 0, value= new List<string> { "15"} },
                                                        },
                                    bus_Data = new BusData
                                    {
@@ -901,7 +931,11 @@
                        else
                        {
                            //2020-11-13 待确认
                            MainPage.ShowAlertOnMainThread("登录失败,请先添加住宅。");
                            //获取住宅失败,重新标记为未登录状态
                             UserInfo.Current.LastTime = DateTime.MinValue;
                             UserInfo.Current.SaveUserInfo();
                            //登录失败,请先添加住宅!
                            Utlis.ShowAlertOnMainThread(Language.StringByID(StringId.FailedGetHomeList));
                        }
                    }
                }
@@ -945,18 +979,26 @@
            if (loginResult.Code == StateCode.SUCCESS)
            {
                var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<UserLoginRes>(loginResult.Data.ToString());
                MainPage.LoginUser = new UserInfo
                {
                    userType = revertData.userType,
                    accountString = account,
                    password = password,
                    lastTime = DateTime.Now,
                    ID = revertData.userId,
                    loginTokenString = revertData.headerPrefix + revertData.accessToken,
                    refreshToken = revertData.refreshToken,
                    userName = revertData.name
                };
                MainPage.LoginUser.SaveUserInfo();
                // UserInfo.Current = new UserInfo
                //{
                //    userType = revertData.userType,
                //    accountString = account,
                //    password = password,
                //    lastTime = DateTime.Now,
                //    ID = revertData.userId,
                //    loginTokenString = revertData.headerPrefix + revertData.accessToken,
                //    refreshToken = revertData.refreshToken,
                //    userName = revertData.name
                //};
                UserInfo.Current.userType = revertData.userType;
                UserInfo.Current.AccountString = account;
                //UserInfo.Current.password = password;
                UserInfo.Current.LastTime = DateTime.Now;
                UserInfo.Current.ID = revertData.userId;
                UserInfo.Current.LoginTokenString = revertData.headerPrefix + revertData.accessToken;
                UserInfo.Current.refreshToken = revertData.refreshToken;
                UserInfo.Current.userName = revertData.name;
                UserInfo.Current.SaveUserInfo();
                MainPage.Log("登录成功。");
                result = true;
                //获取用户信息
@@ -1031,7 +1073,7 @@
            if (responsePack == StateCode.SUCCESS)
            {
                //2020-11-13 待确认,没有住宅,不算登录成功
                if (MainPage.LoginUser.regionList != null && MainPage.LoginUser.regionList.Count > 0){
                if ( UserInfo.Current.regionList != null &&  UserInfo.Current.regionList.Count > 0){
                    result = true;
                }
                //result = true;
@@ -1039,7 +1081,7 @@
            else
            {
                // 提示错误
                IMessageCommon.Current.ShowErrorInfoAlter(NewAPI.API_POST_Gethomepager, responsePack);
                IMessageCommon.Current.ShowErrorInfoAlter(responsePack);
            }
            return result;
        }