protected async Task UserCheckAsync() { Console.WriteLine("UserCheck:" + SessionStorage.GetId()); var user = await SessionStorage.GetItemAsync <JobUserEntity>(SessionStorage.GetId()); if (user == null || user.Id <= 0) { user = await LocalStorage.GetItemAsync <JobUserEntity>($"__User"); if (user != null && user.Id > 0) { var re = await UserLoginAsync(user.UserName, Secret.DesDecrypt(user.Password)); if (re.Success) { await SessionStorage.SetItemAsync(SessionStorage.GetId(), re.Data); } else { Nav.NavigateTo("/login"); } } else { await SessionStorage.ClearAsync(); Nav.NavigateTo("/login"); } } }
public async Task UserLoginAsync() { var input = new Input { Extens = new Dictionary <string, string> { { "UserName", UserName }, { "Password", Secret.DesEncrypt(Password) } } }; var re = await Http.PostHttpAsync <Result <JobUserEntity>, Input>($"job/login", input); if (re.Success) { await JSRuntime.DoVoidAsync("toastrs", new[] { "success", "登录", re.Message }); re.Data.Password = "******"; await SessionStorage.SetItemAsync(SessionStorage.GetId(), re.Data); if (Remember) { re.Data.Password = Secret.DesEncrypt(Password); await LocalStorage.SetItemAsync($"__User", re.Data); } Nav.NavigateTo("/"); } else { await JSRuntime.DoVoidAsync("toastrs", new[] { "error", "登录", re.Message }); } }
} //= new JobUserEntity { Name = "抵拢倒拐", Img = "img/lbxx.jpg" }; protected override async Task OnInitializedAsync() { var user = await SessionStorage.GetItemAsync <JobUserEntity>(SessionStorage.GetId()); if (user != null) { user.Img = "img/lbxx.jpg"; UserInfo = user; } else { UserInfo = new JobUserEntity { RealName = "小秘密", Img = "img/lbxx.jpg" }; } }