Esempio n. 1
0
	/**
	 * 返回有效的验证码.
	 * 
	 * @param userId
	 * @return
	 */
	private List getValidCode(MyJdbcTool jdbcTool, String userId) {
		long now = System.currentTimeMillis();
		// 得到30分钟以前的时间.
		Date before = new Date(now - 1000 * 60 * 30);
		Object[] args = new Object[] { userId, before };
		// 查询没有失效的验证码
		List ans = jdbcTool
				.queryForList(
						"select validcode from shortmessage_info where mobile=? and createtime>?  and completed!=1 order by createtime desc limit 1",
						args);
		return ans;
	}
Esempio n. 2
0
	/**
	 * 更新密码.
	 * 
	 * @Title: updatePass
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @return
	 * @return String
	 * @throws
	 */
	public String updatePass() {
		MyJdbcTool jdbcTool = (MyJdbcTool) SpringContextUtil
				.getBean("jdbcTool");
		Result<String> r = new Result<String>();
		if (isEmpty(userId) || isEmpty(password) || isEmpty(oldPassword)) {
			r.setErrorCode(Result.ARGUMENT_ERROR);
			r.setErrorMessage("缺少必填参数!");
			r.setCount(0);
			writeToPage(response, JSON.toJSONString(r));
			return null;
		}
		if (!geneateToken(userId).equals(token)) {
			r.setErrorCode(Result.VALID_WRONG);
			r.setErrorMessage("url验证失败,请传入正确的token");
			r.setCount(0);
			writeToPage(response, JSON.toJSONString(r));
			return null;
		}
		String[] args = new String[] { userId };
		List pass = jdbcTool.queryForList(
				"select password from rep_user where phone=? ", args);
		try {
			if (pass == null || pass.size() == 0) {
				r.setErrorCode(Result.NO_USER);
				r.setErrorMessage("用户名不存在!");
				r.setCount(0);
				writeToPage(response, JSON.toJSONString(r));
				return null;
			} else {
				Map m = (HashMap) pass.get(0);
				String p = m.get("password") + "";
				oldPassword = Coder.toMyCoder(oldPassword);
				if (!p.equals(oldPassword)) {
					r.setErrorCode(Result.WRONG_PASSWORD);
					r.setErrorMessage("用户名原密码不正确!");
					r.setCount(0);
					writeToPage(response, JSON.toJSONString(r));
					return null;
				} else {
					password = Coder.toMyCoder(password);
					args = new String[] { password, userId };
					jdbcTool.updateSql(
							"update rep_user set password=? where phone = ?",
							args);
					r.setErrorCode(Result.SUCCESS);
					r.setErrorMessage("修改成功!");
					r.setCount(0);
					writeToPage(response, JSON.toJSONString(r));
					return null;
				}
			}
		} catch (Exception e) {
			log.error(e);
			r.setErrorCode(Result.SREVER_ERROR);
			r.setErrorMessage("出现系统异常!");
			r.setCount(0);
			writeToPage(response, JSON.toJSONString(r));
			return null;
		}

	}
Esempio n. 3
0
	/**
	 * 登陆.
	 * 
	 * @Title: login
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @return
	 * @return String
	 * @throws
	 */
	public String login() {
		MyJdbcTool jdbcTool = (MyJdbcTool) SpringContextUtil
				.getBean("jdbcTool");
		String[] args = new String[] { userId };
		List pass = jdbcTool.queryForList(
				"select * from rep_user where phone=? ", args);
		Result<String> r = new Result<String>();
		String _p = geneatePublicToken(userId);
		if (!_p.equals(token)) {
			r.setErrorCode(Result.VALID_WRONG);
			r.setErrorMessage("url验证失败,请传入正确的token");
			r.setCount(0);
			writeToPage(response, JSON.toJSONString(r));
			return null;
		}
		Result<Map> r2 = new Result<Map>();
		try {
			if (pass == null || pass.size() == 0) {
				r.setErrorCode(Result.NO_USER);
				r.setErrorMessage("用户名不存在!");
				r.setCount(0);
				writeToPage(response, JSON.toJSONString(r));
				return null;
			} else {
				Map m = (HashMap) pass.get(0);
				String p = m.get("password") + "";
				password = Coder.toMyCoder(password);
				if (!p.equals(password)) {
					r.setErrorCode(Result.WRONG_PASSWORD);
					r.setErrorMessage("密码不正确!");
					r.setCount(0);
					writeToPage(response, JSON.toJSONString(r));
					return null;
				} else {
					Map result = new HashMap();
					result.put("phone", m.get("phone"));
					result.put("userId", m.get("id"));
					result.put("brandName", m.get("brandname"));
					result.put("brandType", m.get("brandtype"));
					result.put("workNum", m.get("people_flownum_work"));
					result.put("weekendNum", m.get("people_flownum_weekend"));
					result.put("lng_north", m.get("lng_north"));
					result.put("lat_east", m.get("lat_east"));
					result.put("worktime", m.get("work_time"));
					result.put("token", geneateToken("" + m.get("id")));
					r2.setData(result);
					r2.setErrorCode(Result.SUCCESS);
					r2.setErrorMessage("登陆成功!");
					r2.setCount(0);
					writeToPage(response, JSON.toJSONString(r2));
					return null;
				}
			}
		} catch (Exception e) {
			log.error(e);
			r.setErrorCode(Result.SREVER_ERROR);
			r.setErrorMessage("出现系统异常!");
			r.setCount(0);
			writeToPage(response, JSON.toJSONString(r));
			return null;
		}
	}