public async Task Login(LoginRegisterDTO aUser) { await _LoginOrRegister(aUser, APIConstants.URL_LOGIN_USER); }
private async Task _LoginOrRegister(LoginRegisterDTO aUser, string aURL) { using (this.SetBusy()) { var lResponse = await mJSONRequester.Post<LoginRegisterDTO>(this.ServerURL, aURL, aUser, mRequestHeaders); lResponse.EnsureSuccessStatusCode(); var lUser = await lResponse.Content.ReadAsAsync<UserDTO>(); var lCookies = mJSONRequester.Cookies.GetCookies(new Uri(this.ServerURL)); var lAuthCookie = lCookies.Cast<Cookie>().FirstOrDefault(aCookie => aCookie != null && aCookie.Name == APIConstants.FormsAuthentication_FormsCookieName); if (lAuthCookie != null) { this.mHubConnection = new HubConnection(this.ServerURL + APIConstants.URL_SIGNALR_HUB); this.mHubConnection.CookieContainer = new CookieContainer(); this.mHubConnection.CookieContainer.Add(lResponse.RequestMessage.RequestUri, lAuthCookie); mHubProxy = mHubConnection.CreateHubProxy("ProductsHub"); mHubProxy.On<string, object>("OnServerEvent", _OnSignalREvent); await mHubConnection.Start(new LongPollingTransport()); mRequestHeaders[lAuthCookie.Name] = lAuthCookie.Value; LoggedInUser = lUser; mHubConnection.StateChanged += _OnSignalRConnectionStateChanged; _NotifyPropertyChanged("LoggedInUser"); } } }
public async Task RegisterUser(LoginRegisterDTO aUser) { await _LoginOrRegister(aUser, APIConstants.URL_REGISTER_USER); }