基本信息
源码名称:jsp app服务端接口代码
源码大小:1.09M
文件格式:.zip
开发语言:Java
更新时间:2016-02-17
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package com.gsebp.app.api.controller; import javax.annotation.Resource; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.gsebp.app.api.commons.Constants; import com.gsebp.app.api.commons.JsonMessage; import com.gsebp.app.api.commons.RunTimeMessage; import com.gsebp.app.api.service.CompanyService; import com.gsebp.app.api.service.IdentifyingCodeService; import com.gsebp.app.api.vo.CompanyRegisterVo; import com.gsebp.app.api.vo.UserLoginVo; /** * * 地区(省市区)API * * @ProjectName: [gsebp-app] * @Package: [com.gsebp.app.api.controller.UserController] * @ClassName: [UserController] * @Description: [一句话描述该类的功能] * @Author: [niurs] * @CreateDate: [2016年1月27日 下午1:53:21] * @UpdateUser: [niurs] * @UpdateDate: [2016年1月27日 下午1:53:21] * @UpdateRemark: [说明本次修改内容] * @Version: [v2.0] * */ @Controller @RequestMapping("/api-bin") public class UserController { @Value("${usernameRegular}") private String usernameRegular; @Value("${passwordRegular}") private String passwordRegular; @Value("${mobileRegular}") private String mobileRegular; @Value("${emailRegular}") private String emailRegular; @Value("${identifyingCodeRegular}") private String identifyingCodeRegular; @Value("${companyNameRegular}") private String companyNameRegular; @Resource private CompanyService companyService; @Resource private IdentifyingCodeService identifyingCodeService; @RequestMapping("/companyRegist.json") @ResponseBody public JsonMessage companyRegist(CompanyRegisterVo companyRegisterVo){ JsonMessage json=validateCompanyRegistVo(companyRegisterVo); if(json.getRet().equals(Constants.API_JSON_VALUE_RET_FAIL)){ return json; } RunTimeMessage<String> tokenRtm = companyService.companyRegist(companyRegisterVo); if(tokenRtm.getStatus()==RunTimeMessage.SUCCESS){ json.setRet(Constants.API_JSON_VALUE_RET_SUCCESS); json.setMsg("注册成功"); json.setData(tokenRtm.getDate()); identifyingCodeService.delIdentifyingCode(companyRegisterVo.getMobile()); return json; } json.setRet(Constants.API_JSON_VALUE_RET_SUCCESS); json.setMsg("注册失败"); return json; } @RequestMapping("/companyLogin.json") @ResponseBody public JsonMessage companyLogin(UserLoginVo userLoginVo){ JsonMessage json=validateUserLoginVo(userLoginVo); if(json.getRet().equals(Constants.API_JSON_VALUE_RET_FAIL)){ return json; } RunTimeMessage<String> tokenRtm = companyService.companyLogin(userLoginVo); if(tokenRtm.getStatus()==RunTimeMessage.SUCCESS){ json.setRet(Constants.API_JSON_VALUE_RET_SUCCESS); json.setMsg("登录成功"); json.setData(tokenRtm.getDate()); return json; } json.setRet(Constants.API_JSON_VALUE_RET_SUCCESS); json.setMsg("用户名或密码错误"); return json; } /** * @Name: UserController.java * @Description: @param * @Description: @return * @Author: Niurs * @CreateDate 20162016年2月14日上午11:37:20 * @Parameters: * @Return: JsonMessage */ private JsonMessage validateUserLoginVo(UserLoginVo userLoginVo) { JsonMessage jsonMessage=new JsonMessage(); if(userLoginVo.getUsername()==null || userLoginVo.getUsername().trim().equals("")){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("用户名不能为空"); return jsonMessage; }else if(!userLoginVo.getUsername().matches(usernameRegular)){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("用户名不合法;字母开头,长度5-15,由字母、数字及" "_" "组成"); return jsonMessage; } if(userLoginVo.getPassword()==null || userLoginVo.getPassword().trim().equals("")){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("密码不能为空"); return jsonMessage; }else if(!userLoginVo.getPassword().matches(passwordRegular)){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("用户名不合法;长度5-15,由字母、数字及常用特殊符号组成"); return jsonMessage; } jsonMessage.setRet(Constants.API_JSON_VALUE_RET_SUCCESS); jsonMessage.setMsg("输入信息验证成功"); return jsonMessage; } /** * * @Name: UserController.java * @Description: @param * @Description: @return * @Author: Niurs * @CreateDate 20162016年2月14日上午11:39:05 * @Parameters: * @Return: JsonMessage */ private JsonMessage validateCompanyRegistVo(CompanyRegisterVo companyRegisterVo){ JsonMessage jsonMessage=new JsonMessage(); if(companyRegisterVo.getUsername()==null || companyRegisterVo.getUsername().trim().equals("")){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("用户名不能为空"); return jsonMessage; }else if(!companyRegisterVo.getUsername().matches(usernameRegular)){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("用户名格式错误;字母开头,长度5-15,由字母、数字及" "_" "组成"); return jsonMessage; } if(companyRegisterVo.getPassword()==null || companyRegisterVo.getPassword().trim().equals("")){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("密码不能为空"); return jsonMessage; }else if(!companyRegisterVo.getPassword().matches(passwordRegular)){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("密码格式错误;长度5-15,由字母、数字及常用特殊符号组成"); return jsonMessage; } if((companyRegisterVo.getEmail()!=null && companyRegisterVo.getEmail().trim()!="") && !companyRegisterVo.getEmail().matches(emailRegular)) { jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("邮箱格式错误"); return jsonMessage; } if(companyRegisterVo.getMobile()==null || companyRegisterVo.getMobile().trim().equals("")){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("手机号不能为空"); return jsonMessage; }else if(!companyRegisterVo.getMobile().matches(mobileRegular)){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("手机号码格式错误;长度5-15,由字母、数字及常用特殊符号组成"); return jsonMessage; } if(companyRegisterVo.getIdentifyingCode()==null || companyRegisterVo.getIdentifyingCode().trim().equals("")){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("验证码不能为空"); return jsonMessage; }else if(!companyRegisterVo.getIdentifyingCode().matches(identifyingCodeRegular)){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("验证码格式错误;长度6,由数字组成"); return jsonMessage; }else{ if(!identifyingCodeService.validateIdentifyingCode(companyRegisterVo.getIdentifyingCode(), companyRegisterVo.getMobile())){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("验证码错误,请重新输入"); return jsonMessage; } } if(companyRegisterVo.getCompanyName()== null || companyRegisterVo.getCompanyName().trim().equals("")){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("公司名称不能为空"); return jsonMessage; }else if(!companyRegisterVo.getCompanyName().matches(companyNameRegular)){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg("公司名称格式错误,长度2-20,由汉字组成"); } RunTimeMessage<String> rtm=companyService.validateCompanyName(companyRegisterVo); if(rtm.getStatus()==RunTimeMessage.SUCCESS ){ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_SUCCESS); jsonMessage.setMsg("输入信息验证成功"); return jsonMessage; }else{ jsonMessage.setRet(Constants.API_JSON_VALUE_RET_FAIL); jsonMessage.setMsg(rtm.getMsg()); return jsonMessage; } } }