// Path: Server/src/com/hufeiya/utils/CookieUtils.java
// public class CookieUtils {
// 	private static final Boolean IS_STUDENT = true;
// 	public static final int INVALID_VALUE = -1;
// 	public static void addCookieToRespose(HttpServletResponse response, int id) {
// 		Cookie cookie = new Cookie("uid", AESUtils.encrypt(id));
// 		System.out.println(cookie.getValue());//debug the cookie 
// 		response.addCookie(cookie);
// 	}
// 
// 	public static  int getUidFromCookies(Cookie[] cookies) {
// 		int decryptedCookieValue = INVALID_VALUE;
// 		if (cookies != null) {
// 			for (Cookie cookie : cookies) {
// 				if (cookie.getName().equals("uid")) {
// 					int tempDecrypted = AESUtils.decrypt(cookie.getValue());
// 					if (tempDecrypted != INVALID_VALUE) {
// 						decryptedCookieValue = tempDecrypted;
// 						break;
// 					}
// 				}
// 			}
// 		}
// 		return decryptedCookieValue;
// 	}
// }


import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.hufeiya.utils.CookieUtils;
import com.qiniu.util.Auth;
package com.hufeiya.controller;




public class UptokenServlet extends HttpServlet {

	private static Auth auth = Auth.create("8VTgVpzoGcxeuMR0df4te3qH9JE8xDy0XqZCqTLR", "b11rZxCn7f4JPMW2kQUMPS7A5q2F4UVo13smFbfv");

	// 覆盖上传
	private String getUpToken(String signId){
	    return auth.uploadToken("coolsignin",signId);
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		res.setContentType("text/html;charset=UTF-8");
		res.setCharacterEncoding("UTF-8");
		String signId = req.getParameter("signid");
		System.out.println(signId);
		PrintWriter out = res.getWriter();
// Path: Server/src/com/hufeiya/utils/CookieUtils.java
// public class CookieUtils {
// 	private static final Boolean IS_STUDENT = true;
// 	public static final int INVALID_VALUE = -1;
// 	public static void addCookieToRespose(HttpServletResponse response, int id) {
// 		Cookie cookie = new Cookie("uid", AESUtils.encrypt(id));
// 		System.out.println(cookie.getValue());//debug the cookie 
// 		response.addCookie(cookie);
// 	}
// 
// 	public static  int getUidFromCookies(Cookie[] cookies) {
// 		int decryptedCookieValue = INVALID_VALUE;
// 		if (cookies != null) {
// 			for (Cookie cookie : cookies) {
// 				if (cookie.getName().equals("uid")) {
// 					int tempDecrypted = AESUtils.decrypt(cookie.getValue());
// 					if (tempDecrypted != INVALID_VALUE) {
// 						decryptedCookieValue = tempDecrypted;
// 						break;
// 					}
// 				}
// 			}
// 		}
// 		return decryptedCookieValue;
// 	}
// }


// Path: Server/src/com/hufeiya/controller/UptokenServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.hufeiya.utils.CookieUtils;
import com.qiniu.util.Auth;

package com.hufeiya.controller;




public class UptokenServlet extends HttpServlet {

	private static Auth auth = Auth.create("8VTgVpzoGcxeuMR0df4te3qH9JE8xDy0XqZCqTLR", "b11rZxCn7f4JPMW2kQUMPS7A5q2F4UVo13smFbfv");

	// 覆盖上传
	private String getUpToken(String signId){
	    return auth.uploadToken("coolsignin",signId);
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		res.setContentType("text/html;charset=UTF-8");
		res.setCharacterEncoding("UTF-8");
		String signId = req.getParameter("signid");
		System.out.println(signId);
		PrintWriter out = res.getWriter();
		int uidFromCookies = CookieUtils.getUidFromCookies(req.getCookies());