Exemplo n.º 1
0
        private void DoAuthenticateUser()
        {
            if (string.IsNullOrEmpty(this.PasswordBoxPassword.Password) == false &&
                string.IsNullOrEmpty(this.m_AuthenticatedUser.Password) == false &&
                string.IsNullOrEmpty(this.m_AuthenticatedUser.AuthenticatorToken) == false)
            {
                JObject   apiRequest  = APIRequestHelper.GetTokenMessage(this.m_AuthenticatedUser.UserName, this.PasswordBoxPassword.Password, this.m_AuthenticatedUser.AuthenticatorToken);
                APIResult apiResponse = APIRequestHelper.SubmitAPIRequestMessage(apiRequest);
                if (Convert.ToBoolean(apiResponse.JSONResult["result"]["isAuthenticated"].ToString()) == true)
                {
                    string tkn = apiResponse.JSONResult["result"]["token"].ToString();

                    this.m_AuthenticatedUser.WebServiceAccount       = (JObject)apiResponse.JSONResult["result"]["webServiceAccount"];
                    this.m_AuthenticatedUser.WebServiceAccountClient = (JArray)apiResponse.JSONResult["result"]["webServiceAccountClient"];
                    this.m_AuthenticatedUser.ClientCollection        = ClientCollection.Build((JArray)apiResponse.JSONResult["result"]["clientsAllowed"]);

                    JwtSecurityToken token = new JwtSecurityToken(tkn);
                    this.m_AuthenticatedUser.IsAuthenticated = true;
                    this.m_AuthenticatedUser.Token           = token;

                    if (apiResponse.JSONResult["result"]["clientGroupClient"] != null)
                    {
                        JArray clientGroups = (JArray)apiResponse.JSONResult["result"]["clientGroupClient"];
                        if (clientGroups.Count > 0)
                        {
                            this.m_AuthenticatedUser.ClientGroupId = apiResponse.JSONResult["result"]["clientGroupClient"][0]["ClientGroupId"].ToString();
                        }
                        else
                        {
                            this.m_AuthenticatedUser.ClientGroupId = "0";
                        }
                    }

                    LocalSettings.Instance.UpdateUserNamePassword(m_AuthenticatedUser);
                    LocalSettings.Instance.Serialize();

                    PhysicianCollection.SetCollection(this.m_AuthenticatedUser.GetSQLClientIdInList());
                    PhysicianClientCollection.SetCollection();
                    this.Close();
                }
                else
                {
                    this.m_AuthenticatedUser.IsAuthenticated = true;
                    MessageBox.Show("The Authenticator Token provided is not valid.");
                }
            }
            else
            {
                MessageBox.Show("The username, password and authenticator code cannot be blank.");
            }
        }