Skip to content

Instantly share code, notes, and snippets.

@tac-ljustiniano
Last active August 31, 2022 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tac-ljustiniano/76d8930ee0b2d849fc8077fa8159b5b8 to your computer and use it in GitHub Desktop.
Save tac-ljustiniano/76d8930ee0b2d849fc8077fa8159b5b8 to your computer and use it in GitHub Desktop.
public class AccessUsers_Extension : PXGraphExtension<AccessUsers>
{
...
protected virtual IEnumerable associateUser(PXAdapter adapter)
{
Users user = (Users)Base.UserList.Current; // Acumatica user
if(GoogleActive && user != null)
{
...
if (!string.IsNullOrEmpty(user.Email))
{
GoogleMaint socketGraph = PXGraph.CreateInstance<GoogleMaint>(); // My screen graph
GSocket gc = socketGraph.CreateGSocketInstance();
if (gc != null)
{
try
{
UserData userItem = gc.GetUser(user.Email);
if (!string.IsNullOrEmpty(userItem?.ID))
{
user.IsApproved = userItem.Active; //Enable/Disable the user
user.AllowPasswordRecovery = false; // SSO does not require password recovery
user.PasswordChangeable = false; // SSO does not require allowing to change the password
user.PasswordNeverExpires = true; // Any password never expires
user.PasswordChangeOnNextLogin = false; // No need to change the password next login
Base.UserList.Update(user);
SetUserIdentity(userItem.ID); // Sets the Account ID
}
}
catch(Exception ex)
{
// Error here
}
}
}
Base.Actions.PressSave();
}
return adapter.Get();
}
...
}
...
foreach (var uiRow in Base.Identities.Select())
{
UserIdentity ui = (UserIdentity)uiRow;
if (ui.ProviderName == Provider.Google)
{
ui.UserKey = userKey; // Account ID
ui.Active = active;
Base.Identities.Update(ui);
break;
}
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment