Overview

This document outlines how to add the unified login/sign-up popup to a new or existing client site. In order to force the use of the login_signup_unified.view.tpl view, a function needs to be overridden in the client's override file for ctrl_WebUserAccount.action.php. All of these functions, plus the additions to the view are a necessity.


Add overrides for ctrl_WebUserAccount.action.php

Add the following overrides to the client’s ctrl_WebUserAccount.action.php file. The first function override below is to force the client to use the unified view for popups.

/**
 * @param array $view
 * @return array
 */
protected function login_form_template($view) {
	if (self::$isPopUp) {
		$view = array(get_class($this->INT), "login_signup_unified");
	}

	return $view;
}

This function override tells the client to use the unified view if there is a sign-in failure when trying to sign-up using the Favorite Property trigger on details pages or other pages where properties exist.

/**
 * @return bool
 */
protected function useSignupLoginUnifiedForFailure() {
	return true;
}

This function override is essential for the view to get the correct $tpl_args to make sure the redirect happens correctly.

public function modify_login_popup_tpl_args($tpl_args) {
	$protocol = 'http';
	if ((defined('FORCE_SSL') && FORCE_SSL) || (defined('PERMANENT_FORCE_SSL') && PERMANENT_FORCE_SSL) || !empty($_SERVER['HTTPS']) || !empty($_SERVER['HTTP_X_SSL_SESSIONID'])) {
		$protocol .= 's';
	}
	$last_url = SwitchBoard::GetLastURL();
	$baseURL = $protocol . "://{$_SERVER['HTTP_HOST']}";
	if (stripos($last_url['url_raw'], 'addRemoveFavoritePropertyManager') !== false) {
		$tpl_args['redirect'] = $baseURL . '/popup' . $last_url['url_raw'];
	}

	if (isset($tpl_args['set_last_url'])) {
		SwitchBoard::SetLastURL(SwitchBoard::GetLastURL());
	}

	return $tpl_args;
}

Add overrides for login_signup_unified.view.tpl

Add the following overrides to the client’s login_signup_unified.view.tpl file. The first override below will tell the login form to not use AJAX and will tell the sign-up form to redirect to the correct favorite property form after signing in.

<form method="post" {if $redirect}action="/popup{$ACTION_URLS.account}login"{else}id="account_login_ajax" action="{$ACTION_URLS.account}ajax_login"{/if} class="validate-form">
	<fieldset>
		<div class="float-label-wrap margin-bottom-20">
			<label for="wua-email">Email</label>
			<input id="wua-email" name="email_address" type="email" placeholder="Email" class="form-control float-label-form-control required">
        </div>
        <div class="float-label-wrap margin-bottom-20">
            <label for="wua-pass">Password</label>
            <input id="wua-pass" type="password" name="password" placeholder="Password" class="form-control float-label-form-control required">
        </div>
        <div class="center">
            <button class="btn btn-default" type="submit" name="Submit">Sign In</button>
        </div>
        <a href="{$ACTION_URLS.account}forgot_password" title="Forgot Password?">Forgot your password?</a>
    </fieldset>
</form>

You will also need to add the redirect input to get the form to redirect to the correct view after form submission.

<form id="create_account_form" action="{$ACTION_URLS.account}createAccount" method="post" autocomplete="off" class="validate-form">
	{if $redirect}
		<input type="hidden" name="redirect" value="{$redirect}">
    {/if}
    <fieldset>
		<div class="row">
			<div class="col-sm-6 float-label-wrap float-label-wrap-column margin-bottom-20">
				<label for="reg-first-name">First Name</label>
                <input type="text" name="fname" id="reg-first-name" placeholder="First Name" class="form-control float-label-form-control required" value="">
            </div>
            <div class="col-sm-6 float-label-wrap float-label-wrap-column margin-bottom-20">
                <label for="reg-last-name">Last Name</label>
                <input type="text" name="lname" id="reg-last-name" placeholder="Last Name" class="form-control float-label-form-control required" value="">
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6 float-label-wrap float-label-wrap-column margin-bottom-20">
                <label for="reg-email">Email Address</label>
                <input type="email" name="email_address" id="reg-email" placeholder="Email Address" class="form-control float-label-form-control required email" value="">
                <input type="email" name="email" style="display:none;" value="" class="labelstate-ignore">
            </div>
            <div class="col-sm-6 float-label-wrap float-label-wrap-column margin-bottom-20">
                <label for="reg-phone">Phone (optional)</label>
                <input class="form-control float-label-form-control" id="reg-phone" placeholder="Phone (optional)" type="tel" name="5_Cell_Phone" value="">
            </div>
        </div>
        <div class="center">
            <button type="submit" name="Submit" class="btn btn-primary create-account-link"><span>Create Account</span></button>
        </div>
    </fieldset>
</form>

Add overrides for add_favorite_property.popup.view.tpl

Add the following overrides to the client’s add_favorite_property.popup.view.tpl file. This is just the addition of a data attribute to check if a refresh is required. All of the logic to determine this has been added to the base controller, however, the HTML and SMARTY check must be added to the form for the JS to work.