Exemplo n.º 1
0
        private void ProcessLogin()
        {
            var loginRq = new LoginRq
            {
                username       = LoginDetails.Username,
                passwordDigest = LoginDetails.PasswordHash,
                profile        = LoginDetails.Profile,
                workstation    = LoginDetails.Workstation,
                version        = _appContext.Version(2),
                partnerCode    = _appContext.Reg.getRegValue("PromoCode", true),
                loginGuest     = LoginDetails.LoginGuest,
            };
            LoginRs loginRs = null;

            try
            {
                loginRs = _appContext.ConnectionManager.Connection.Request <LoginRq, LoginRs>(loginRq);
                _appContext.CurrentUserManager.SetUser(loginRs.userElement, loginRs.shortCode);
                _appContext.RosterManager.RetrieveRoster();
                if (loginRs.partnerElement != null)
                {
                    _appContext.SettingsManager.Partner = new Partner()
                    {
                        Basename = loginRs.partnerElement.basename,
                        LinkText = loginRs.partnerElement.linkText,
                        Logo     = Convert.FromBase64String(loginRs.partnerElement.logo),
                        Name     = loginRs.partnerElement.name,
                        Text     = loginRs.partnerElement.text,
                        Website  = loginRs.partnerElement.website
                    };
                }
                else
                {
                    _appContext.SettingsManager.Partner = null;
                }
            }
            catch (MessageException <LoginRs> e)
            {
                if (!e.Response.loggedIn)
                {
                    throw new LoginException("Failed to login, server responded with : " + e.Response.errorMessage,
                                             e.Response.error);
                }
                throw;
            }

            // Exception not thrown, login success, save details
            LoginDetails.Username   = loginRs.userElement.user;
            _reg.Username           = loginRs.userElement.user;
            _reg.PasswordHash       = loginRq.loginGuest ? loginRs.guestSecretKey : LoginDetails.PasswordHash;
            _reg.Profile            = LoginDetails.Profile = loginRs.profileId;
            LoginDetails.LoginGuest = false;
            IsLoggedIn = true;
            // Notify all threads waiting for login
            lock (LoginOccurredLock)
            {
                Monitor.PulseAll(LoginOccurredLock);
            }
            OnLoggedIn();
            Logger.Info("Login success : " + _appContext.CurrentUserManager.CurrentUser.Username + "!" + _appContext.CurrentUserManager.ActiveShortCode + "@" + LoginDetails.Profile + "-" +
                        LoginDetails.Workstation);
            // can fetch the team in the background
            ThreadPool.QueueUserWorkItem(state => {
                try
                {
                    _appContext.TeamManager.RetrieveTeams();
                }
                catch (Exception e)
                {
                    Logger.Error("Failed to retrieve teams during login", e);
                }
            });
        }
Exemplo n.º 2
0
 public void Start()
 {
     _connection.StartConnection(_appContext.Version(), Cert);
 }