<?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_USER, ROLE_ADMIN"/>

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

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

  <subflow-state id="authenticate" subflow="account.authentication-sub-flow">
    <transition on="finish" to="mailAddrChange"/>
  </subflow-state>

  <action-state id="mailAddrChange">
    <evaluate expression="accountMailAddrChangeAction.changeMailAddr"/>
    <transition on="success" to="mailSendOrNot"/>
  </action-state>

  <decision-state id="mailSendOrNot">
    <if test="mailService.enable" then="mailSent" else="mailNotSent"/>
  </decision-state>

  <end-state id="mailSent" view="account.MailAddrChangeSuccessWithMail"/>

  <end-state id="mailNotSent" view="account.MailAddrChangeSuccessWithoutMail">
    <on-entry>
      <set name="flashScope.mailAddrAndPassword" value="flowScope.mailAddrAndPassword"/>
    </on-entry>
  </end-state>

</flow>
