Answers.Body: <p>I assume you have basic knowledge about plugins and routing, if not I'll update my post in a few hours.. otherwise Your form could be</p>
  
  <pre><code>&lt;!-- check if user submitted something --&gt;
  {% if userExists is defined %}
      {% if userExists == true %}
          &lt;!-- user exists login --&gt;
          hello {{ user.name }}
  
          &lt;form method="post" accept-charset="UTF-8"&gt;
              {{ getCsrfInput() }}
              &lt;input type="hidden" name="action" value="users/login"&gt;
  
              &lt;h3&gt;&lt;label for="loginName"&gt;Username or email&lt;/label&gt;&lt;/h3&gt;
              &lt;input id="loginName" type="text" name="loginName"
                     value="{{ craft.session.rememberedUsername }}"&gt;
  
              &lt;h3&gt;&lt;label for="password"&gt;Password&lt;/label&gt;&lt;/h3&gt;
              &lt;input id="password" type="password" name="password"&gt;
  
              &lt;label&gt;
                  &lt;input type="checkbox" name="rememberMe" value="1"&gt;
                  Remember me
              &lt;/label&gt;
  
              &lt;input type="submit" value="Login"&gt;
  
              {% if errorMessage is defined %}
                  &lt;p&gt;{{ errorMessage }}&lt;/p&gt;
              {% endif %}
          &lt;/form&gt;
  
          &lt;p&gt;&lt;a href="{{ url('forgotpassword') }}"&gt;Forget your password?&lt;/a&gt;&lt;/p&gt;
  
      {% else %}
          &lt;!-- user does not exist register --&gt;
          &lt;!-- snip see here for full content https://craftcms.com/docs/templating/user-registration-form --&gt;
  
      {% endif %}
  
  {% else %}
      &lt;!-- parameter not set show search form --&gt;
      &lt;form method="post"&gt;
          &lt;input type="hidden" name="action" value="test/checkEmail"&gt;
          &lt;input type="text" name="email"&gt;
          &lt;input type="submit"&gt;
      &lt;/form&gt;
  {% endif %}
  </code></pre>
  
  <p>And your controller </p>
  
  <pre><code>public function actionCheckEmail(){
      $email = craft()-&gt;request-&gt;getParam('email');
      if($user = craft()-&gt;users-&gt;getUserByEmail($email)){
          // user registered
          $userExists = true;
      }else{
          $userExists = false;
      }
      craft()-&gt;urlManager-&gt;setRouteVariables([
          'userExists'    =&gt; $userExists,
          'user'          =&gt; $user
      ]);
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-13T23:31:09.513Z
Answers.Text: Thanks Robin. I'm heading to bed now. I will take a good look tomorrow.
Answers.UserDisplayName: Jonathan Schofield
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-13T23:21:31.660Z
Answers.LastActivityDate: 2017-12-13T23:21:31.660Z
Answers.UserDisplayName: Robin Schambach
Body: <p>How could I go about allowing a (not logged in) guest user to submit their email address, check behind the scenes if it belongs to a user account, and then return: </p>
  
  <ol>
  <li>A login form if it does</li>
  <li>A registration form if it doesn't</li>
  </ol>
  
Tags: <users>
Title: Check if submitted email address belongs to a user account
ThreadText: # Check if submitted email address belongs to a user account
  
  (Asked by: username_0 on 2017-12-13)
  
  How could I go about allowing a (not logged in) guest user to submit their email address, check behind the scenes if it belongs to a user account, and then return:
  
  1. A login form if it does
  2. A registration form if it doesn't
  
  **Tags:** users
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-12-13. Score: 3
  
  I assume you have basic knowledge about plugins and routing, if not I'll update my post in a few hours.. otherwise Your form could be
  
  ```
  <!-- check if user submitted something -->
  {% if userExists is defined %}
      {% if userExists == true %}
          <!-- user exists login -->
          hello {{ user.name }}
  
          <form method="post" accept-charset="UTF-8">
              {{ getCsrfInput() }}
              <input type="hidden" name="action" value="users/login">
  
              <h3><label for="loginName">Username or email</label></h3>
              <input id="loginName" type="text" name="loginName"
                     value="{{ craft.session.rememberedUsername }}">
  
              <h3><label for="password">Password</label></h3>
              <input id="password" type="password" name="password">
  
              <label>
                  <input type="checkbox" name="rememberMe" value="1">
                  Remember me
              </label>
  
              <input type="submit" value="Login">
  
              {% if errorMessage is defined %}
                  <p>{{ errorMessage }}</p>
              {% endif %}
          </form>
  
          <p><a href="{{ url('forgotpassword') }}">Forget your password?</a></p>
  
      {% else %}
          <!-- user does not exist register -->
          <!-- snip see here for full content https://craftcms.com/docs/templating/user-registration-form -->
  
      {% endif %}
  
  {% else %}
      <!-- parameter not set show search form -->
      <form method="post">
          <input type="hidden" name="action" value="test/checkEmail">
          <input type="text" name="email">
          <input type="submit">
      </form>
  {% endif %}
  
  ```
  
  And your controller
  
  ```
  public function actionCheckEmail(){
      $email = craft()->request->getParam('email');
      if($user = craft()->users->getUserByEmail($email)){
          // user registered
          $userExists = true;
      }else{
          $userExists = false;
      }
      craft()->urlManager->setRouteVariables([
          'userExists'    => $userExists,
          'user'          => $user
      ]);
  }
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks username_1. I'm heading to bed now. I will take a good look tomorrow.  
  
  ---
  
  