/*
 * Copyright 2014-2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package org.docksidestage.app.web.signin;

import javax.annotation.Resource;

import org.docksidestage.app.web.base.HarborBaseAction;
import org.docksidestage.app.web.base.login.HarborLoginAssist;
import org.docksidestage.app.web.mypage.MypageAction;
import org.docksidestage.dbflute.exbhv.MemberBhv;
import org.lastaflute.web.Execute;
import org.lastaflute.web.response.HtmlResponse;

/**
 * @author jflute
 */
public class SigninAction extends HarborBaseAction {

    // ===================================================================================
    //                                                                           Attribute
    //                                                                           =========
    @Resource
    private HarborLoginAssist harborLoginAssist;
    @Resource
    private MemberBhv memberBhv;

    // ===================================================================================
    //                                                                             Execute
    //                                                                             =======
    @Execute
    public HtmlResponse index() {
        if (getUserBean().isPresent()) {
            return redirect(MypageAction.class);
        }
        return asHtml(path_Signin_SigninJsp).useForm(SigninForm.class);
    }

    @Execute
    public HtmlResponse signin(SigninForm form) {
        validate(form, messages -> {} , () -> {
            form.clearSecurityInfo();
            return asHtml(path_Signin_SigninJsp);
        });
        return harborLoginAssist.loginRedirect(form.email, form.password, op -> op.rememberMe(form.rememberMe), () -> {
            return redirect(MypageAction.class);
        });
    }
}
@@ -893,31 +893,37 @@
 age.
-dbflute.exbhv.MemberBhv
+mylasta.action.HarborMessages
 ;%0Aim
@@ -1424,55 +1424,8 @@
 ist;
-%0A    @Resource%0A    private MemberBhv memberBhv;
 %0A%0A  
@@ -2023,11 +2023,36 @@
  -%3E 
-%7B%7D 
+moreValidate(form, messages)
 , ()
@@ -2318,32 +2318,32 @@
 eAction.class);%0A
-
         %7D);%0A    
@@ -2343,10 +2343,323 @@
 );%0A    %7D
+%0A%0A    private void moreValidate(SigninForm form, HarborMessages messages) %7B%0A        if (isNotEmpty(form.email) && isNotEmpty(form.password)) %7B%0A            if (!harborLoginAssist.checkUserLoginable(form.email, form.password)) %7B%0A                messages.addErrorsLoginFailure(%22email%22);%0A            %7D%0A        %7D%0A    %7D
 %0A%7D

add more validation of login