Forum Discussion

PerBonomi's avatar
9 years ago

Increase completed registrations?

Hi there. I was thinking this morning, that maybe we could help new users complete their registration if we suggest a username for them, and I couldn't figure out the XML Text generator for sso users.

Hence this basic code. Anyone want to pick it apart?

 

Basically, on the page where you've already logged in through sso, but haven't picked a username yet I check if a user with your sso already exists and either suggest your sso as username, or loop through variations(sso_1,sso_2,etc.) to find an available name.

 

<#if !user.anonymous>
	<#attempt>
		<#assign usersso = restadmin("/users/id/${user.id}/sso_id").value />
	<#recover>
		<#assign usersso = "" />
	</#attempt>
</#if>
<#if usersso?? && usersso != "">
	<#attempt>
		<#assign userNameExists = restadmin("/users/login/${usersso}/login").value/>
	<#recover>
		<#assign userNameExists = "N"/>
		<#assign userName = usersso/>
	</#attempt>
</#if>
<#if userNameExists??>
	<#if userNameExists != "N">
		<#list 1..50 as u>
			<#attempt>
				<#assign userNameExists = restadmin("/users/login/${usersso}_${u}/login").value/>
			<#recover>
				<#assign userNameExists = "N"/>
				<#assign userName = "${usersso}_${u}"/>
			</#attempt>
			<#if userNameExists == "N">
				<#break>
			</#if>
		</#list>
	</#if>
	<#if userName??>
		<script>
		$(window).load( function() {
			$("#lia-login").val('${userName}');
		});
		</script>
	</#if>
</#if>
  • DougS's avatar
    DougS
    Khoros Oracle

    There is an option in the SSO admin to auto-suggest a username -- see the reference for the auto-generated username is here in the SSO configuration doc.  I'm not sure it quite fits the bill as far as what you are looking for.  If not, you might want to consider using LiQL to find any users with the same username:

     

    <#assign query = "SELECT login FROM users WHERE login = '" + chosenLogin+ "'" />
    <#assign resp = restadmin("2.0", "/search?q=" + query?url) />

    It will do a search in the back-end that way and you won't have to do the lookup in an attempt/recover block, so it should perform better.