Skip to content

Instantly share code, notes, and snippets.

@rdehler
Created May 6, 2020 18:43
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 rdehler/c8d429d918ce1392d23af1170da5caff to your computer and use it in GitHub Desktop.
Save rdehler/c8d429d918ce1392d23af1170da5caff to your computer and use it in GitHub Desktop.
Proof of concept to use a partial username or even another
<apex:page id="loginPage" controller="CommunitiesLoginController" title="{!$Label.site.site_login}" showHeader="false">
<apex:form>
<apex:pageMessages></apex:pageMessages>
Username:
<apex:inputText value="{!username}" />
Password:
<apex:inputSecret value="{!password}" />
<apex:commandButton action="{!customLogin}"/>
</apex:form>
</apex:page>
global with sharing class CommunitiesLoginController {
global String username {get; set;}
global String password {get; set;}
global CommunitiesLoginController () {}
global PageReference customLogin() {
String actualUsername = username;
// here is where we would dynamically choose a field other than the username to retrieve the actual username
if (actualUsername != null && !actualUsername.contains('@')) {
actualUsername += '@7s-ray.dev';
}
return Site.login(actualUsername, password, '/');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment