<commit_before>/* 
 * Copyright 2012-2017 qifu of copyright <NAME>
 * 
 * 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.
 * 
 * -----------------------------------------------------------------------
 * 
 * author: 	<NAME>
 * contact: <EMAIL>
 * 
 */
package org.qifu.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.shiro.SecurityUtils;
import org.qifu.base.Constants;
import org.qifu.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class LoginAction extends BaseController {
	
	private void fillErrorMessage(HttpServletRequest request, HttpServletResponse response) {
		Object errObj = request.getAttribute(org.apache.shiro.web.filter.authc.FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
		if ("org.qifu.sys.IncorrectCaptchaException".equals(errObj)) {
			request.setAttribute(Constants.PAGE_MESSAGE, "Captcha code incorrect.");
		}		
		if ("org.apache.shiro.authc.IncorrectCredentialsException".equals(errObj)
				|| "org.apache.shiro.authc.UnknownAccountException".equals(errObj)
				|| "org.apache.shiro.authc.AuthenticationException".equals(errObj)) {
			this.setPageMessage(request, "Login fail.");
		}		
	}
	
	@RequestMapping(value = "/login.do", method = {RequestMethod.GET, RequestMethod.POST} )
	public String login(HttpServletRequest request, HttpServletResponse response) {
		request.setAttribute("loginCaptchaCodeEnable", this.getLoginCaptchaCodeEnable());
		try {
			if (SecurityUtils.getSubject().isAuthenticated()) {
				return this.getPageRedirect( REDIRECT_INDEX );
			}			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			this.fillErrorMessage(request, response);
		}<commit_msg>update code.<commit_after>/* 
 * Copyright 2012-2017 qifu of copyright <NAME>
 * 
 * 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.
 * 
 * -----------------------------------------------------------------------
 * 
 * author: 	<NAME>
 * contact: <EMAIL>
 * 
 */
package org.qifu.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.shiro.SecurityUtils;
import org.qifu.base.Constants;
import org.qifu.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class LoginAction extends BaseController {
	
	private void fillErrorMessage(HttpServletRequest request, HttpServletResponse response) {
		Object errObj = request.getAttribute(org.apache.shiro.web.filter.authc.FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
		if ("org.qifu.sys.InvalidAccountException".equals(errObj)) {
			request.setAttribute(Constants.PAGE_MESSAGE, "Invalid account.");
		}		
		if ("org.qifu.sys.IncorrectCaptchaException".equals(errObj)) {
			request.setAttribute(Constants.PAGE_MESSAGE, "Captcha code incorrect.");
		}		
		if ("org.apache.shiro.authc.IncorrectCredentialsException".equals(errObj)
				|| "org.apache.shiro.authc.UnknownAccountException".equals(errObj)
				|| "org.apache.shiro.authc.AuthenticationException".equals(errObj)) {
			this.setPageMessage(request, "Login fail.");
		}		
	}
	
	@RequestMapping(value = "/login.do", method = {RequestMethod.GET, RequestMethod.POST} )
	public String login(HttpServletRequest request, HttpServletResponse response) {
		request.setAttribute("loginCaptchaCodeEnable", this.getLoginCaptchaCodeEnable());
		try {
			if (SecurityUtils.getSubject().isAuthenticated()) {
				return this.getPageRedirect( REDIRECT_INDEX );
			}			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			this.fillErrorMessage(request, response);
		}
{'fraction_non_alphanumeric': 0.1311737652469506, 'fraction_numerical': 0.004799040191961607, 'mean_word_length': 4.178053830227744, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4638821', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1367, 'n_words': 332}