001// --------------------------------------------------------------------------------
002// Copyright 2002-2025 Echo Three, LLC
003//
004// Licensed under the Apache License, Version 2.0 (the "License");
005// you may not use this file except in compliance with the License.
006// You may obtain a copy of the License at
007//
008//     http://www.apache.org/licenses/LICENSE-2.0
009//
010// Unless required by applicable law or agreed to in writing, software
011// distributed under the License is distributed on an "AS IS" BASIS,
012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013// See the License for the specific language governing permissions and
014// limitations under the License.
015// --------------------------------------------------------------------------------
016
017package com.echothree.view.client.web.struts;
018
019import com.echothree.control.user.user.common.UserUtil;
020import com.echothree.control.user.user.common.result.GetRecoveryQuestionChoicesResult;
021import com.echothree.model.control.user.common.choice.RecoveryQuestionChoicesBean;
022import java.util.List;
023import javax.naming.NamingException;
024import javax.servlet.http.HttpServletRequest;
025import org.apache.struts.action.ActionMapping;
026import org.apache.struts.util.LabelValueBean;
027
028public class BasePersonWithLoginActionForm
029        extends BasePersonActionForm {
030    
031    private RecoveryQuestionChoicesBean recoveryQuestionChoices = null;
032    
033    private String emailAddress = null;
034    private String username = null;
035    private String password1 = null;
036    private String password2 = null;
037    private boolean allowSolicitation;
038    private String recoveryQuestionChoice = null;
039    private String answer = null;
040    
041    private void setupRecoveryQuestionChoices() {
042        if(recoveryQuestionChoices == null) {
043            try {
044                var form = UserUtil.getHome().getGetRecoveryQuestionChoicesForm();
045                
046                form.setDefaultRecoveryQuestionChoice(recoveryQuestionChoice);
047                form.setAllowNullChoice(String.valueOf(true));
048
049                var commandResult = UserUtil.getHome().getRecoveryQuestionChoices(userVisitPK, form);
050                var executionResult = commandResult.getExecutionResult();
051                var getRecoveryQuestionChoicesResult = (GetRecoveryQuestionChoicesResult)executionResult.getResult();
052                recoveryQuestionChoices = getRecoveryQuestionChoicesResult.getRecoveryQuestionChoices();
053                
054                if(recoveryQuestionChoice == null) {
055                    recoveryQuestionChoice = recoveryQuestionChoices.getDefaultValue();
056                }
057            } catch (NamingException ne) {
058                // failed, recoveryQuestionChoices remains null, no default
059            }
060        }
061    }
062    
063    public void setEmailAddress(String emailAddress) {
064        this.emailAddress = emailAddress;
065    }
066    
067    public String getEmailAddress() {
068        return emailAddress;
069    }
070    
071    public void setUsername(String username) {
072        this.username = username;
073    }
074    
075    public String getUsername() {
076        return username;
077    }
078    
079    public void setPassword1(String password1) {
080        this.password1 = password1;
081    }
082    
083    public String getPassword1() {
084        return password1;
085    }
086    
087    public void setPassword2(String password2) {
088        this.password2 = password2;
089    }
090    
091    public String getPassword2() {
092        return password2;
093    }
094    
095    public void setAllowSolicitation(boolean allowSolicitation) {
096        this.allowSolicitation = allowSolicitation;
097    }
098    
099    public boolean getAllowSolicitation() {
100        return allowSolicitation;
101    }
102    
103    public List<LabelValueBean> getRecoveryQuestionChoices() {
104        List<LabelValueBean> choices = null;
105        
106        setupRecoveryQuestionChoices();
107        if(recoveryQuestionChoices != null) {
108            choices = convertChoices(recoveryQuestionChoices);
109        }
110        
111        return choices;
112    }
113    
114    public void setRecoveryQuestionChoice(String recoveryQuestionChoice) {
115        this.recoveryQuestionChoice = recoveryQuestionChoice;
116    }
117    
118    public String getRecoveryQuestionChoice() {
119        setupRecoveryQuestionChoices();
120        
121        return recoveryQuestionChoice;
122    }
123    
124    public void setAnswer(String answer) {
125        this.answer = answer;
126    }
127    
128    public String getAnswer() {
129        return answer;
130    }
131    
132    @Override
133    public void reset(ActionMapping mapping, HttpServletRequest request) {
134        super.reset(mapping, request);
135        
136        allowSolicitation = false;
137    }
138    
139}