<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/webflow
      http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">

  <secured attributes="ROLE_ANONYMOUS"/>

  <var name="account" class="org.unitedfront2.domain.Account"/>

  <subflow-state id="captcha" subflow="captcha-sub-flow">
    <transition on="finish" to="userForm"/>
  </subflow-state>

  <subflow-state id="userForm" subflow="user.form-sub-flow">
    <input name="pageTitleCode" value="'Registration.user.Form'"/>
    <input name="formSubmitCode" value="'toNext'"/>
    <output name="user" required="true"/>
    <transition on="finish" to="mailAddrForm"/>
  </subflow-state>

  <view-state id="mailAddrForm" view="account.MailAddrRegisterForm" model="account">
    <binder>
      <binding property="mailAddr"/>
    </binder>
    <on-render>
      <set name="flashScope.validator" value="accountValidator"/>
    </on-render>
    <transition on="submit" to="register"/>
  </view-state>

  <action-state id="register">
    <evaluate expression="registrationAction.register"/>
    <transition on="success" to="registrationSuccess"/>
    <transition on="error" to="registrationFailure"/>
  </action-state>

  <decision-state id="registrationSuccess">
    <if test="mailService.enable" then="registrationSuccessWithMail" else="registrationSuccessWithoutMail"/>
  </decision-state>

  <decision-state id="registrationFailure">
    <if test="mailService.enable" then="registrationFailureWithMail" else="registrationFailureWithoutMail"/>
  </decision-state>

  <end-state id="registrationSuccessWithMail" view="RegistrationSuccessWithMail"/>
  <end-state id="registrationFailureWithMail" view="RegistrationSuccessWithMail"/>
  <end-state id="registrationSuccessWithoutMail" view="RegistrationSuccessWithoutMail"/>
  <end-state id="registrationFailureWithoutMail" view="RegistrationSuccessWithMail"/>

</flow>
